Guest User

Untitled

a guest
Dec 18th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. public class WsHttpHeaderCallback implements WebServiceMessageCallback
  2. {
  3. private String headerKey;
  4. private String headerValue;
  5. private String soapAction;
  6.  
  7. public WsHttpHeaderCallback(String headerKey, String headerValue, String soapAction)
  8. {
  9. super();
  10. this.headerKey = headerKey;
  11. this.headerValue = headerValue;
  12. this.soapAction = soapAction;
  13. }
  14.  
  15. public WsHttpHeaderCallback()
  16. {
  17. super();
  18. }
  19.  
  20. @Override
  21. public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException
  22. {
  23. validateRequiredFields();
  24. addRequestHeader(headerKey, headerValue);
  25. if (StringUtils.hasText(this.soapAction))
  26. {
  27. AxiomSoapMessage axiomMessage = (AxiomSoapMessage) message;
  28. axiomMessage.setSoapAction(this.soapAction);
  29. }
  30. }
  31. private void addRequestHeader(String headerKey, String headerValue)
  32. {
  33. TransportContext context = TransportContextHolder.getTransportContext();
  34. WebServiceConnection connection = context.getConnection();
  35. if (connection instanceof HttpComponentsConnection)
  36. {
  37. HttpComponentsConnection conn = (HttpComponentsConnection) connection;
  38. HttpPost post = conn.getHttpPost();
  39. post.addHeader(headerKey, headerValue);
  40. }
  41. else if( connection instanceof ClientHttpRequestConnection )
  42. {
  43. ClientHttpRequestConnection conn = (ClientHttpRequestConnection)connection;
  44. conn.getClientHttpRequest().getHeaders().add(headerKey, headerValue);
  45. }
  46. }
  47. }
  48.  
  49. WebServiceResponse resp = (WebServiceResponse)webSvcTemplate.marshalSendAndReceive(wsUrl, request, new WsHttpHeaderCallback(headerKey, headerValue, "http://ws.com/soapAction") );
Add Comment
Please, Sign In to add comment