简体   繁体   English

SOAP响应编码问题

[英]SOAP Response encoding issue

I have a soap client which call a SOAP WS method. 我有一个肥皂客户端,它调用SOAP WS方法。 Issue is, when I receive data in JAVA using below code, java parses SOAPMessage using some default encoding. 问题是,当我使用以下代码在JAVA中接收数据时,java使用某种默认编码来解析SOAPMessage。 As a result when I print WS response I see some garbage characters. 结果,当我打印WS响应时,我看到一些垃圾字符。

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. 因此,有什么方法可以指定或强制上述.call()方法使用特定的字符编码。

I have tested WS using SOAP UI and RAW XML tab of SOAP UI shows valid characters. 我已经使用SOAP UI测试了WS,并且SOAP UI的RAW XML选项卡显示了有效字符。

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);

You can do this: 你可以这样做:

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

before sending your soapMessage variable as a parameter to call() . 在将soapMessage变量作为参数发送给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 请参阅此文档: http : //docs.oracle.com/javaee/5/api/javax/xml/soap/SOAPMessage.html#setProperty%28java.lang.String,%20java.lang.Object%29

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM