views:

1638

answers:

2

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/"?&gt;
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;
<soapenv:Body>
<WBSREFT xmlns="http://tempuri.org/LICPOCSampleService"&gt;
<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/"&gt;
      <soapenv:Body>
         <WBSREFT xmlns="http://tempuri.org/LICPOCSampleService"&gt;
            <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/"&gt;
      <soapenv:Body>
         <WBSREFT xmlns="http://tempuri.org/LICPOCSampleService"&gt;
            <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?

+1  A: 

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.

Joachim Sauer
+1  A: 

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");
Lucas -luky- N.
The chunk encoding is not a problem, it's a standardized way to transfer data. Why do you want to change it?
Joachim Sauer
well, somehow the webservice wasn't understanding the encoding. it's a COBOL webservices.
Lucas -luky- N.