1

I have a soap client which call a SOAP WS method. Issue is, when I receive data in JAVA using below code, java parses SOAPMessage using some default encoding. As a result when I print WS response I see some garbage characters.

SOAPConnectionFactory connectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = connectionFactory.createConnection();
SOAPMessage response = connection.call(soapMessage, endpoint);

So, is there any way, by which I can specify or force .call() method above to use a particular character encoding.

I have tested WS using SOAP UI and RAW XML tab of SOAP UI shows valid characters.

Edit: Am printing and validating presence of garbage characters using below code:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
response.writeTo(baos);
String s2 = new String(baos.toByteArray(), "ISO-8859-1"); // decoding 
System.out.println(s2);
John
  • 371
  • 3
  • 11
  • is it possible that you are handling the response incorrectly, or that your terminal cannot display the characters? how are you printing thre response? – jtahlborn May 30 '16 at 23:50
  • @jtahlborn Please see my edit. – John May 31 '16 at 03:08
  • my guess is that you are corrupting the response when you are trying to display it. do you know for a fact that the response is encoded using "iso-8859-1"? – jtahlborn May 31 '16 at 03:56
  • That is what WS provider say, but how come Raw xml tab in SOAP UI, show correct character if am seeing garbage character in java. – John May 31 '16 at 16:22
  • i don't understand your last comment. – jtahlborn May 31 '16 at 17:48

1 Answers1

1

You can do this:

soapMessage.setProperty(SOAPMessage.WRITE_XML_DECLARATION, Boolean.TRUE);

before sending your soapMessage variable as a parameter to call().

Refer to this documentation: http://docs.oracle.com/javaee/5/api/javax/xml/soap/SOAPMessage.html#setProperty%28java.lang.String,%20java.lang.Object%29

Yogesh Ghimire
  • 432
  • 1
  • 8
  • 21
  • After adding above I am getting Runtime exception: javax.xml.soap.write-xml-declaration must have value false or true – John May 31 '16 at 03:03