Tuesday, June 16, 2015

Dynamic partnerlink in SOA



The dynamic partnerlink feature enables you to dynamically assign an endpoint reference to a partnerlink for use at runtime in BPEL versions 1.1 and 2.0. It is similar to switch activity in the sense that based on the input condition it evaluate the end point dynamically
In this implementation we will first try to understand how dynamic partnerlink can save the complexity and time for developer at design time. Let suppose there is a requirement to design process for which the end point is not fixed i.e. there are multiple end points that can be used. In an ideal scenario a developer will define multiple partnerlink and will write separate logic to use them. This will un necessarily complicate the code. This can be simplified using a single dynamic partnerlink. In order to achieve this we will first create three web services (end point URL) based on same wsdl. These will be a simple web services which will accept the input, will do some enhancement and will return it back to the calling service. Next is we will define another process where in we will define a dynamic partnerlink to call these end point url based on input. In order to achieve this a variable will be created based on ws-addressing Endpoint-reference (more detail on the implementation). This variable will serve as an input to the dynamic partnerlink for deciding on which web service has to be called. Based on the input this variable will be updated with the end point url of the predefined web services and the services will be called dynamically. In our typical use case we have defined 3 services which will be called based on the input values. If input is less than 5 call ServiceA, If it is between 5 and 10 call ServiceB otherwise call ServiceC. All these invocation will done through a single partnerlink in the calling process.

First of all define three business service.
Create three business service based on same input parameter and output parameter but may have different logic for implementation.

Let’s call them ServiceA, ServiceB and ServiceC.



Get the end point url for these three services as below
http://localhost:8001/soa-infra/services/default/ServiceA/servicea_client_ep?WSDL
http://localhost:8001/soa-infra/services/default/ServiceB/serviceb_client_ep?WSDL
http://localhost:8001/soa-infra/services/default/ServiceC/servicec_client_ep?WSDL
Now Create a WSDL which contain these services as shown below.





The important point to note is that all the services will be based on same binding and port that is all the services needs to have similar input and output format that is the message type will remain the same. As it appears all the services calls the actual end point url of the Services we have defined in the first step.
Create a synchronous BPEL process and drag and drop a web service in the external reference of the composite.
Define this web service based on the WSDL you have created now.
So once complete these steps your process will look like this.








The next step is to create a variable from ws-addressing XSD available in w3.
Import the schema from the following url in to your jdeveloper as ws-addressing.xsd
http://schemas.xmlsoap.org/ws/2003/03/addressing/





Create a variable based on the end point reference in the schema.



Now go to your BPEL process and assign following to the end point reference variable
<EndpointReference xmlns=”http://schemas.xmlsoap.org/ws/2003/03/addressing”>
<Address/>
<ServiceName/>
</EndpointReference>



Create one more variable EndPointUrl to store the end points of the services. The end point we will derive dynamically based on the input condition. Map this end point URL to the Address field in the EndPointReference.



Finally assign the end point reference variable to the partner link




Complete the process by invoking the partnerlink and assigning the input and output parameter. After completing all these steps your process will look like this.





Retrieve the end point url dynamically based on input parameter.
To achieve this put a switch activity just after the receive activity and define 3 conditions. This condition can be based on the real business logic. However for implementation to make easy lets define a simple condition
i.e. if input payload is less than 5 redirect it to Service A
If input payload is between 10 and 5 redirect it to ServiceB and
If input payload is greater than 10 redirect it to ServiceC
Once you defined the three conditions assign the end point url to the corresponding service to the variable “EndPointUrl”









Complete the assignment for all the three conditions and deploy your project to the server.

Test the Dynamic Partnerlink service.
To test the invocation of Service A pass an input value less than 5 so let’s pass 4 as input and test the result
Log in to em console.
Click on your process and click on test button




Specify input as 4





And test the service
Check the response




And check the Audit trail



No comments: