user2714010
user2714010

Reputation: 535

Using a enricher on a Mule outbound endpoint so that the message properties context is not lost

When i make a call to to soap web service using the soap component in Mule. The message properties context is lost. I understand a Mule enricher component can be used but not sure on the usage. Below you will find my test mule code

<spring:beans>
 <spring:bean id="myWebServiceImpl" class="com.xxx.xxx.service.MyWebServiceImpl">
 </spring:bean>

</spring:beans>
<custom-transformer class="com.xxx.xxx.service.TestTransformer" name="Java" doc:name="Java"/>
<flow name="testwebserviceFlow1" doc:name="testwebserviceFlow1">
    <file:inbound-endpoint path="c:\landing" responseTimeout="10000" doc:name="File"/>
    <object-to-string-transformer doc:name="Object to String"/>

    <http:outbound-endpoint exchange-pattern="request-response" method="POST" address="http://localhost:28081/MyWebService" responseTimeout="100000" doc:name="HTTP" >
        <cxf:jaxws-client operation="helloWorld" serviceClass="com.xxx.xxx.service.MyWebService" enableMuleSoapHeaders="true" doc:name="SOAP"/>
    </http:outbound-endpoint>
    <transformer ref="Java" doc:name="Transformer Reference"/>
    <logger level="INFO" doc:name="Logger"/>
</flow>

<flow name="MyWebServiceFlow" doc:name="MyWebServiceFlow">
    <http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:28081/MyWebService?wsdl" doc:name="HTTP" responseTimeout="100000">
        <cxf:jaxws-service serviceClass="com.xxx.xxx.service.MyWebService" doc:name="SOAP"/>
    </http:inbound-endpoint>
    <component doc:name="MyWebService">
        <spring-object bean="myWebServiceImpl"/>
    </component>
</flow>

Upvotes: 0

Views: 682

Answers (1)

Anton Kupias
Anton Kupias

Reputation: 4015

Yes, you can use an enricher to preserve your original message and put the return value of the web service into a variable. It works like this:

<enricher source="#[payload]" target="#[variable:myVal]">
    <http:outbound-endpoint exchange-pattern="request-response" method="POST" address="http://localhost:28081/MyWebService" responseTimeout="100000" doc:name="HTTP" >
        <cxf:jaxws-client operation="helloWorld" serviceClass="com.xxx.xxx.service.MyWebService" enableMuleSoapHeaders="true" doc:name="SOAP"/>
    </http:outbound-endpoint>
</enricher>

You can then later access the variable like this:

<logger message="#[variable:myVal]" level="INFO"/>

If you just want to call the web service and ignore any return values, you can also do that asynchronously by putting the http outbound inside <async></async> tags instead of the enricher.

Upvotes: 1

Related Questions