由于编码原因,AXIS2 生成错误的 SOAP 消息。 如何修复它?

发布于 2024-07-14 13:01:06 字数 2621 浏览 5 评论 0原文

问题:如何在轴上使用不同的编码(字符集和传输)

这是我的客户:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱本泡沫多脆弱 2024-07-21 13:01:06

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.

゛清羽墨安 2024-07-21 13:01:06

毕竟 Eclipse 的插件 TCP/IP Monitor 显然没有给我正确的 XML 请求,导致我走向错误的方向。

它显示 encoding="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");

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

options.setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE);

And to answer my question:

options.setProperty(org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING, "UTF-8");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文