Friday, July 22, 2011

MULE HTTP Web Service - Step5. Configuring mule-config.xml as a http web service

This step involves in configuring the mule-config.xml to process the incoming SOAP request.

1. Add the client jar to your pom.xml if it is not added already. This jar contains the request and response objects that we will be using in processing the request.

2. Create a folder named lib under the project root folder and copy the mule-data-int-3.1.6.jar and mule-data-int-db-3.1.6.jar to the lib folder. These jars would be required to run the service outside of the Mule ESB. When the project runs out of Mule ESB, we would require a license from Mulesoft to use the Mule Data Integrator.


3. Go to Project Build path and add the Mule Library to your classpath. In the order and support, make sure that the Mule Library is having the highest priority. This is used to ensure that Mule Data Integrator would work with Mule IDE. In order to use MDI Maps outside Mule IDE, we would require a license from MuleSoft.

NOTE: For Mule MDI's to work, the MDI runtime has to be installed on the Mule Distribution. Please follow the steps in this link to do it easily. Install Mule Data Integrator

Add Library

Select the Mule Distribution that has MDI installed

Update the Order and Support of Mule Libraries
4. Package the ShippingServiceTransformers project into a zip file and place it under src/main/resources location.

ShippingServiceTransformers.zip
5. Configure the service in mule-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.2"
    xmlns:http="http://www.mulesource.org/schema/mule/http/2.2"
    xmlns:data-int="http://www.mulesoft.com/schema/mdi/data-int/2.2"
    xmlns:saaj="http://www.mulesource.org/schema/mule/saaj/2.2"
    xmlns:mule-xml="http://www.mulesource.org/schema/mule/xml/2.2"
    xsi:schemaLocation="
       http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
       http://www.mulesource.org/schema/mule/vm/2.2 http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd
       http://www.mulesource.org/schema/mule/http/2.2 http://www.mulesource.org/schema/mule/http/2.2/mule-http.xsd
       http://www.mulesoft.com/schema/mdi/data-int/2.2 http://www.mulesoft.com/schema/mdi/data-int/2.2/mule-module-data-int.xsd
       http://www.mulesource.org/schema/mule/saaj/2.2 http://www.mulesource.org/schema/mule/saaj/2.2/mule-saaj.xsd
       http://www.mulesource.org/schema/mule/xml/2.2 http://www.mulesource.org/schema/mule/xml/2.2/mule-xml.xsd">

    <!-- Transformers Configuration START -->
    <data-int:transformer name="orderShippingInfoRequest"
        mapPath="/ShippingServiceTransformers/Maps/request/OrderShippingInfoRequestMap"
        resultType="JAVA">
        <data-int:project archive="ShippingServiceTransformers.zip"
            project="ShippingServiceTransformers" />
    </data-int:transformer>

    <data-int:transformer name="orderShippingInfoResponse"
        mapPath="/ShippingServiceTransformers/Maps/response/OrderShippingInfoResponseMap">
        <data-int:project archive="ShippingServiceTransformers.zip"
            project="ShippingServiceTransformers" />
    </data-int:transformer>

    <data-int:transformer name="getShippingInfoRequest"
        mapPath="/ShippingServiceTransformers/Maps/request/GetShippingInfoRequestMap"
        resultType="JAVA">
        <data-int:project archive="ShippingServiceTransformers.zip"
            project="ShippingServiceTransformers" />
    </data-int:transformer>

    <data-int:transformer name="getShippingInfoResponse"
        mapPath="/ShippingServiceTransformers/Maps/response/GetShippingInfoResponseMap">
        <data-int:project archive="ShippingServiceTransformers.zip"
            project="ShippingServiceTransformers" />
    </data-int:transformer>
    <!-- Transformers Configuration END -->

    <model>
        <service name="ShippingService">
            <inbound>
                <http:inbound-endpoint
                    address="http://localhost:9090/ShippingService"
                    synchronous="true">
                    <transformers>

                        <!-- Transform Incoming Soap Message to String -->
                        <saaj:soap-message-to-document-transformer />
                        <mule-xml:dom-to-xml-transformer
                            returnClass="java.lang.String" />
                    </transformers>
                    <response-transformers>

                        <!-- Transform XML to Soap Response -->
                        <mule-xml:xml-to-dom-transformer
                            returnClass="org.w3c.dom.Document" />
                        <saaj:document-to-soap-message-transformer
                            propagateHeaders="false" />
                    </response-transformers>
                </http:inbound-endpoint>
            </inbound>
            <outbound>
                <pass-through-router>
                    <vm:outbound-endpoint path="routeData"
                        synchronous="true" />
                </pass-through-router>
            </outbound>
        </service>

        <!-- Log Incoming Request and route it accordingly -->
        <service name="RouterService">
            <inbound>
                <vm:inbound-endpoint path="routeData"
                    synchronous="true" />
            </inbound>
            <log-component />
            <outbound>

                <!--
                    Route the request to the corresponding component
                    based on the incoming request
                -->
                <filtering-router>
                    <vm:outbound-endpoint path="orderShippingRequestIN"
                        synchronous="true" />
                    <wildcard-filter pattern="*OrderShippingRequest*" />
                </filtering-router>
                <filtering-router>
                    <vm:outbound-endpoint path="getShippingRequestIN"
                        synchronous="true" />
                    <wildcard-filter pattern="*GetShippingInfoRequest*" />
                </filtering-router>
            </outbound>
        </service>

        <!-- This service processes order shipping request -->
        <service name="OrderShippingService">
            <inbound>
                <vm:inbound-endpoint path="orderShippingRequestIN"
                    synchronous="true">
                    <transformers>
                        <transformer ref="orderShippingInfoRequest" />
                    </transformers>
                    <response-transformers>
                        <transformer ref="orderShippingInfoResponse" />
                    </response-transformers>
                </vm:inbound-endpoint>
            </inbound>
            <component
                class="org.mybusiness.shippingservice.components.OrderShippingComponent">
            </component>
        </service>

        <!-- This service processes get Shipping Info request -->
        <service name="GetShippingService">
            <inbound>
                <vm:inbound-endpoint path="getShippingRequestIN"
                    synchronous="true">
                    <transformers>
                        <transformer ref="getShippingInfoRequest" />
                    </transformers>
                    <response-transformers>
                        <transformer ref="getShippingInfoResponse" />
                    </response-transformers>
                </vm:inbound-endpoint>
            </inbound>
            <component
                class="org.mybusiness.shippingservice.components.GetShippingInfoComponent">
            </component>
        </service>
    </model>
    
</mule>

No comments:

Post a Comment