File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes Deserialise SOAP Response Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Deserialise SOAP Response" Watch "Deserialise SOAP Response" New topic
Author

Deserialise SOAP Response

Guru Rao
Greenhorn

Joined: Apr 24, 2009
Posts: 11
Hi All,

I had earlier posted a topic regarding Russian characters.

I write this in connection with the above post.

I get a SOAP response which contains some Russian characters in it. Below is the SOAP Response:-

<?xml version="1.0" encoding="UTF-8" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns:OpportunityWS_OpportunityQueryPage_Output xmlns:ns="urn:crmondemand/ws/opportunity/10/2004">
<ns:LastPage>true</ns:LastPage>
<ListOfOpportunity xmlns="urn:/crmondemand/xml/opportunity">
<Opportunity>
<OpportunityId>AEMA-XVGYA</OpportunityId>
<ltEndCustomer>Сибирь/Дальний во�ток</ltEndCustomer>
</Opportunity>
</ListOfOpportunity>
</ns:OpportunityWS_OpportunityQueryPage_Output>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Can someone help me out in deserialising this SOAP response to retrieve the Russian characters.

Regards,
Guru
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12784
    
    5
What do you have on the client side right now?

Are you using one of the many SOAP toolkits or what?

Every SOAP message should be a valid XML document so the option of writing your own treatment using the standard XML library is always available.

Bill
Guru Rao
Greenhorn

Joined: Apr 24, 2009
Posts: 11
Thanks for you reply.

I actually have the SOAP request in a String object (this is only for testing). I submit this SOAP request using a HttpURLConnection object by setting all the required properties like request method, Content-Length, SOAPAction, etc. Then the SOAP request is written to the connection object's output stream. Here is the code snippet of the same:-

HttpURLConnection wsConnection = (HttpURLConnection)wsURL.openConnection();
wsConnection.setUseCaches(false);

StringBuilder strRead = new StringBuilder();

wsConnection.setRequestMethod("POST");
wsConnection.setAllowUserInteraction(true);
wsConnection.setDoOutput(true);
wsConnection.setDoInput(true);
wsConnection.setRequestProperty("Content-Length", "" + request.length());
wsConnection.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
wsConnection.setRequestProperty("Accept", "text/xml");
wsConnection.setRequestProperty("SOAPAction", soapAction);

DataOutputStream stream = new DataOutputStream(wsConnection.getOutputStream());

// write the post vars (the request string).
stream.write(request.getBytes("UTF-8"));

stream.flush();
stream.close(); // close the stream.

From the initial post, I continued my debugging and tried to deserialise the SOAP response (posted earlier) using DOM parser. I was able to retrieve the Russian text, but not all characters. The actual Russian text is "Сибирь/Дальний восток". But using DOM parser the retrieved Russian text is "Сибирь/Дальний во�?ток". So as can be seen one of the character is not rendered correctly.

~Guru
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41839
    
  63
Is the character transferred correctly, and just not displayed correctly wherever the code is displaying it? Or is it incorrect within the SOAP as well?


Ping & DNS - my free Android networking tools app
Guru Rao
Greenhorn

Joined: Apr 24, 2009
Posts: 11
I believe the characters should be getting transfered correctly. I was able to successfully retrieve the Russian characters using a Axis WSDL2Java client.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41839
    
  63
In that case, where are you seeing the incorrect character? How are you getting the characters from the SOAP response, and how are you displaying them?
Guru Rao
Greenhorn

Joined: Apr 24, 2009
Posts: 11
As mentioned in my 2nd post in this thread, I post a SOAP request to the HttpURLConnection object. The response is deserialised using DOM parser and the Russian characters are written to a file. I open this file in a Unicode enabled text editor (like edit plus) and check for the Russian characters.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12784
    
    5
Russian characters are written to a file


Writing a String to a file involves an implicit character encoding - probably the default on your machine.

If this was my problem I would consider dumping the captured string one character at a time as int values to see if the internal Unicode corresponds to the expected Russion characters.

Bill
Guru Rao
Greenhorn

Joined: Apr 24, 2009
Posts: 11
I tried writing as char[] as well as byte[], but was not able to retrieve the russian characters successfully.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12784
    
    5
Did you look at the int (or hex) value of the Unicode characters in memory to see if they are getting that far intact.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Deserialise SOAP Response