Jimmy Geers
Jimmy Geers

Reputation: 742

java.util.collection return from webservice

I'm calling a service that gives me back as output parameter of java.util.Collection. Now my question is how can I retrieve data from that object? If I print it in Java, I get something like [[Ljava.lang.Object;@7ff4d7c0]. That's normal because I'm just printing the object.

This service is from the ofbiz project and it is working correctly. When i use the web service tester from ofbiz I get the return value as:

{{party=[GenericEntity:Party][partyId,10045(java.lang.String)][partyTypeId,PERSON(java.lang.String)]}, {party=[GenericEntity:Party][partyId,10119(java.lang.String)][partyTypeId,PERSON(java.lang.String)]}}` 

How do I achieve this in Java?

This is my code:

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


    XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
    config.setServerURL(new URL("http://127.0.0.1:8080/webtools/control/xmlrpc"));
    config.setEnabledForExceptions(true);
    config.setEnabledForExtensions(true);

    XmlRpcClient client = new XmlRpcClient();
    client.setConfig(config);

    Map paramMap = new HashMap();
    Map map1 = new HashMap();


    //Verplichte parameters
    paramMap.put("login.username", "admin");
    paramMap.put("login.password", "opentaps");
    paramMap.put("userLoginId", "David");

    Object[] params = new Object[]{paramMap};

    Map result = (Map) client.execute("getPartyFromUserLogin", params);
    //System.out.println(result.values());


    Collection parties = null;
    parties = (Collection) result.values();
    System.out.println("Got parties: " + parties.size());
    System.out.println(parties.toString());


    Iterator it = parties.iterator();
    while(it.hasNext()){
        Party object = (Party)it.next();
        System.out.println("ok : "+ object.getPartyId());
    }

}

Ok so now I'm trying to iterate it and cast it to an Party Object (import org.opentaps.base.entities.Party;). guess its just casting to the wrong class?

Error log:

Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to org.opentaps.base.entities.Party
    at test.xmlrpcGetPartyEmail.main(xmlrpcGetPartyEmail.java:56)

Error log after using this code:

    Iterator it = parties.iterator();
while(it.hasNext()){
    System.out.println("ok : "+ it.next().getClass());
}

class java.util.HashMap$Values
Got parties: 1
[[Ljava.lang.Object;@2380bfe1]
ok : class [Ljava.lang.Object;

Server Log:

  ava:777:WARN ] Running the getPartyFromUserLogin Service...
     [java] 2012-03-27 14:47:28,861 (http-0.0.0.0-8080-1) [      PartyServices.
ava:792:INFO ] PartyFromUserLogin number found: 2
     [java] 2012-03-27 14:47:28,865 (http-0.0.0.0-8080-1) [     RequestHandler.
ava:641:INFO ] Ran Event [xmlrpc:#] from [request], result is [null]
     [java] 2012-03-27 14:47:28,866 (http-0.0.0.0-8080-1) [     ControlServlet.
ava:328:INFO ] [[[xmlrpc] Request Done- total:0.056,since last([xmlrpc] Request
...):0.056]]

Upvotes: 0

Views: 799

Answers (1)

02strich
02strich

Reputation: 206

Can you try running your program with

Iterator it = parties.iterator();
while(it.hasNext()){
    System.out.println("ok : "+ it.next().getClass());
}

and post the result?

Upvotes: 1

Related Questions