Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Deserialise SOAP Response

 
Guru Rao
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Guru Rao
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic