Skip to Content
Menu
This question has been flagged
1 Reply
2997 Views

Hi Friends 

I am learning XML-RPC API for JAVA, I tried some code, but the SEARCH,SEARCH_COUNT, etc operation is not working for me .

I am using IDE - Java Eclipse & my program looks like 


public static void main(String[] args) throws MalformedURLException, XmlRpcException {

        final XmlRpcClient client = new XmlRpcClient();

        final XmlRpcClient models = new XmlRpcClient();

        final XmlRpcClientConfigImpl common_config = new XmlRpcClientConfigImpl();

        common_config.setServerURL(

                new URL(String.format("%s/xmlrpc/2/common", url)));

        client.execute(common_config, "version", emptyList());

        int uid = (int) client.execute(

                common_config, "authenticate", asList(

                        db, username, password, emptyMap()));


      Integer count=(Integer)models.execute("execute_kw", asList(

            db, uid, password,"res.partner", "search_count", asList(asList())));        

        System.out.println(count);

   }     

}



Output:


Exception in thread "main" java.lang.NullPointerException

at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:32)

at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:53)

at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:166)

at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:157)

at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:146)

Avatar
Discard
Best Answer

You got this error because your "pURL" is null. The easiest solution is to create a new XmlRpcClientConfigImpl and use it in your search call.

final XmlRpcClientConfigImpl models_config = new XmlRpcClientConfigImpl();
models_config.setServerURL(new URL(String.format("%s/xmlrpc/2/object",url)));
Integer count=(Integer)models.execute( models_config, "execute_kw",
    List.of( db, uid, password,"res.partner", "search_count", List.of(List.of())));

That's because you query "xmlrpc/2/common" once (for the version,..)and once "xmlrpc/2/object" for the search. Therefore you need two configurations.

Avatar
Discard