Often we may want to call the target endpoints dynamically. In such cases WS Addressing comes for our help.
In BPEL 1.1 we can assign the following snippet to the partner link and it will try to hit the endpoint mentioned in the snippet.
<wsa:EndpointReference xmlns:wsa="http://schemas.xmlsoap.org/ws/2003/03/addressing">
<wsa:Address>http://localhost:8001/soa-infra/services/default/TargetService</wsa:Address>
</wsa:EndpointReference>
But in BPEL 2.0 the above approach was not working for me.
I have achieved the dynamic partner link requirement achieved in BPEL 2.0 as follows
Download the
ws-bpel_serviceref.xsd and add it to your project
Create a variable of element type service-ref , which is defined in the above xsd
<variable name="partnerlink-reference" element="sref:service-ref"/>
For the example purpose I am storing my target endpoint in a variable. (You may use DVM or AIAServiceConfigurationProperty file to store your target endpoint at real time.)
<copy>
<from>'http://localhost:8001/soa-infra/services/default/TargetService'</from>
<to>$TargetService</to>
</copy>
Using append xml fragment option the following xml snippet to the above variable partnerlink-reference
<wsa:EndpointReference xmlns:wsa="http://schemas.xmlsoap.org/ws/2003/03/addressing">
<wsa:Address/>
</wsa:EndpointReference>
Now enrich the partnerlink-reference xml with the actual endpoint you need
<copy>
<from>$TargetService</from>
<to>$partnerlink-reference/wsa:EndpointReference/wsa:Address</to>
</copy>
Finally copy partnerlink-reference variable to the target partner link
<copy>
<from>$partnerlink-reference</from>
<to partnerLink="TargetServicePartnerLink"/>
</copy>
The entire Assign activity will look like as follows
<assign name="Assign1">
<copy>
<from>'http://localhost:8001/soa-infra/services/default/TargetService'</from>
<to>$TargetService</to>
</copy>
<extensionAssignOperation>
<bpelx:append>
<bpelx:from><bpelx:literal><wsa:EndpointReference xmlns:wsa="http://schemas.xmlsoap.org/ws/2003/03/addressing">
<wsa:Address/>
</wsa:EndpointReference></bpelx:literal></bpelx:from>
<bpelx:to>$partnerlink-reference</bpelx:to>
</bpelx:append>
</extensionAssignOperation>
<copy>
<from>$TargetService</from>
<to>$partnerlink-reference/wsa:EndpointReference/wsa:Address</to>
</copy>
<copy>
<from>$partnerlink-reference</from>
<to partnerLink="TargetServicePartnerLink"/>
</copy>
</assign>
Save and deploy your project. Test your flow, you can see your partnerlink's target address is changed to the one you updated from your BPELprocess