Using dynamic partner links with BPEL 2.0

With most BPEL processes, partner links are static in that they reference a single instance of web service specified by the developer at design time (though typically configured at deployment).

In the majority of cases, this approach is fine. However, in this recipe we will consider a scenario in which a standard service contract might be implemented by multiple providers, the selection of which we want to dynamically configure at runtime.

An example of this, is the order aggregation process of our online bookstore, where at the point of placing an order with the publisher, we will need to invoke the appropriate service in order to route our book order to the correct publisher.

For this scenario, the BPEL language supports the concept of dynamic partner links, which enables the BPEL process to specify at runtime the endpoint of the web service being invoked and bind to it dynamically.

In this recipe, we will build on the order aggregation process of our online bookstore in order to route our book orders to the appropriate publisher.

Getting ready

In order to use this design pattern, you will need to define a standard WSDL to be implemented by each of your routing destinations (publishers, in our example).

For our purposes, we have defined the WSDL Publisher_Service_1.0.wsdl, which defines the operation submitBookOrder.

We have provided three basic implementations of this service, as defined in the following table:

Publisher

Endpoint

ACME

http://<host>:7001/soa-infra/services/default /PublisherACME/publisheracme_client_ep

Packt

http://<host>:7001/soa-infra/services/default /PublisherPackt/publisherpackt_client_ep

Skynet

http://<host>:7001/soa-infra/services/default /PublisherSkynet/publisherskynet_client_ep

These implementations are defined in the PublisherApp application, which is included in the sample for the book. You will need to open this sample in JDeveloper and deploy to your instance of the SOA Suite.

For the purpose of this recipe, we will extend the Message aggregation within a composite recipe to place the aggregated order, so you will either need to follow this sample recipe or open the sample solution with JDeveloper.

In addition, we are going to create a variable of type Endpoint Reference, defined in the schema ws-addressing.xsd. This is already defined and deployed to MDS. So, to reference this from within our BPEL process, we will need to create a file-based MDS connection in JDeveloper.

Instructions on how to do this are defined in the Creating a file-based MDS repository for JDeveloper recipe in Chapter 2, Using the Metadata Service to Share XML Artifacts.

How to do it...

  1. Open the Message Aggregation composite and drag a web service onto the External Reference swimlane. This will open the Create Web Service window. Give it the name PublisherService, and then browse to the PublisherService_1.0.wsdl WSDL included with the samples and select it.

    When prompted to localize files, ensure that the option Maintain original directory structure for imported files is selected, but deselect the option Rename duplicate files.

    Next, wire the WarehouseService service to the PublisherService service.

  2. The next step is to invoke the publisher service. Open the WarehouseService BPEL process, and drag an Invoke activity onto the end of the BPEL process (after the while loop).

    Open the Edit Invoke window, give it the name submitPublisherOrder, specify PublisherService as the Partner Link, and ensure submitBookOrder is selected as the operation.

    Create an input variable with the name publisherBookOrder and an output variable with the name publisherBookOrderResponse.

  3. We now need to initialize the publisherBookOrder variable. Drag an Assign activity on to the BPEL process just before the Invoke activity submitPublisherOrder.

    Map the content of inputVariable/payload/ns1:submitBookOrder to publisherBookOrder/payload/ns4:submitBookOrder.

  4. Open the Variables window for the BPEL process, and click on Create. This will open the Create Variable window. Specify a name for publisherEndpoint, specify a type of Element, and then click on Browse Elements… (the magnifying glass icon).

    This will open the Type Chooser window. Click on Import Schema File…. This will launch the Import Schema File window. Click on the Browse Resources… icon to open the SOA Resource Browser window.

  5. Ensure Resource Palette is selected from the dropdown, and then expand the following:
    IDE Connections > SOA-MDS > File Based MDS > soa > shared > common

    Select the schema ws-addressing.xsd as shown in the following screenshot:

    How to do it...
  6. In the Import Schema file, uncheck Copy to Project, and click on OK.

    In the Type Chooser window, select Endpoint Reference, as shown in the following screenshot:

    How to do it...
  7. Next, we need to set the variable publisherEndpoint to contain the endpoint of the appropriate publisher service that we wish to invoke.

    To populate the Address element, use a transformation activity rather than an Assign activity. We have used a concat function, as shown in the following screenshot, to create the endpoint based on the publisher name and map that to the Address element within the EndpointReference variable:

    How to do it...

    Note

    In reality, we would want to use the publisher name to look up the actual endpoint; but have just taken this approach to keep it simple.

  8. Open the Variables window for the BPEL process and click on Create. This will open the Create Variable window. Specify a name for publisherServiceRef, specify a type of element, and then click on Browse Elements….

    In the Type Chooser window, select Import Schema File…. Browse the filesystem and select the file ws-bpel_serviceref.xsd, included with the samples for the Getting ready section for this recipe. In the Import Schema File, uncheck Copy to Project, and click on OK.

    In the Type Chooser window, select service-ref.

  9. Drag an Assign activity onto the BPEL process, just before the Invoke activity, and give it the name setPublisherServiceRef.

    Map publisherEndpoint to publisherServiceRef/ns6:service-ref/xsd:any.

    JDeveloper will prompt you with the following warning:

    How to do it...
  10. Double click on To part of the copy rule to open the Expression Builder window, and manually update the XPath to $publisherServiceRef/ns5:EndpointReference.

    Note

    Note that the namespace prefix may not be ns5; rather, you should ensure that you specify the prefix mapped to the namespace http://schemas.xmlsoap.org/ws/2003/03/addressing.

  11. Then, right-click on the To part of the copy rule and select insertMissingToData.
    How to do it...
  12. Next, create a copy rule to map $publisherServiceRef to the PublisherService partner link, as shown in the following screenshot:
    How to do it...
  13. Deploy the updated WarehouseService composite to the Oracle SOA Suite and use Enterprise Manager to submit multiple submitBookOrder messages.

    Ensure that you specify either ACME, Packt, or Skynet as the publisher , you should see that orders are dynamically routed by the Warehouse Service to the appropriate publisher service.

How it works...

BPEL 2.0 provides support for dynamic partner links. This allows a BPEL 2.0 process to override the endpoint specified at design time for a partner link, with a value determined at runtime.

While we can override the endpoint for a partner link, all other attributes of our service definition remain fixed. So, to use this approach, we must define a common WSDL interface that all of our services will implement.

To dynamically invoke the appropriate endpoint at runtime, we need to update the endpoint reference of the partner link before invoking the service. To do this, we need to create a variable of type Service-Ref (as defined by ws-bpel_serviceref) and populate it with a variable of type EndPointReference (as defined by WS-Addressing) containing just an <Address> element populated with the endpoint of the publisher service that we wish to invoke.

This is important, since if we create an EndpointReference containing any of the other optional elements, the BPEL engine will throw a fault when we try and invoke the partner link.

To do this, we used a transformation activity rather than an Assign activity, since Assign will create all optional elements as well (we could still use an Assign, but we would need to add a remove rule for each of these elements). Once done, we inserted this into the Service-Ref variable.

Once we have created the Service-Ref variable, we just map it to the partner link before invoking the service, and BPEL will dynamically route the request to the updated endpoint.

There's more...

Oracle Service Bus also enables the dynamic routing of web service invocations at runtime.

If you are implementing a solution where OSB provides a virtualization layer on top of all your external services, we would recommend that as the appropriate place to implement dynamic routing.

However, if you are only using the core Oracle SOA Suite (minus the OSB), this isn't an option. In addition, there are occasions where you may want to dynamically assemble SCA composites to build a dynamic end-to-end business process. In this scenario, dynamic partner links can prove extremely useful.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.3.175