Question

QUESTION : comment utiliser un autre encodage (jeu de caractères et transfert) avec un axe?

Voici mon 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;

    }

Voici l’enveloppe SOAP en cours de génération (capturée à l’aide du moniteur 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>

POURQUOI Axis2 a généré cet encodage stupide ( http://schemas.xmlsoap.org/soap/envelope ) ???

Utilisation d'Apache TCPMon, j'ai capturé cette requête:

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

Si j'envoie la demande XML à l'aide de soapUI, c'est ce que TCPMon enregistre:

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>

J'ai remarqué cette sortie étrange: 102 et 0 au milieu du XML ... que peut-il bien être?

Était-ce utile?

La solution 2

Après tout, le plugin Eclipse TCP / IP Monitor ne me donnait apparemment pas la bonne requête XML qui me conduisait dans de mauvaises directions.

Il affichait encoding = "http: //schemas.xmlsoap.org/soap/envelope/" , alors qu'Apache TCPMon m'a donné des résultats différents (à DROITE).

Comme saua a été noté, le problème était le codage de bloc, que vous pouvez modifier avec ceci (ET RÉSOLU DE MON PROBLÈME):

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

Et pour répondre à ma question:

options.setProperty(org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING, "UTF-8");

Autres conseils

Les symboles 102 et 0 au milieu du code XML sont des artefacts du fichier "Transfer-Encoding: chunked". ils ne font pas partie du contenu que vous envoyez.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top