官术网_书友最值得收藏!

  • BPEL and Java Cookbook
  • Jurij Laznik
  • 649字
  • 2021-08-06 16:58:19

The dynamic selection of the web service's endpoint

In this recipe, we will explore how to dynamically call web services from the BPEL process. Such an approach can be useful in an early stage of the SOA adoption or when we don't have the middleware infrastructure set up yet and we have, for example, a set of redundant web services. In such a scenario, we need to provide ourselves with the functionality for the BPEL process to dynamically select the web service's endpoint.

Getting ready

We start this recipe by deploying the same web service to multiple instances of the servers. We decided to use the hotel reservation service from the Implementing web services with Axis2 recipe. We deployed the web service to the three instances of the server. The interface of web service remains the same; however, the address on which the web services reside do change as follows:

Server 1: <soap:address location = "http://192.168.1.101:7777/axis2/services/BookHotelService/"/>
Server 2: <soap:address location = "http://192.168.1.101:8888/axis2/services/BookHotelService/"/>
Server 3: <soap:address location = "http://192.168.1.101:9999/axis2/services/BookHotelService/"/>

How to do it…

In the following steps, we will describe the actions to be performed in order to configure the BPEL process to dynamically select the web services endpoint:

  1. First we create the BPEL process. The BPEL process can either be synchronous or asynchronous. As an input parameter we take two dates, presenting the from and to reservation dates as follows:
    <element name = "process">
      <complexType>
        <sequence>
          <element minOccurs = "0" name = "from" nillable = "true" type = "dateTime"/>
          <element minOccurs = "0" name = "to" nillable = "true" type = "dateTime"/>
        </sequence>
      </complexType>
    </element>

    We introduce the decision element. The criteria we took is the year of the from parameter as shown in the following figure:

  2. Based on the decision criteria, we set the endpoint parameters for the web service. We created the EndpointReference variable and initialize it with the following literal:
        <copy>
          <from><EndpointReference xmlns = "http://schemas.xmlsoap.org/ws/2003/03/addressing">
      <Address/>
    </EndpointReference></from>
          <to variable = "EndpointReference"/>
        </copy>
  3. Based on the decision criteria, we set the web service endpoint address as follows:
          <bpelx:append>
            <bpelx:from variable = "address"/>
            <bpelx:to variable = "EndpointReference" query = "/ns2:EndpointReference/ns2:Address"/>
          </bpelx:append>
  4. Finally, we copy the endpoint reference variable to the partnerLink element as follows:
          <copy>
            <from variable = "EndpointReference"/>
            <to partnerLink = "BookHotelSvc"/>
          </copy>
        </assign>
  5. We model the BPEL process so that the parameters are set to the web service variable, the web service is invoked, and after the web service invocation the results are picked up as shown in the following screenshot:

How it works…

One of the advantages of the BPEL processes is that it is possible to invoke a web service with the dynamic partner links. If we have redundant web services, it is the easiest way of using the dynamic partner links. That way we simply change the address of the web service endpoint, and we can immediately consume the web service.

Note

The dynamic partner links, as shown in this recipe, are supported only for the BPEL 1.1 specification BPEL processes.

The dynamic partner links take advantage of the WSA mechanism. In WSA, the various data about the web service endpoint can be found. The only two parameters that can be changed are as follows:

  • <wsa:Adress>: This defines the location of the web service endpoint
  • <wsa:ServiceName>: This defines the name of the service and the port used
    Note

    The recipe will work only in the web service, which will use the dynamic partner links that will have the same web service interface (messages, portType, and binding).

There's more…

It is also possible to extend our BPEL process to include the partner links of all three web services. Then, we model the BPEL process same way as we have in this recipe. The only difference is in the assign activity, where we now set the endpoint address data. Instead of dynamically assigning data to the invoke activity, we could use three separate invoke activities and set one partner link to each of them.

Actually , the dynamic selection of the web service is highly dependent on the infrastructure we have at our disposal. This recipe explained the dynamic selection of web services with no external help of other technologies. We could, however, use the service registry for web service discovery along with late binding through a mediator.

See also

  • For the web service implementation and deployment, see the Implementing web services with Axis2 recipe
主站蜘蛛池模板: 屏边| 靖江市| 新疆| 苍山县| 德化县| 拉孜县| 西城区| 上饶市| 吉林市| 英山县| 炉霍县| 沙湾县| 平山县| 南皮县| 绥滨县| 通州区| 天水市| 桃园县| 思南县| 长沙市| 日照市| 南京市| 孝义市| 洪江市| 上高县| 松江区| 丰镇市| 离岛区| 洱源县| 增城市| 昌江| 合川市| 肇源县| 天全县| 甘南县| 儋州市| 囊谦县| 台前县| 金塔县| 徐州市| 汤阴县|