title: Sending SOAP request with MessageCallback and MessageExtractor
body: <p>When sending a <code>SOAP</code> request through Spring's <a href="http://docs.spring.io/spring-ws/site/apidocs/org/springframework/ws/client/core/WebServiceTemplate.html" rel="nofollow"><code>WebServiceTemplate</code></a>, I would like to provide my payload and perform operation on both the request and the response of it. This is because I need some details from the headers of the request/response.</p>
  
  <p>In the <a href="http://docs.spring.io/spring-ws/site/reference/html/client.html" rel="nofollow">Spring documentation</a> I have found it's possible to alter the request with a <a href="http://docs.spring.io/spring-ws/site/apidocs/org/springframework/ws/client/core/WebServiceMessageCallback.html" rel="nofollow"><code>WebServiceMessageCallback</code></a> and the response with a <a href="http://docs.spring.io/spring-ws/site/apidocs/org/springframework/ws/client/core/WebServiceMessageExtractor.html" rel="nofollow"><code>WebServiceMessageExtractor</code></a>.</p>
  
  <p>The problem I'm having is that the <a href="http://docs.spring.io/spring-ws/site/apidocs/org/springframework/ws/client/core/WebServiceTemplate.html" rel="nofollow"><code>WebServiceTemplate</code></a> seems to <em>choose</em> between providing a <em>payload</em> and providing <code>MessageCallback</code>/<code>MessageExtractor</code>.</p>
  
  <p>With that, I mean there are the following methods available:</p>
  
  <ul>
  <li><code>marshalSendAndReceive(Object requestPayload, WebServiceMessageCallback requestCallback)</code></li>
  <li><code>sendAndReceive(WebServiceMessageCallback requestCallback, WebServiceMessageExtractor&lt;T&gt; responseExtractor)</code></li>
  <li><code>sendAndReceive(WebServiceMessageCallback requestCallback, WebServiceMessageCallback responseCallback)</code></li>
  </ul>
  
  <p>But nothing to provide <strong>all three</strong>. So providing the <strong>payload</strong>, a <a href="http://docs.spring.io/spring-ws/site/apidocs/org/springframework/ws/client/core/WebServiceMessageCallback.html" rel="nofollow"><code>WebServiceMessageCallback</code></a> for operations on the request and a <a href="http://docs.spring.io/spring-ws/site/apidocs/org/springframework/ws/client/core/WebServiceMessageCallback.html" rel="nofollow"><code>WebServiceMessageCallback</code></a>/<a href="http://docs.spring.io/spring-ws/site/apidocs/org/springframework/ws/client/core/WebServiceMessageExtractor.html" rel="nofollow"><code>WebServiceMessageExtractor</code></a> for operations on the response.</p>
  
  <p>In the documentation they do provide the following snippet:</p>
  
  <pre><code>public void marshalWithSoapActionHeader(final Source s) {
      final Transformer transformer = transformerFactory.newTransformer();
      webServiceTemplate.sendAndReceive(new WebServiceMessageCallback() {
      public void doWithMessage(WebServiceMessage message) {
          transformer.transform(s, message.getPayloadResult());
      },
      new WebServiceMessageExtractor() {
          public Object extractData(WebServiceMessage message) throws IOException
              // do your own transforms with message.getPayloadResult()
              //     or message.getPayloadSource()
          }
      });
  }
  </code></pre>
  
  <p>But passing your payload into an innerclass just to pass in a payload doesn't seem like clean code.</p>
  
  <p>It doesn't really seem logical that you can provide a payload and callback for tampering the request, but not the response. Or tampering the request and response without providing a payload. How would I go about if I'd like to send a payload and access both the request and response?</p>