Charu Khurana
Charu Khurana

Reputation: 4551

How to write Mule muleEventContext.getMessage().getPayloadAsString() in MEL in mule-config

I've a soap service flow which gets inbound request through <cxf:proxy-service>. I have a java component right after it to get payload as String.

Here is my flow:

<flow name="soapService">
    <http:inbound-endpoint address="${service.address}" exchange-pattern="request-response">
        <cxf:proxy-service wsdlLocation="classpath:service.wsdl" namespace="http://pennmutual.com/services/mvi" service="MVIService" enableMuleSoapHeaders="false"/>                
    </http:inbound-endpoint>        
    <component class="test.GetPayload" />
  .
  .
  .
 </flow>

And here is my GetPayload class:

public Object onCall(MuleEventContext eventContext) throws Exception {
    String requestXml = null;
    try {

        requestXml = eventContext.getMessage().getPayloadAsString();
        logger.debug("Request XML " + requestXml);

    } catch (Exception e) {
        e.printStackTrace();
    }
    return requestXml;
}

I need a way to get rid of GetPayload class and do same thing in my mule-config. I tried <object-to-string-transformer/>

and <set-payload value="#[message.payloadAsString]"/>

but message.payloadAsString throws exception. I don't understand why.

Upvotes: 1

Views: 3689

Answers (1)

David Dossot
David Dossot

Reputation: 33413

Use: #[message.payloadAs(java.lang.String)]

From: http://www.mulesoft.org/documentation/display/current/MEL+Cheat+Sheet#MELCheatSheet-PayloadandAttachments

Upvotes: 4

Related Questions