Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class WsHttpHeaderCallback implements WebServiceMessageCallback
- {
- private String headerKey;
- private String headerValue;
- private String soapAction;
- public WsHttpHeaderCallback(String headerKey, String headerValue, String soapAction)
- {
- super();
- this.headerKey = headerKey;
- this.headerValue = headerValue;
- this.soapAction = soapAction;
- }
- public WsHttpHeaderCallback()
- {
- super();
- }
- @Override
- public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException
- {
- validateRequiredFields();
- addRequestHeader(headerKey, headerValue);
- if (StringUtils.hasText(this.soapAction))
- {
- AxiomSoapMessage axiomMessage = (AxiomSoapMessage) message;
- axiomMessage.setSoapAction(this.soapAction);
- }
- }
- private void addRequestHeader(String headerKey, String headerValue)
- {
- TransportContext context = TransportContextHolder.getTransportContext();
- WebServiceConnection connection = context.getConnection();
- if (connection instanceof HttpComponentsConnection)
- {
- HttpComponentsConnection conn = (HttpComponentsConnection) connection;
- HttpPost post = conn.getHttpPost();
- post.addHeader(headerKey, headerValue);
- }
- else if( connection instanceof ClientHttpRequestConnection )
- {
- ClientHttpRequestConnection conn = (ClientHttpRequestConnection)connection;
- conn.getClientHttpRequest().getHeaders().add(headerKey, headerValue);
- }
- }
- }
- WebServiceResponse resp = (WebServiceResponse)webSvcTemplate.marshalSendAndReceive(wsUrl, request, new WsHttpHeaderCallback(headerKey, headerValue, "http://ws.com/soapAction") );
Add Comment
Please, Sign In to add comment