Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Parsing SOAP response

843833Apr 21 2005 — edited May 2 2005
Hi all,
I'm trying to parse a response to a SOAP request and am not quite sure how to do this. I see in all the examples on the web and in the books where the information being returned is a simple type or a complex type and you can use Response.getReturnValue() to access the data.
Either something like,
<SOAP-ENV:Body>
<stockquoteresponse>
<stockprice>123.45</stockprice>
</stockquoteresponse>
</SOAP-ENV:Body>
or
<SOAP-ENV:Body>
<stockquoteresponse>
<stock>
<tickersymbol>XYZ</tickersymbol>
<stockprice>123.45</stockprice>
</stock>
</stockquoteresponse>
</SOAP-ENV:Body>
In my case however i have multiple pieces of information coming back and I am not sure how to encapsulate it in an object and if that is not possible, how to read it. I am getting something like,

<SOAP-ENV:Body>
<stockquoteresponse>
<tickersymbol>XYZ</tickersymbol>
<stockprice>123.45</stockprice>
</stockquoteresponse>
</SOAP-ENV:Body>
Is it possible to get access to the stockquoteresponse element and deserialize that into an object ? In the examples I have seen, it doesn't seem to be possible.
Thanks

Comments

843833 Apr 21 2005
Try this article.
http://www-106.ibm.com/developerworks/webservices/library/ws-castor/

This may be helpful for you to do this task
843833 Apr 21 2005
I should have mentioned that I am using Apache SOAP for my client. Unless I missed something, the URL Kanishka_Liyanage provided does not really explain what to do in my situation. I understand how to deal with a complex object being returned, but I don't get one object returned but few simple types.
843833 Apr 21 2005
Hi,

As you have mentioned that you are using AXIS, you must have run wsdl2Java. When you run that All the classes , related to the response are also generated.

So now when you have the response, the response will also be of some type (i,e a Class). It will have various methods (getter Methods).

for e.g: if the response is like this:

<getCustomerInfoResonse>
<customer>
<name> Milan</name>
</customer>
<customer>
<name> Steve</name>
</customer>
</getCustomerInfoResonse>

then there would be a class like GetCustomerInfoResponse (not exactly the same name as it depends on Schema and NOT on XML).

This class will have method like getCustomer . Similarly class Customer will have a method called getName and so on.

Hope this gives some direction,

MD.
843833 Apr 22 2005
Milan,
No, I am not using AXIS. I am using the Apache SOAP package.
I'm sorry if I was not clear. My problem is with accessing the parameters being returned if there are more than one. AXIS has the getOutputParams() method that will allow you to access all the params being returned. In your example I will be able to access both the customers. In the Apache SOAP package I don't see a similar method. There is a getReturnValue() which only returns one value. I understand the concept of the RPC and that there would only be one return value, as in any method. If I do the getReturnValue() for your example, I would only get the first customer. I am looking for a way to do INOUT parameters in Apache SOAP.

Thanks
PN
843833 May 2 2005
To answer my own question, for a response like this:
<getCustomerInfoResonse>
<customer>
<name> Milan</name>
</customer>
<customer>
<name> Steve</name>
</customer>
</getCustomerInfoResonse>
The first customer gets sent back as the return value
Parameter returnVal = resp.getReturnValue() ; // where resp is of type Response
// returnVal.getValue() == Milan
the other customer can be accessed by
Vector parms = resp.getParams() ;
//((Parameter)parms.elementAt(0)).get Value() == Steve
1 - 5
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on May 30 2005
Added on Apr 21 2005
5 comments
141 views