e2e jbi+project

Download E2E JBI+Project

Post on 07-Apr-2018

224 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

  • 8/6/2019 E2E JBI+Project

    1/13

    Using BPEL 2.0 to wrap an existing web service

    Summary The web service we have already created is generic; any client could potentiallymake use of it. However, this is not quite true for mobile clients.

    Mobile devices, by their nature, are less powerful than desktop machines and sohave a more restricted set of APIs available in Java. One particular restriction werun into for our project is that the SOAP implementation for mobile devices (JSR172) only contains a subset of the SOAP specification in use by the web servicewe have already created. In short, the mobile device will not be able to call ourweb service directly.

    Our solution is to build a new, lightweight web service which wraps our existingweb service and exposes only WSDL that can be consumed by the mobile device.

    The steps we are going to take are:1. Create WSDL to expose to mobile client.2. Import WSDL for the service implementation.3. Orchestrate.4. Test.

  • 8/6/2019 E2E JBI+Project

    2/13

    Implementation stepsIn the project panel, select New Project SOA BPEL Module and call it"TravelAgendaSvc"

    Creating JSR 172 compliant WSDLUnder the Process Files node, choose New WSDL Document... and call it"TravelAgenda".In the Abstract Configuration screen that follows, change the message part nameof the input to "parameters", and the name of the output to "results". Leave theelement/type at the defaults (xsd:string) and we will change these to appropriatetypes later. At the bottom of the dialog, uncheck "Generate partnerlinktypeautomatically".

    On the "Concrete Configuration" screen, choose "finish".

    Now we build the structures needed for the WSDL. In the WSDL editor, right clickon "Types" and Add Inline Schema.

  • 8/6/2019 E2E JBI+Project

    3/13

    The inline schema appears in tree structure in the editor window. In the propertiespanel, change Attribute Form Default and Element Form Default to "Qualified".Experimental evidence indicates that without this change, the client (which wewill generate later) will often fail to call our web service with namespace errors.

    Add a new Complex Type called "PersonComplexType" (keep all other defaults).Under the sequence, select Add Element... and call it "PersonId". For the type,use Existing Type Built-in Types int

    Add another Complex Type called "TripComplexType" (again, keep all otherdefaults). Add the following elements, of type "string":

    DepartureDateDepartureCityDestinationCityReason

    As there may be multiple trips for a given person, we need to be able to return

    multiple instances of the previous structure.Add a final Complex Type called "ResultComplexType", which is a sequencenamed "Trip" of type "TripComplexType".In the properties panel, Change MaxOccurs for the Trip to "unbounded", andMinOccurs to 0.

    Under the Elements node, we will create an element to represent to request andresponses. First, create an element called "AgendaRequest" with a Complex Typeof PersonComplexType. Next, create an element called "AgendaResponse" with aComplex Type of ResultComplexType.

    Now, under Messages/TravelAgendaOperation, we can change the types of parameters from string to the correct types. Change parameters to be theelement "AgendaRequest, and the results to be element "AgendaResponse".

    Under Bindings/TravelAgendaBinding/soap:binding, change the style in theproperties panel from "rpc" to "document".

    Inside TravelAgendaOperation, there is a soap:operation element. Although this is

  • 8/6/2019 E2E JBI+Project

    4/13

    blank by default, it is mandatory for the JSR172 wizard we will use in the nextstage of development. This could be any text but we will use "getTravelAgenda".In the same properties sheet, set the style to "document".

    By now, you should have created WSDL which looks like this:

  • 8/6/2019 E2E JBI+Project

    5/13

    Importing existing WSDLFirst, use the UDDI browser to locate the URL of the WSDL we created in the

    previous section.In the projects tab, Right-click on TravelAgendaSvc/Process Files and choose "New Other..."In the XML category, choose "External WSDL Document(s)". Enter the URL of theWSDL to import and press Finish.

    New items should be created in the project structure, under a folder calledlocalhost_8080.

    Build BPEL to wrap the web serviceNow to create the BPEL process which exposes the JSR 172 compliant WSDL andinvokes the service built previously in the repository-based project.

    Under TravelAgendaSvc/Process Files, choose "New BPEL Process..." and call it"TravelAgenda".

    Drag TravelAgenda.wsdl into the left column on the BPEL editor panel. It shouldbring up a dialog titled "Create New Partner Link". Fill out the fields as shown inthe following screenshot:

  • 8/6/2019 E2E JBI+Project

    6/13

    Expand the localhost_8080 folder and locate TravelAgendaPort.wsdl. Drag it ontothe right column of the BPEL editor and fill out the partner link dialog as shown:

  • 8/6/2019 E2E JBI+Project

    7/13

    In order, drag the following components into the business process:ReceiveAssignInvokeForEach

    (Containing an Assign)Reply

  • 8/6/2019 E2E JBI+Project

    8/13

    Double-click on the receive activity. Select the Partner Link"TravelAgendaPartnerLink" and the operation "TravelAgendaOperation". Create anew input variable, and take the default options.

    Double-click on the reply activity. Again, select the Partner Link"TravelAgendaPartnerLink" and the operation "TravelAgendaOperation". Create anew output variable, taking the default options.

  • 8/6/2019 E2E JBI+Project

    9/13

    Double-click on the invoke activity. Select the Partner Link"ExtTravelAgendaPartnerLink", and the operation "getTravelAgenda". Create inputand output variables, accepting the default options.

    Click on the first assignment activity, and select the mapper. Map PersonId from TravelAgendaOperationIn to GetTravelAgendaIn

    The structure which returns is repeating, and we have to perform the mapping foreach returned trip inside a loop. To do this, we will be using a predicate.

  • 8/6/2019 E2E JBI+Project

    10/13

    Click on the ForEach icon. Open the mapper, and perform the followingmappings:

    1. Drag a number literal "1" to the Start Value.2. Map the count of the "trip" nodes to the Final Value.3. Leave the Completion Condition empty.

    Click on the second assignment activity, and select the mapper. Expand theoutput variable GetTravelAgendaOut and add a predicate to the "trip" node asshown:

    Create a similar predicate for the Trip element of TravelAgendaOperationOut onthe input side. Map the fields under GetTravelAgendaOut to

    TravelAgendaOperationOut as shown in the screenshot:

  • 8/6/2019 E2E JBI+Project

    11/13

    Note: The date which is returned from the underlying web service is in theformat yyyy-mm-ddThh:mm:ssZ. By using the "Substring Before" BPELfunction, we can extract just the date from the depDate field.

    Finally, you should have a business process which looks like this:

  • 8/6/2019 E2E JBI+Project

    12/13

    Deploying the project JBI projects such as this one need to be deployed as a composite application.We could create a new project of this type, but in this case we will reuse theexisting project AppUserApps which has been used for the other sampleapplications.

    Right-click on the project "AppUserApps" and choose "Add JBI Module...". Selectthe project "TravelAgendaSvc" and press "Add Project JAR Files". Right-click on

    AppUserApps again, and choose "Deploy". This should report a successful buildand deployment via the output window in NetBeans.

    Testing the serviceFor this type of project, it is possible to test web services from within NetBeans.

    Expand AppUserApps, right-click on "Test" and select "New Test Case". Choose aname for your test case (e.g. TestAgentTravel). Select TravelAgenda.wsdl

  • 8/6/2019 E2E JBI+Project

    13/13

    underneath the TravelAgendaSvc item. On the next screen, select TravelAgendaOperation.

    A new screen will open with the XML to be sent as the request to the service.Change the contents of the PersonId element to "1", or any valid entry from thedatabase table.

    Right-click on the test in the project tab, and choose "Run". The testing frameworkrequires an existing message to compare each run against to determine if theexpected output was produced, and you may receive an alert asking if you wish tosave your first run.

    Note:Connect to the database in NetBeans first, to ensure that it is running.