title: How to replace response body in WSO2 ESB 4.8.1 Custom Handler
body: <p>I'm doing some validation in custom handler and in case of error sending response back to client from custom handler. However original payload of the client request is also sent back to client. How body can be emptied from response message ? If I debug SoapBody it seems to be empty but still somehow original payload is sent back to client.</p>
  
  <p>Here's my function for sending message back to user.</p>
  
  <pre><code>private void myAuthErrorHandler(MessageContext msgCtx)
  {
      Axis2MessageContext axis2smc = (Axis2MessageContext) msgCtx;
      org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
  
      SOAPBody body = msgCtx.getEnvelope().getBody();
  
      // remove the existing payload
      for (Iterator itr = body.getChildElements(); itr.hasNext();) {
          OMElement child = (OMElement) itr.next();
          child.detach();
      }
  
      log.error(""+msgCtx.getEnvelope());
      axis2MessageCtx.setProperty("HTTP_SC", "403");
      axis2MessageCtx.setProperty("NO_ENTITY_BODY", new Boolean("true"));
      axis2MessageCtx.setProperty("RESPONSE", "true");
      axis2MessageCtx.setTo(null);
      Axis2Sender.sendBack(msgCtx); 
  }
  </code></pre>
  
  <p>log.error(""+msgCtx.getEnvelope()); looks to be empty but still original body (payload) is sent back to client. </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;soapenv:Body&gt;&lt;/soapenv:Body&gt;&lt;/soapenv:Envelope&gt; 
  </code></pre>
  
  <p>Is this possibly a bug or why original body is sent back to client ? Is there's any other  methods to clear response body ?</p>
  
  <p>Thanks for any help.</p>