Axis2 gerando errado mensagem SOAP por causa da codificação. como corrigi-lo?
-
03-07-2019 - |
Pergunta
Pergunta ??strong>: como posso usar um diferente codificação (charset e transferência) com o eixo
Aqui está o meu 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;
}
Aqui está a SOAPEnvelope sendo gerado (capturado usando 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>
POR Axis2 gerado esta codificação burro ( http://schemas.xmlsoap.org/soap/envelope ) ???
Usando Apache tcpmon eu capturei este pedido:
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
Se eu enviar a solicitação XML usando soapUI Isso é o 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>
Tenho notado esta saída estranho: 102 e 0 no meio do XML ... o que pode ser
Solução 2
Afinal de Eclipse plug-in Monitor de TCP / IP foi, aparentemente, não me dando o pedido XML direita me levando a direções erradas.
Ele estava mostrando encoding = "http://schemas.xmlsoap.org/soap/envelope/" , enquanto o Apache tcpmon me deu resultados diferentes (direita).
Como saua observou, problema era a codificação Chunk, que você pode mudar com isso (e resolveu o meu problema):
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE);
E para responder a minha pergunta:
options.setProperty(org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING, "UTF-8");
Outras dicas
A 102 e 0 no meio da XML são artefatos do "Transfer-Encoding: blocos" eles não fazem parte do conteúdo que você enviar
.