Powered By Blogger

Feb 8, 2014

Service Integration with WSO2 Developer Studio, WSO2 Enterprise Service Bus (ESB) and WSO2 Application Server (AS)

With related to the previous post let's assume a customer wants to make the request about booking tickets online. For implementing, as prerequisites you need to download and install WSO2 products (Developer Studio, ESB, AS) and also below mentioned third party tools and libraries.

  • Apache ActiveMQ
      • activemq-broker-5.9.0.jar
      • activemq-client-5.9.0.jar
      • geronimo-j2ee-management_1.1_spec-1.0.1.jar
      • geronimo-jms_1.1_spec-1.1.1.jar
Main Processes

1. Configure Servers
2. Modeling Booking Service
3. Modeling Request Process
4. Deploy the artifacts
5. Test the scenario

Configure Servers


WS02 ESB : 

  • Leave the offset parameter as it is to ‘0’. ($CARBON_HOME/repository/conf/carbon.xml)

  • Enable ESB to talk over a message queue by copying  the ActiveMQ libraries to the $ESB_HOME/repository/components/lib.
  • Enable the JMS transport on the ESB by uncommenting the following two sections in the ESB's configuration file.($ESB_HOME/repository/conf/axis2/axis2.xml)
<transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener">/transportReceiver>

AND

<transportSender name="jms"   class="org.apache.axis2.transport.jms.JMSSender"/>

WSO2 AS :

  • Set offset parameter to ‘2’.
  • To enable the Application Server to talk over a message queue follow the same step did for ESB previously.
  • To enable the JMS transport on the App Server follow the same step did for ESB previously.

Modeling Booking Service


  • Go to Developer Studio dashboard and select Axis2service project. Then select option Create new Axis2 Service.
  • Then create a service called Request.



  • Then go to the source view and copy and paste the below code.


public class Request {

private String customerID;
private String requestID;
private String movieName;
private int noOfSeats;
private String request;

public void setCustomerRequest(String customerID, String requestID,
String movieName, int noOfSeats) {
this.customerID = customerID;
this.requestID = requestID;
this.movieName = movieName;
this.noOfSeats = noOfSeats;
}

public String getCustomerRequest() {
return request;

}

}

  • Then right click on the created Axis2 Project and New-> Axis2 Service Class and then create a new Axis2 Class name ‘CreateRequest’. Then go to the source view and copy and paste the below code
public class CreateRequest { public Request createrequest(String customerID, String requestID, String movieName, int noOfSeats) { Request request = new Request(); request.setCustomerRequest(customerID, requestID, movieName, noOfSeats); return request; } }


  • JMS transport should enable since this service will communicate via JMS transport, add the below code to services.xml under /src.main.resources/META-INF.  
<transports>
<transport>jms</transport>
</transports>


 Modeling Request Process


  • Go to Developer Studio dashboard and then click on ESB Config project and select option create new ESB Config project with the name CustomerESB.
  • Then right click on that and select New-> Proxy Service and then create a new Proxy called 'ticketRequestProxy'
  • Then go to the source view and copy and paste the below code.



<proxy xmlns="http://ws.apache.org/ns/synapse" name="ticketRequestProxy" transports="http https" startOnLoad="true" trace="disable">
   <target>
        <inSequence>
            <log level="full">
                <property name="text" value="** User Ticket Request Process **"/>
            </log>
            <property xmlns:heal="http://ticketreservationRequest.wso2" name="customerID" expression="//heal:getUserRequest/heal:customerID/text()" scope="default" type="STRING"/>
            <property xmlns:heal="http://ticketreservationRequest.wso2" name="requestID" expression="//heal:getUserRequest/heal:requestID/text()" scope="default" type="STRING"/>
            <property xmlns:heal="http://ticketreservationRequest.wso2" name="movieName" expression="//heal:getUserRequest/heal:movieName/text()" scope="default" type="STRING"/>
            <property xmlns:heal="http://ticketreservationRequest.wso2" name="noOfSeats" expression="//heal:getUserRequest/heal:noOfSeats/text()" scope="default" type="STRING"/>
            <log level="custom" separator=",">
                <property name="movieName" expression="$ctx:movieName"/>
                <property name="noOfSeats" expression="$ctx:noOfSeats"/>
            </log>
            <log level="custom" separator=",">
                <property name="MessageFlow" value="======================= Before Sending User Request to RequestService : ======================="/>
            </log>
            <enrich>
                <source type="inline" clone="true">
                    <p:createrequest xmlns:p="http://axis.com">
                        <xs:customerID xmlns:xs="http://axis.com">x</xs:customerID>
                        <xs:requestID xmlns:xs="http://axis.com">y</xs:requestID>
                        <xs:movieName xmlns:xs="http://axis.com">z</xs:movieName>
                        <xs:noOfSeats xmlns:xs="http://axis.com">0</xs:noOfSeats>
                    </p:createrequest>
                </source>
                <target type="body"/>
            </enrich>
            <enrich>
                <source type="property" clone="true" property="customerID"/>
                <target xmlns:p="http://axis.com" xpath="//p:createrequest/p:customerID/text()"/>
            </enrich>
            <enrich>
                <source type="property" clone="true" property="requestID"/>
                <target xmlns:p="http://axis.com" xpath="//p:createrequest/p:requestID/text()"/>
            </enrich>
            <enrich>
                <source type="property" clone="true" property="movieName"/>
                <target xmlns:p="http://axis.com" xpath="//p:createrequest/p:movieName/text()"/>
            </enrich>
            <enrich>
                <source type="property" clone="true" property="noOfSeats"/>
                <target xmlns:p="http://axis.com" xpath="//p:createrequest/p:noOfSeats/text()"/>
            </enrich>
            <log level="custom" separator=",">
                <property name="MessageFlow" value="======================= Sending Request To RequestService======================="/>
            </log>
            <log level="full" separator=","/>
            <send receive="loginRequest">
                <endpoint key="SendRequest"/>
            </send>
        </inSequence>
        <outSequence>
            <log level="full" separator=","/>
            <send/>
        </outSequence>
        <faultSequence/>
    </target>
    <publishWSDL uri="http://192.168.1.2:9765/services/CreateRequest?wsdl"/>
</proxy>


  • The design of the proxy is as follows


Deploy the artifacts

  • Go to Developer Studio dashboard and select Composite Application Project and the give the name as 'CustomerCApp' and dependencies as stated below
    • ticketRequestProxy
    • CustomerAxis2ServiceProject

  • Then Right click on the CustomerCApp and select 'Export Composite Application Project' then give a name and destination. Now you have the .car file
  • Then start the WSO2 AS by navigate to $CARBON_HOME/bin and type the command wso2server.sh (Linux) or wso2server.bat (Windows)
  • Then deploy the created .car file on the server.
  • Then start WSO2 ESB and deploy the .car file
Test the scenario

  • Send the below soap request 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                              xmlns:heal="http://ticketreservationRequest.wso2">
                <soapenv:Body>
                    <heal:getUserRequest>
  <heal:customerID>123</heal:customerID>
<heal:requestID>100</heal:requestID>
                        <heal:movieName>Harry Potter</heal:movieName>
<heal:noOfSeats>3</heal:noOfSeats>
                    </heal:getUserRequest>
                </soapenv:Body>
</soapenv:Envelope>


  • See the logs in ESB console

No comments:

Post a Comment