user1493140
user1493140

Reputation: 6186

Mule 3.2 flow and cxf:jaxws-service

I am relatively new to mule and trying to define a mule flow which takes request XML via soap-based Web service. The XML is based on a complex schema and I have generated classes using WSDL2Java

After receiving the request cxf:jaxws-service executes the method submitOrder(SubmitOrderRequest parameters). After this method's execution I would like to transform the request XML to a little bit different format. Then this XML needs to be forwarded to another web service. The problem is that the mule message that comes out of ServiceImpl contains SubmitOrderResponse whereas I still want to work on SubmitOrderRequest.

<flow name="testService">
    <http:inbound-endpoint address="http://localhost:62005/test"
        exchange-pattern="request-response">
        <cxf:jaxws-service serviceClass="com.test.ServicePortType" />
    </http:inbound-endpoint>
    <component class="com.test.ServiceImpl" />
    <!--  transformer ref="MVIRequestTransformer" / -->
    <!--  xm:object-to-xml-transformer / -->
    <!-- logger message="XML payload is #[payload]" level="INFO" / -->
    <!-- SEND TRASNFORMED MESSAGE TO ANOTHER SERVICE -->
</flow>


@WebService(endpointInterface = "com.pennmutual.services.mvi.MVIServicePort")
public class ServiceImpl implements ServicePortType {
    ...
    @Override
    public SubmitOrderResponse submitOrder(SubmitOrderRequest parameters) {
    ...
    }
...
}

What are my options are. I can think of the following – 1. Put the request object somewhere in the context and retreive it later on for processing. 2. Change the return type of submitOrder to Object and return SubmitOrderRequest instead of SubmitOrderResponse.

Please suggest the best possible way to handle this situation. I am using mule 3.2.

Upvotes: 0

Views: 1764

Answers (1)

genjosanzo
genjosanzo

Reputation: 3264

I think there are two elegant way to do that (excluding the one that involves changing the webservice interface)

Store the request into a session variable and restore it afterwards. Here is how your flow would look like:

<flow name="testService">
<http:inbound-endpoint address="http://localhost:62005/test" exchange-pattern="request-response">
<cxf:jaxws-service serviceClass="com.test.ServicePortType" />
</http:inbound-endpoint>
<message-properties-transformer scope="session">
<add-message-property value="payload" key="originalPayload" />
</message-properties-transformer>
<component class="com.test.ServiceImpl" />
</flow>

Use the enricher around the component to store the returned value into a variable so that it won't become the payload of your flow. Following an example of how to achieve this

<flow name="Echo" doc:name="Echo">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="6090" path="echo" encoding="UTF-8" />
<cxf:jaxws-service serviceClass="org.mule.example.echo.Echo" />
<enricher target="#[variable:echo]">
<component class="org.mule.example.echo.Echo" />
</enricher>
<logger level="ERROR" message="#[variable:echo]"/>
</flow>

You can find more informations on the enricher here

Upvotes: 0

Related Questions