Dynamically binding to a JSON service in OSB

It's common for JSON services to use RESTful interface design principles; as such, the URI and HTTP method will often combine to indicate what is to be done.

This differs from the common document-literal SOAP/HTTP pattern, where the HTTP method will always be POST, the URI will be constant for all operations exposed by a service, and the operation will be selected by the outer-most element inside the SOAP body or the SOAPAction header.

This difference means that we'll often need to do some extra preparation before calling out to a JSON service, so that the HTTP method and the URI are correctly configured.

Getting ready

We'll be building on the previous recipes, so we'll assume that you already have an OSB project in OEPE, with an HTTP business service, and a proxy service that invokes it using a Service Callout.

How to do it…

  1. The HTTP business service will have been configured to use a particular HTTP method. In the event that a different method is required, the proxy service can override the method by adding an element to the outbound variable.
  2. Add an Insert activity to the Request Action path of the Service Callout and configure the Properties of the Insert activity described as follows:

    i. First, click on <Expression> to open the XQuery/XSLT Expression Editor and enter the following:

    <http:http-method>PUT</http:http-method>

    Note

    Here, we are specifying PUT as the HTTP method, but it could be GET, POST, or DELETE as appropriate.

    ii. Next, ensure the Location attribute is set to as first child off.

    iii. Click on <XPath> to open the XPath Expression Editor. Within the variable structure browse to outbound | $outbound | transport | request | request – http and drag it on to the Expression, as shown in the following screenshot:

    How to do it…

    iv. Click on OK.

    v. Next, set In Variable to outbound.

    How to do it…
  3. The business service will have been configured with a base URI to use for outgoing calls. If a suffix is required (to identify a specific resource, for example), the relative-URI element may be added to the outbound variable to provide this information to the business service.

    To append /1 to the end of the URI, drag an Insert activity to the Request Action path of the Service Callout. Configure the Properties of the Insert activity (as in step 2) to have the values listed in the following table:

    Field

    Value

    Expression

    <http:relative-URI>/1</http: relative-URI >

    Location

    as first child of

    XPath

    ./ctx:transport/ctx:request

    In Variable

    outbound

    If the Endpoint URI configured for the business service is http://example.org:8091/CreditCardService/CreditCardJSON_1.0, the outgoing call will now be made to the following URL:

    http://example.org:8091/CreditCardService/CreditCardJSON_1.0/1.

    It is, of course, much more likely that you will dynamically construct the relative-URI value based on the received request.

How it works…

The ./ctx:transport/ctx:request element of the outbound variable is used to supply transport-specific metadata to the business service, to influence how it makes the outgoing service invocation.

There's more...

In some cases it will be necessary to completely override the business service's endpoint URI.

Assuming that the URI to use has been assigned to a variable requestURI earlier in the proxy service message flow, the endpoint URI override is performed as follows:

  1. Insert a Routing Options activity to the Request Action path of the Service Callout. Configure the Properties of the Routing Options activity as described next.
  2. First, ensure URI is selected, and then click on <Expression> to open the XQuery/XSLT Expression Editor and enter the text $requestURI.
    There's more...

    Note

    If we were using a Route, rather than a Service Callout, and we wanted to select one of a number of business services bound to different endpoint URIs, a Dynamic Route activity would be the one to use.

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

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