Hello Guys,
I'm facing a problem to add a soap header properly during request.
I need a Header like this:
<soapenv:Header>
<esb:CONSUMIDOR xmlns:m="http://foo.com">
<IDCONSUMIDOR>DINIZ</IDCONSUMIDOR>
<USUARIOCANAL>FOO</USUARIOCANAL>
<PASSWORD>MyPsw</PASSWORD>
</esb:CONSUMIDOR>
</soapenv:Header>
But I'm getting the below wrong header instead:
Take a look at the code below:Code:<soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <esb:CONSUMIDOR soapenv:mustUnderstand="0" xmlns:esb="http://foo.com"/> </soapenv:Header>
What's missing guys?Code:(...) public class WSClient { private final static String CONSUMIDOR_HEADER_NODE = "<esb:CONSUMIDOR xmlns:m=\"http://foo.com\" xmlns:esb=\"http://foo.com\">"; private final static String _CONSUMIDOR_HEADER_NODE = "</esb:CONSUMIDOR>"; private final static String USERNAME_HEADER_NODE = "<IDCONSUMIDOR>"; private final static String _USERNAME_HEADER_NODE = "</IDCONSUMIDOR>"; private final static String USUARIOCANAL_HEADER_NODE = "<USUARIOCANAL>"; private final static String _USUARIOCANAL_HEADER_NODE = "</USUARIOCANAL>"; private final static String PASSWORD_HEADER_NODE = "<PASSWORD>"; private final static String _PASSWORD_HEADER_NODE = "</PASSWORD>"; private StringBuffer headerBuffer = new StringBuffer(); private WebServiceTemplate webServiceTemplate; public RootInstraClient(WebServiceTemplate webServiceTemplate) { this.webServiceTemplate = webServiceTemplate; headerBuffer.append(CONSUMIDOR_HEADER_NODE); headerBuffer.append(USERNAME_HEADER_NODE); headerBuffer.append("XX"); headerBuffer.append(_USERNAME_HEADER_NODE); headerBuffer.append(USUARIOCANAL_HEADER_NODE); headerBuffer.append("YYY"); headerBuffer.append(_USUARIOCANAL_HEADER_NODE); headerBuffer.append(PASSWORD_HEADER_NODE); headerBuffer.append("foo"); headerBuffer.append(_PASSWORD_HEADER_NODE); headerBuffer.append(_CONSUMIDOR_HEADER_NODE); } public RESPONSE_INSTRA ROOT_INSTRA(final ROOT_INSTRA rootInstra) throws Exception { RESPONSE_INSTRA response = (RESPONSE_INSTRA)webServiceTemplate.marshalSendAndReceive(rootInstra, new WebServiceMessageCallback() { public void doWithMessage(WebServiceMessage webServiceMessage) { try { SoapMessage soapMessage = (SoapMessage)webServiceMessage; SoapHeader soapHeader = soapMessage.getSoapHeader(); StringSource headerSource = new StringSource(headerBuffer.toString()); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(headerSource, soapHeader.getResult()); } catch (Exception e) { new RuntimeException(e); } } }); return response; } }
Thanks in advance.


Reply With Quote
