由于编码原因,AXIS2 生成错误的 SOAP 消息。 如何修复它?
问题:如何在轴上使用不同的编码(字符集和传输)?
这是我的客户:
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 监视器捕获):
<?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...它会是什么?
QUESTION: how can I use a different encoding (charset and transfer) with axis?
Here is my client:
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;
}
Here is the SOAPEnvelope being generated (captured using 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>
WHY Axis2 generated this stupid encoding (http://schemas.xmlsoap.org/soap/envelope)???
Using Apache TCPMon I've captured this request:
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
If I send the XML request using soapUI that's what TCPMon captures:
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>
I've noticed this weird output: 102 and 0 in the middle of the XML... what can it be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
XML 中间的 102 和 0 是“传输编码:分块”的产物,它们不是您发送的内容的一部分。
The 102 and 0 in the middle of the XML are artifacts of the "Transfer-Encoding: chunked" they are not part of the content you send.
毕竟 Eclipse 的插件 TCP/IP Monitor 显然没有给我正确的 XML 请求,导致我走向错误的方向。
它显示 encoding="http://schemas.xmlsoap.org/soap/envelope/",而 Apache TCPMon 给了我不同的(正确的)结果。
正如 saua 指出的,问题是块编码,您可以用它来更改它(并解决了我的问题):
并回答我的问题:
After all Eclipse's plugin TCP/IP Monitor was apparently not giving me the right XML request leading me to wrong directions.
It was showing encoding="http://schemas.xmlsoap.org/soap/envelope/", while Apache TCPMon gave me different (RIGHT) results.
As saua noted, problem was the Chunk encoding, which you can change with this (AND SOLVED MY PROBLEM):
And to answer my question: