title: Mule: transform the results of outbound-endpoint
body: <p>The following flow transforms incoming an JSON payload into a SOAP message which is used in a subflow to make a webservice request. Everything works fine -- i'm able to send a response back for the original (incoming) request, but I want to add a final step to transform the SOAP result into JSON before sending it back to the client.</p>
  
  <p>Here is the flow:</p>
  
  <pre><code>&lt;mule ...&gt;
      &lt;data-mapper:config name="json2xml_grf" transformationGraphPath="json2xml.grf" doc:name="DataMapper"/&gt;
      &lt;flow name="simpleFlow" doc:name="simpleFlow"&gt;
          &lt;http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/&gt;
          &lt;set-property propertyName="Access-Control-Allow-Origin" value="*" doc:name="Property"/&gt;
          &lt;choice doc:name="Choice"&gt;
              &lt;when expression="#[message.inboundProperties['http.method'] != 'OPTIONS']"&gt;
                  &lt;data-mapper:transform config-ref="json2xml_grf" doc:name="DataMapper"/&gt;
                  &lt;flow-ref name="invokeCalculatorService" doc:name="invokeCalculator"/&gt;
              &lt;/when&gt;
              &lt;otherwise&gt;
                  &lt;http:response-builder status="200" doc:name="HTTP Response Builder"&gt;
                  ...
                  &lt;/http:response-builder&gt;
              &lt;/otherwise&gt;
          &lt;/choice&gt;
      &lt;/flow&gt;
      &lt;flow name="invokeService" doc:name="invokeService"&gt;
          &lt;cxf:proxy-client payload="body" enableMuleSoapHeaders="true" doc:name="Proxy Client"&gt;
          &lt;/cxf:proxy-client&gt;
          &lt;mulexml:xslt-transformer maxIdleTransformers="2" maxActiveTransformers="5" xsl-file="/Users/jsleeuw/MuleStudio/workspace/calc/src/main/resources/transformsoap.xslt" doc:name="XSLT"/&gt;
          &lt;http:outbound-endpoint exchange-pattern="request-response" doc:name="CalculatorService" method="POST" host="service-host" port="30001"/&gt;
      &lt;/flow&gt;
  &lt;/mule&gt;
  </code></pre>
  
  <p>Putting a DataMapper at the end of the subflow like this:</p>
  
  <pre><code>...
  &lt;flow-ref name="invokeCalculatorService" doc:name="invokeCalculator"/&gt;
  &lt;data-mapper:transform config-ref="xml2json_grf" doc:name="DataMapper"/&gt;
  ...
  </code></pre>
  
  <p>Results in this error:</p>
  
  <pre><code>********************************************************************************
  Message               : Error executing graph: ERROR (com.mulesoft.mule.module.datamapper.api.exception.DataMapperExecutionException). Message payload is of type: DepthXMLStreamReader
  Code                  : MULE_ERROR--2
  --------------------------------------------------------------------------------
  Exception stack is:
  1. Content is not allowed in prolog. (org.xml.sax.SAXParseException)
    org.apache.xerces.util.ErrorHandlerWrapper:-1 (null)
  2. org.xml.sax.SAXParseException: Content is not allowed in prolog. (net.sf.saxon.trans.DynamicError)
    net.sf.saxon.event.Sender:308 (null)
  3. XPath evaluation failed (org.jetel.exception.JetelRuntimeException)
    org.jetel.component.tree.reader.xml.XmlXPathEvaluator:81 (null)
  4. Error executing graph: ERROR (com.mulesoft.mule.module.datamapper.api.exception.DataMapperExecutionException)
    com.mulesoft.mule.module.datamapper.impl.DefaultGraphExecutor:83 (null)
  5. Error executing graph: ERROR (com.mulesoft.mule.module.datamapper.api.exception.DataMapperExecutionException). Message payload is of type: DepthXMLStreamReader (com.mulesoft.mule.module.datamapper.processors.DataMapperMessageExecutionException)
    com.mulesoft.mule.module.datamapper.processors.DataMapperMessageProcessor:135 (null)
  -------------------------------------------------------------------------------- 
  </code></pre>
  
  <p>Whereas putting the datamapper at the end of the subflow ends up blocking the response.</p>
  
  <p>How should I go about transforming my response?</p>