Showing posts with label Web Services. Show all posts
Showing posts with label Web Services. Show all posts

Consuming Web Service in TibcoBW Process

In this article, I will brief on how to consume web services in TibcoBW. In the project view, lets add resource to consume WSDL as shown below, make sure to explicitly add the service schema to the project and re-map the Input and Output messages in the port type which is as part of WSDL.
Right Click on the project Folder, Choose WSDL and then WSDL. In the WSDL, provide the service url and click Copu From URL.
We would build a Tibco BW using file poller, to receive a booking request and then call process is used to invoke the actually booking service as shown below.
In child process, that would call booking service. Both Start and End Activity is mapped to BookRequest Schema and Booking Service Response Schema respectively as shown below,
using SOAPRequestReply Activity, we would invoke the service and its configuration and service request transformation is shown. Here cab booking service is invoked.
Lets test the project. Load both Main and Child Process.
As we see, booking request got process and original request is passed on to the child process and in the child process, after service transformation, service is invoked and the response in render to the main process.

Now, lets develop another process to invoke hotel booking service using child process and main process would dynamically invoke either cab or hotel booking child process. As both the service responses vary, lets generalize the output of each process as shown below.
Below screen shot, shows the service response mapping to generalized schema for both cab and hotel booking.
Test the project by placing a Cab and Hotel booking requests. Alternate approach to dynamic call process is shown below, here both cab and hotel booking flow are defined using filter conditions as shown below.
Run and test project. Screen shot shown the flow path for cab and hotel requests.
The video demonstration is available on the Youtube, here is the embedded video.

Scatter Gather Router for Parallel Tasks in Mule


In this walk through, I would build a mule flow which would receive a booking request and mule flow would to invoke Cab Booking web service and archive the message to database and finally fetch available cars from DB using scatter gather pattern.

As usual we will configure configure HTTP Connector with listener configuration as shown, 
Lets bring in as web service consumer connector and add a new connector configuration as shown and choose the relevant operation from the dropdown.
Web service expects specify format as its request, to achieve it bring a transform message and set the payload at the source and apply the logic as shown
Lets run the project and post the Booking Request message, the web service response is echoed back
Add new transform message and apply the mapping logic after the service call
Retest the mule application.
Now lets try to archive the message we receive to a Database table, extract the cab booking flow into a subflow and then drag and drop the scatter-gather router and move cab booking flow reference into it
Bring in database connector into the scatter-gather router and configure the connector properties as shown.
Run the project and post a booking request. Muleflow would throw a exception as shown below, to over come add object to byte array transform so this allow the message to be shared by parallel process.
Re-run the application, this would process the message but still an exception is thrown. This is because multiple message/payload isn't handled properly.
Bring in a transform message after the logger and access payload with indices as shown would resolve the issue 
Test the application by posting a booking request. Successful response is received.
Lets add another Database connector to the scatter-gather router and perform a simple select from cars table and tranform to an XML format as shown. In the finally transformation, add logic to map the cars data to the final response.

Re-test the application.
Built a new mule flow for Hotel booking as shown below, its mock kind of flow where a request is received and mock success response is rendered to client using payload and property activities. Similarly develop another flow for Flight booking. These are mock services, that would be invoked using scatter gather.
Here is the main flow that uses scatter gather router to call Hotel and Flight Booking using HTTP Connectors. If you noticed the main different between earlier and the current one, payload isn't passed to child flows and hence payload conversion from object to byte array is not used.
 Run the project and test the application

Consuming RESTful web service in Mulesoft | Tiny-URL Mule


In this walk through, I would build a mule flow which would receive and payload containing website url address and mule flow would to invoke a restapi and render a tinyurl for the posted url in payload. Based on the content-type we will have a routing logic using choice router.


Drag out an HTTP connector and drop it in the canvas. In the HTTP properties view, set the connector configuration to the as shown HTTP_Listener_Configuration and Set the path and allowed methods as /shorturl and POST repesctively.
Drag and configure a json to object transformer with java.util.HashMap in the class property. Drag out another HTTP connector and drop it into the process section of the flow. In the Global Elements view of HTTP Connector, click Create and in the Choose Global Type dialog box, select Connector Configuration > HTTP Request Configuration and click OK. Then in  the Global Element Properties dialog box, set the following values and click OK. In the HTTP Request properties view, set the path, method and add query params as shown
Lets run the project and post a message to mule application. Application is working as expected. 
Lets refactor the application using subflows and variable to make this more generic.
Instead of passing payload directly in the http query params we would use a flow variable as shown, bring a flow variable and set the value and use the flowvar in query param.
Select both JSON To Object and longUrl then right click, Extract To >> Sub flow, provide appropriate name for the subflow.
In order to support requests with xml and text payload, we will bring in a choice router and move the reusable-conversion code into choice router, then bring in another XML to JSON transformer inside choice router and text payload will be configured as default flow.
For XML flow, we will convert xml to json and then call the reusable conversion code using flow reference. For default flow, we will set the flowvar as shown

Choice Router is configured based on Content-Type as shown below, in the Choice properties view, double-click the route. In the Route Properties dialog box, set the expression to true if the Content-Type is equal application/json and click OK. Repeat same for other flows.
Run and test the project,
Test outputs for different payloads shown below
Play around the http parameters [query and uri params]