title: How can I overwrite the payload in mule
body: <p>I've a Soap request coming into mule flow. Am tasked with getting information out of payload and depending on outcome, push the original request to different jms queues. </p>
  
  <p>To get the desired information out of payload, I'm using XSLT tranformer (not XPath, because I need to get IDREF attribute from an element, based on IDREF, get the element and then a child element out of the IDREF object). </p>
  
  <p>Based on the outcome of the of XSLT tranformation, I use choice element to push original payload. Am storing original payload in a Session (can do it in Inbound as well). After XSLT tansformation, apply choice router to find out appropriate queue, and then want to push the original payload into queue(original payload in stored in a session variable). I am using <code>&lt;expression-component&gt;</code> element. Below is the snippet of mule-flow:</p>
  
  <pre><code>&lt;flow name="ProcessXML121Order"&gt;
      &lt;jms:inbound-endpoint queue="mviq.121.order" exchange-pattern="one-way" /&gt;
      &lt;logger message="121 order payload is #[payload]" level="INFO" /&gt;
      &lt;message-properties-transformer scope="session"&gt;
          &lt;add-message-property key="mviPayload" value="#[payload]"/&gt;
      &lt;/message-properties-transformer&gt;
      &lt;xm:xslt-transformer xsl-file="chooseVendor.xslt" /&gt;
      &lt;logger message="After xsl file payload is #[payload]" level="INFO" /&gt;      
      &lt;choice&gt;
          &lt;when expression="'EMSI'"&gt;
              &lt;logger message="Vendor is EMSI" level="INFO" /&gt;
              &lt;expression-component&gt;payload=#[header:SESSION:mviPayload]&lt;/expression-component&gt;
              &lt;jms:outbound-endpoint queue="mviq.121.order.emsi" /&gt;
          &lt;/when&gt;
          &lt;when expression="'PRMD'"&gt;
              &lt;logger message="Vendor is PRMD" level="INFO" /&gt;
              &lt;jms:outbound-endpoint queue="mviq.121.order.prmd" /&gt;
          &lt;/when&gt;
          &lt;when expression="'RSA'"&gt;
              &lt;logger message="Vendor is RSA" level="INFO" /&gt;
              &lt;logger message="RSA payload is #[payload]" level="INFO" /&gt;
              &lt;jms:outbound-endpoint queue="mviq.121.order.rsa" /&gt;
          &lt;/when&gt;
          &lt;otherwise&gt;
              &lt;logger message="Vendor is Error" level="INFO" /&gt;
              &lt;logger message="Vendor error payload is #[payload]" level="INFO" /&gt;
              &lt;jms:outbound-endpoint queue="mviq.error" /&gt;
          &lt;/otherwise&gt;
      &lt;/choice&gt;
  &lt;/flow&gt;
  </code></pre>
  
  <p>Following exception is thrown when evaluating payload=#[header:SESSION:mviPayload]</p>
  
  <pre><code>[ProcessXML121Order.stage1.02] exception.AbstractExceptionListener (AbstractExceptionListener.java:296) - 
  ********************************************************************************
  Message               : Execution of the expression "payload=#[header:SESSION:mviPayload]" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: byte[]
  Code                  : MULE_ERROR-29999
  --------------------------------------------------------------------------------
  Exception stack is:
  1. [Error: illegal use of operator: +]
  [Near : {... Unknown ....}]
               ^
  [Line: 1, Column: 0] (org.mvel2.CompileException)
    org.mvel2.ast.OperatorNode:46 (null)
  2. Execution of the expression "payload=#[header:SESSION:mviPayload]" failed. (org.mule.api.expression.ExpressionRuntimeException)
    org.mule.el.mvel.MVELExpressionLanguage:211 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/ExpressionRuntimeException.html)
  3. Execution of the expression "payload=#[header:SESSION:mviPayload]" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: byte[] (org.mule.api.MessagingException)
    org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:35 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
  --------------------------------------------------------------------------------
  Root Exception stack trace:
  [Error: illegal use of operator: +]
  [Near : {... Unknown ....}]
               ^
  [Line: 1, Column: 0]
      at org.mvel2.ast.OperatorNode.getReducedValueAccelerated(OperatorNode.java:46)
      at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
      at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:105)
      + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
  ********************************************************************************
  </code></pre>
  
  <p>I've 2 questions:</p>
  
  <ol>
  <li>How can I overwrite the original payload? (Not saying this is the best way to go)</li>
  <li>What is the better approach in this scenario? Is it advisable to keep original payload intact (in this case) and store XSLT output in other variable? How can I do that? What is the path (mule component) I can use to achieve that? I'm very new to Mule and seek community advice. </li>
  </ol>
  
  <p>Thanks for your time looking into this.</p>