Wednesday, April 16, 2014

IIB/Worklight "HelloESB" Step 1: Building the IIB Webservice.

 DISCLAIMER : "The postings on this site are my own and don't necessarily represent IBM's positions, strategies or opinions."
 Introduction

"Hello World" is the quintessential introduction to any new technology and in that spirit we are building a  "Hello ESB/Worklight" kind of thing.

Notes and Assumptions:
  • This is not a tutorial to either WMB/IIB/WebServices/SQL/JavaScript/Worklight, etc. but I will provide as much detail as possible.
  • Originally this tutorial included a connection to DB/2 database in the back end but I opted to create a 'mimic' service for simplicity and since connecting to DB/2 from IIB is out of the scope of this blog entry.
  • Italic NOTES : Things to take into consideration.
  • You have installed
  • IIB and IIB toolkit installed (WMB 8.x would be sufficient and I highly recommend fixpack 8.0.0.4 for reasons to be stated later).
  • Worklight 6.x 

Now let us get this thing rolling.

Building the web service

Any webservice  starts with a WSDL that describes it, here is our WSDL as it appears in Rational Application Developer WSDL editor.


Figure 1 - Hello ESB WSDL

This WSDL defines one operation 'GetPerson' which takes a person user id as input and returns the PersonType data.
Figur 2-PersonType Object.
Now that we have a WSDL that describe the service, start IIB (or WMB toolkit) , and select New -> Integration Bus ->Start from WSDL and/or XSD files. then choose to Create an integration service.


Figure 3 - Start the service wizard
Figure 4 - Create an Integration Service wizard

Point the wizard to your WSDL and select the Web Services port
Figure 5 -  Selecting the wsdl

Figure 6 - Selecting the service port.

 Your screen should now have all WSDL/XSD artifacts imported , a project created and a Main flow with multiple subflows (The explanation of which is out of our scope).

In the Sevice project locate the Main flow under Project->Resources->Flows.

Figure 7 - Opening the Main flow


In the Canvas you will see IIB_BackEnd_Service service opened, Click the arrow next to service as in the diagram below, this will show you the 'GetPerson' yet to be implemented operation, click on it.



Figure 8 - Implementing GetPerson.

Take sometime to examine the empty flow in the application development pane if you want to explore more.
Figure 9 - New Flow screen.
 To create the response without actually connecting to a Database or back end of any type, you can simply drop a 'compute' node on the canvas, connect it to the input and connect its 'out' to the output.
figure 10 - compute node to mimic backend.


Double click on the node and insert the following code that will return the person data if the key is 'wwhite'.
Figure 11 - Code to mimic a back end return.

    CREATE FUNCTION Main() RETURNS BOOLEAN
    BEGIN
        CALL CopyMessageHeaders();
        -- CALL CopyEntireMessage();
        if (InputRoot.XMLNSC.ns:GetPerson.userID = 'wwhite') then
            set OutputRoot.SOAP.Body.ns:GetPersonResponse.(XMLNSC.NamespaceDecl)xmlns:NS3 = ns;
            set OutputRoot.SOAP.Body.ns:GetPersonResponse.(XMLNSC.NamespaceDecl)xmlns:NS4 = ns2;
            set OutputRoot.SOAP.Body.ns:GetPersonResponse.person.ns2:fullName = 'Walter White';
            DECLARE person REFERENCE to OutputRoot.SOAP.Body.ns:GetPersonResponse.person;
            set person.ns2:uID = 'Heisenberg';
            set person.ns2:email = 'Heisenberg@AMC.com';
            set person.ns2:address.ns2:street = '308 Negra Arrow Lane';
            set person.ns2:address.ns2:city = 'Albaquerque';
            set person.ns2:address.ns2:province = 'NM';
            set person.ns2:address.ns2:postalCode = '87111';
            set person.ns2:address.ns2:country = 'USA';
        end if;
        RETURN TRUE;
    END;TURN TRUE;
    END;


In the 'Integration Nodes' pane, select an Integration Node (aka. Broker), and create a new "Integration Server" (aka. Execution Group) and name it IIBBackEndServer. this integration server will now host your service.

Figure 12 - Creating a new Integration Server

 Select your Integration service and from the menu choose 'Deploy...' , then select IIBBackEndServer this will deploy the service into the server.
Figure 13 - Deploying the service into an Integration Server.

It takes a bit to do that (depending on your machine), when it is done you can now browse your server to see the deployed server including the URL you can use to access it.

Figure 14 - Examining the service URL.

Using SOAPUI (or your favorite webservice tool) point it into the service Query URL to test. First I import the WSDL definition using the URL from figure 14 above
Figure 15 - Using SOAPUI to test the service

Expand the service to the 'GetPerson'  and double click on Request1  , insert 'wwhite' as userID value and you should get the following reply

Figure 16 - Return from Service Output


IMPORTANT Notes :

I would like to thank Scott Rippley of ISSW , his help in the dark corners of WMB, toolkit and XMLNC was valuable.

Now that the service is up and running and before you move into the next step to connect to Worklight the following is important to notice.
  • The service runs on HTTP (we will secure it with SSL later).
  • This is a 'development' setup running the service on the HTTP port of the Integration server vs. Broker err.. Node wide port is another debate.
  • The code to set the name schemas at the top of the Main method will be a topic of another blog entry, keep following.

























2 comments:

  1. Nice information and great. Thanks for sharing with us. Great job. If you want to see a collection of https://xcritical.software visit our site

    ReplyDelete