AXIS2 genera un mensaje SOAP incorrecto debido a la codificación. ¿Como arreglarlo?
-
03-07-2019 - |
Pregunta
PREGUNTA : ¿cómo puedo usar una codificación (conjunto de caracteres y transferencia) diferente con el eje?
Aquí está mi cliente:
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;
}
Aquí se genera el SOAPEnvelope (capturado mediante el Monitor 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>
POR QUÉ Axis2 generó esta codificación estúpida ( http://schemas.xmlsoap.org/soap/envelope ) ???
Usando Apache TCPMon, capturé esta solicitud:
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 envío la solicitud XML utilizando soapUI, eso es lo que captura 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>
He notado esta salida extraña: 102 y 0 en el medio del XML ... ¿qué puede ser?
Solución 2
Después de que todo el complemento TCP / IP Monitor de Eclipse aparentemente no me estaba dando la solicitud XML correcta, lo que me lleva a direcciones equivocadas.
Estaba mostrando encoding = " http: //schemas.xmlsoap.org/soap/envelope/" , mientras que Apache TCPMon me dio resultados diferentes (DERECHO).
Como se ha señalado saua , el problema fue la codificación Chunk, que puede cambiar con esto (Y RESOLVIÓ MI PROBLEMA):
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE);
Y para responder a mi pregunta:
options.setProperty(org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING, "UTF-8");
Otros consejos
Los 102 y 0 en el medio de XML son artefactos de la " Transfer-Encoding: chunked " no forman parte del contenido que envías.