AXIS2因编码而生成错误的SOAP消息。怎么解决?
-
03-07-2019 - |
题
问题:如何在轴上使用不同的编码(字符集和传输)?
这是我的客户:
public Object[] invoke(String xmlRepresentation)
throws CustomApplicationException {
Object[] responseWS = null;
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
options.setAction("WBSREFT");
options.setTo(new EndpointReference("http://localhost:6132"));
QName qName = new QName(XML_SCHEMA, operation);
Object[] args = new Object[] { "blablabla" };
responseWS = serviceClient.invokeBlocking(qName, args, returnTypes);
String responseAsString = (String) responseWS[0];
return responseWS;
}
这是生成的SOAPEnvelope(使用TCP / IP Monitor捕获):
<?xml version="1.0" encoding="http://schemas.xmlsoap.org/soap/envelope/"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<WBSREFT xmlns="http://tempuri.org/LICPOCSampleService">
<arg0 xmlns="">blablabla</arg0>
</WBSREFT>
</soapenv:Body>
</soapenv:Envelope>
为什么Axis2生成了这种愚蠢的编码( http://schemas.xmlsoap.org/soap/envelope )...
使用Apache TCPMon我已经捕获了这个请求:
POST / HTTP/1.1
Content-Type: text/xml; charset=UTF-8
SOAPAction: "WBSREFT"
User-Agent: Axis2
Host: 172.17.192.113:6133
Transfer-Encoding: chunked
102
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<WBSREFT xmlns="http://tempuri.org/LICPOCSampleService">
<arg0 xmlns="">to cobol</arg0>
</WBSREFT>
</soapenv:Body>
</soapenv:Envelope>0
如果我使用soapUI发送XML请求,那就是TCPMon捕获的内容:
POST / HTTP/0.9
Content-Type: text/xml;charset=UTF-8
SOAPAction: ""
User-Agent: Jakarta Commons-HttpClient/3.1
Host: 172.17.192.113:6133
Content-Length: 265
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<WBSREFT xmlns="http://tempuri.org/LICPOCSampleService">
<arg0 xmlns="">to cobol</arg0>
</WBSREFT>
</soapenv:Body>
</soapenv:Envelope>
我注意到这个奇怪的输出:在XML的中间102和0 ......它可以是什么?
解决方案 2
毕竟Eclipse的插件TCP / IP Monitor显然没有给我正确的XML请求,导致我指向错误的方向。
它显示了 encoding =&quot; http://schemas.xmlsoap.org/soap/envelope/" ,而Apache TCPMon给了我不同的(正确)结果。
正如 saua 所述,问题是块编码,您可以使用此更改(并解决我的问题):
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE);
回答我的问题:
options.setProperty(org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING, "UTF-8");
其他提示
XML中间的102和0是“Transfer-Encoding:chunked”的工件。它们不是您发送内容的一部分。
不隶属于 StackOverflow