AXIS2はエンコードのために誤ったSOAPメッセージを生成します。修正方法

StackOverflow https://stackoverflow.com/questions/601771

質問

質問:軸で別のエンコード(文字セットと転送)を使用するにはどうすればよいですか

こちらが私のクライアントです:

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があります...それは何ですか?

役に立ちましたか?

解決 2

結局のところ、EclipseのプラグインTCP / IPモニターは、正しい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」のアーティファクトです。送信するコンテンツの一部ではありません。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top