Primer: Calling Multiple REST Services

podborka-14062013-20

This is the shortest guide for making an OSB parallel call to REST services with GenericParallel.

I assume the GenericParallel service is already deployed on your domain. (If not, here’s the deployment guide.)

Suppose we need to call a RESTful service named RegisterResourceId. We’ll need to register a number of ids at once, hence the parallel call.

To register one id, we need to call this service with the following parameters:

Base URL http://datagrid/restful
Relative URI register-resource-id
HTTP Method PUT
Payload Resource ID itself

The base URL is configured on a business service, let’s call it Datagrid/Biz/Restful.

Now we need to call this business service, passing correct relativeURI and HTTP method, and do it in parallel.

GenericParallel will do all of it for you, you just need to:

  1. Create a GenericParallel wrapper request.
  2. Add a list of REST requests to the wrapper.
  3. Pass that wrapper request to GenericParallel/GenericParallel local proxy.
  4. Read the responses from the GenericParallel wrapper response.

For example, let’s register two resource ids:

<typ:GPS xmlns:typ="http://genericparallel/types">
  <typ:Requests>

   <typ:Request GPSTarget="Datagrid/Biz/Restful" 
      GPSTargetType="BusinessService" GPSMethod="PUT" GPSRelativeURI="register-resource-id">
      ad41115e-9e26-11e5-8994-feff819cdc9f
   </typ:Request> 

   <typ:Request GPSTarget="Datagrid/Biz/Restful" 
      GPSTargetType="BusinessService" GPSMethod="PUT" GPSRelativeURI="register-resource-id">
      927e4e10-a21b-11e5-bf7f-feff819cdc9f
   </typ:Request> 
  
  </typ:Requests> 
</typ:GPS>

Now pass this request to GenericParallel/GenericParallel proxy.

GenericParallel will take every Request entry and execute them in parallel by calling the business service at path Datagrid/Biz/Restful, setting relativeURI to register-resource-id, HTTP method to PUT and body to anything that is under Request – UUID in this case.

Then it will collect the responses and return them back as a list in the same order as they were sent out:

<types:GPSResponse xmlns:types="http://genericparallel/types">
  <types:Responses>

    <types:Response GPSIndex="1" GPSBatchIndex="1">
      <soap-env:Envelope>
        <soap-env:Body>+OK Registered</soap-env:Body>
      </soap-env:Envelope>
    </types:Response>

    <types:Response GPSIndex="2" GPSBatchIndex="1">
      <soap-env:Envelope>
        <soap-env:Body>+OK Registered</soap-env:Body>
      </soap-env:Envelope>
    </types:Response>

  </types:Responses>
</types:GPSResponse>

Note: the responses are always wrapped into soap-env:Body.

If you want to learn more, feel free to try GenericParallel.

Vladimir Dyuzhev, author of GenericParallel

About Me

My name is Vladimir Dyuzhev, and I’m the author of GenericParallel, an OSB proxy service for making parallel calls effortlessly.

I’m building SOA enterprise systems for clients large and small for almost 20 years. Most of that time I’m working with BEA (later Oracle) Weblogic platform, including OSB and other SOA systems.

Feel free to contact me if you have a SOA project to design and implement. See my profile on LinkedIn.

I live in Toronto, Ontario, Canada.  canada   Email me at info@genericparallel.com


12 comments on “Primer: Calling Multiple REST Services
  1. Ashwaq says:

    Hi Vladimir Dyuzhev,

    I tried to construct wrapper requests as like below

    … Getting the below exception….

    OSB-382000: Validation of ServiceMetadataDerivedType GenericParallelSelfTest/REST/RestBackendService.ProxyService failed: ServiceMetadataDerivedType GenericParallelSelfTest/REST/RestBackendService.ProxyService does not exist

    Could you please help on it.

    Thanks,
    Ashwaq

    • Vlad Dyuzhev says:

      WP ate the request. Can you email me directly?

      • Rashi Saluja says:

        Any solution to above mentioned problem? I am getting similar error.

        • Vlad Dyuzhev says:

          GenericParallelSelfTest/REST/RestBackendService.ProxyService is a self-test service which is not required for normal operations. It is only needed if you want to run GenericParallel SoapUI tests. If it is the case, then you need to deploy SelfTest JAR project from the distribution.

          You do not need that project if you just want to use GenericParallel.

  2. Suraj says:

    Hi Vlad,

    JSON response getting populated from backend, but unmarshalling from xml is failing … so json is displayed in err:text of soap:fault.. pfb…

    REQUEST:

    RESPONSE:

    soapenv:Server

    GPSFailMode is ANY_REQUEST_FAILS and one request has failed

    soapenv:Server

    OSB-382030: Failure while un-marshalling message: Failed to parse XML text

    OSB-382030

    Failure while un-marshalling message: Failed to parse XML text

    {“firstname”:”Firstname 0″,”id”:0,”hiredate”:”2015-12-10T16:34:08.169-05:00″,”lastname”:”Last 0″}

    One Request Pipeline Pair

    One Request Pipeline Pair_response

    Build Response

    response-pipeline

    Thank You in Advance,
    Suraj

  3. Ashwaq says:

    Hi Vlad,

    Thank you very much for rolling up new version with fix.

    Now GenericParallel works well for 12.2.1.0 verion of OSB.

    Regards,
    Ashwaq

  4. Hi Vladimir Dyuzhev,

    Thanks for the service.

    I am facing some issue while enqueueing to multiple AQs. The GPSFailMode is ANY_REQUEST_FAILS. The scenario is, when i am trying to enqueue to 5 AQs, and if it fails on any one of the queue, the other queues are getting the messages successfully. The transaction is not getting rolled back.

    Could you please help on it.

    Thanks,
    Vignesh

    • Vlad Dyuzhev says:

      Hey, Vignesh.

      My understanding you want to place messages into 5 queues, and if any of them fail, you plan to rollback the transaction so none of the messages go out?

      OK, I did not plan for such a use. GenericParallel code is using BestEffort inside of the split-join, so even if you have a transaction in progress, GPS is outside of it.

      I see two solutions for you:

      1. Do not use a parallel call. Placing into a queue is usually a very fast operation, so you can do all 5 sequentially without a performance impact. Do it within a OSB proxy with transaction, and you’ll have either 5 or 0 messages sent.
      2. Update GPS code to use Exactly Once in Invoke Service steps. I did not test that, but, according to Oracle documentation, that is enough to propagate the transaction via Split-Join… hmm… you’d have to make other GPS proxies transactional, too.

      Let me know if that helps.

      • Hi Vladimir,

        I changed the QoS of Invoke Service in flow to Exactly Once and also in Assign/Replace/Insert activities.
        Still it didnt work.

        If parallel publish is not working, then i should try Sequential with normal proxy service.

        Is there any other way we should try ?

        • Vlad Dyuzhev says:

          I do not have time presently to test GPS with transactions, so I cannot comment on what could be wrong.

          At this point, I believe, you should try a single transactional proxy with sequential calls to 5 Publish which in turn have Exactly Once. JMS connection factory should support transactions.

Leave a Reply

Your email address will not be published. Required fields are marked *

*