Powered By Blogger

Feb 6, 2014


Modelling a User Registration Process using WSO2 Developer Studio


Let's assume there is an Online Ticket Reservation System and a customer wants to register in the system and make the Request. In that case first thing needs to be done is Register the user in the System. 

I am going to implement this scenario using WSO2 Developer Studio, WSO2 Enterprise Service Bus (ESB) and WSO2 Data Service Server (DSS). As Prerequisites you need to download and install relevant WSO2 products.

Main Processes are as below

1. Configure Servers
2. Set up Database using MySQL
3. Modeling Customer Data Service
4. Modeling Registration Process
5. Deploy the artifacts
6. Test the scenario

Configure Servers

WS02 ESB

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

WSO2 DSS :

Set offset parameter to '1'

Enable database access by copying the MySQL driver library (mysql-connector-java-5.1.13-bin.jar) to $DSS_HOME/repository/components/lib.


Set up Database using MySQL


  • Create database named 'ticketReservation' and then create a table named 'User'



CREATE TABLE User (
  UID int(11) NOT NULL AUTO_INCREMENT,
  UName varchar(200) NOT NULL,
  password varchar(200) DEFAULT NULL,
  PRIMARY KEY (`UID`)
)

Modeling Customer Data Service

  • Go to Developer Studio dashboard and select Data Service Project and then select 'Create new Data Service'

  • Give relevant information and select Next. In the next wizard give relevant data as shown below

Database Engine: MySQL

Driver Class : com.mysql.jdbc.Driver

JDBC URL : jdbc:mysql://localhost:3306/ticketReservation

Username : [username according to MySQL credentials]
Password: [password according to MySQL credentials]

  • Then open UserDSS.dbs and copy and paste below code

<data name="UserDSS" serviceNamespace="http://dataservice" serviceGroup="UserDSS">

    <description/>

    <config id="test">

        <property name="org.wso2.ws.dataservice.user">root</property>
        <property name="org.wso2.ws.dataservice.password">root</property>
        <property name="org.wso2.ws.dataservice.protocol">jdbc:mysql://localhost:3306/ticketReservation</property>
        <property name="org.wso2.ws.dataservice.driver">com.mysql.jdbc.Driver</property>
    </config>
   <query id="InsertPersonQ" useConfig="test">
        <sql>INSERT INTO User(UName, password) VALUES(?,?)</sql>
        <param name="UName" ordinal="1" sqlType="STRING"/>
        <param name="password" ordinal="2" sqlType="STRING"/>
    </query>
    <operation name="InsertPerson">
        <call-query href="InsertPersonQ">
            <with-param name="UName" query-param="UName"/>
            <with-param name="password" query-param="password"/>
        </call-query>
    </operation>
</data>

Modeling Registration Process

  • Go to Developer Studio dashboard and create a new ESB config project with the name 'CustomerESB'
  • Then go to the project explorer and right click on 'CustomerESB' and select New-> Proxy Service and select option 'Create new Proxy Service' 
  • Then create a proxy with a name 'userRegistrationProxy' and click Finish
  • Go to the source view of the userRegistrationProxy and copy and paste the below code
<proxy xmlns="http://ws.apache.org/ns/synapse" name="userRegistrationProxy" transports="http https" startOnLoad="true" trace="disable">
    <target>
        <inSequence>
            <log level="full">
                <property name="text" value="** User Registration Process **"/>
            </log>
            <property xmlns:heal="http://userRegistration.wso2" name="UName" expression="//heal:setUserInfo/heal:UName/text()" scope="default" type="STRING"/>
            <property xmlns:heal="http://userRegistration.wso2" name="password" expression="//heal:setUserInfo/heal:password/text()" scope="default" type="STRING"/>
            <log level="custom" separator=",">
                <property name="UName" expression="$ctx:UName"/>
                <property name="password" expression="$ctx:password"/>
            </log>
            <log level="custom" separator=",">
                <property name="MessageFlow" value="======================= Before Sending message to Data Service : RegistrationDSS ======================="/>
            </log>
            <enrich>
                <source type="inline" clone="true">
                    <p:InsertPerson xmlns:p="http://dataservice">
                        <xs:UName xmlns:xs="http://dataservice">$1</xs:UName>
                        <xs:password xmlns:xs="http://dataservice">$2</xs:password>
                    </p:InsertPerson>
                </source>
                <target type="body"/>
            </enrich>
            <enrich>
                <source type="property" clone="true" property="UName"/>
                <target xmlns:p="http://dataservice" xpath="//p:InsertPerson/p:UName/text()"/>
            </enrich>
            <enrich>
                <source type="property" clone="true" property="password"/>
                <target xmlns:p="http://dataservice" xpath="//p:InsertPerson/p:password/text()"/>
            </enrich>
            <log level="custom" separator=",">
                <property name="MessageFlow" value="======================= Sending Request To Database : RegistrationDSS ======================="/>
            </log>
            <log level="full" separator=","/>
            <send>
                <endpoint key="UserRegistration"/>
            </send>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </target>
    <publishWSDL uri="http://192.168.1.2:9764/services/UserDSS?wsdl"/>
</proxy>


  • Right click on the ESB project and select New -> Endpoint and the create an Address Endpoint named 'UserRegistration'
  • Go to the source view and copy and paste the below code
<?xml version="1.0" encoding="UTF-8"?>
<endpoint xmlns="http://ws.apache.org/ns/synapse" name="UserRegistration">
   <address uri="http://192.168.1.2:9764/services/UserDSS/" > 
</endpoint>


  • Final 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

  • 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 DSS 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 and check the database, newly inserted user has been added.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                              xmlns:heal="http://userRegistration.wso2">
                <soapenv:Body>
                    <heal:setUserInfo>
                        <heal:UName>def</heal:UName>
<heal:password>456</heal:password>
                    </heal:setUserInfo>
                </soapenv:Body>
</soapenv:Envelope>


  • See the logs in ESB console

No comments:

Post a Comment