Monday, 1 December 2014

Using Proxy Server with OSB

I have used http://hilite.me/ website to do the java-html conversion.
We will see how to implement a Restful Gateway on the OSB which will accept restful requests and then routes these requests to the real implementation of the service that can also be a Restful service. This additional layer created can be used for auditing,security....

We will use an external public service called BrewaryDB which offers a Restful API ( http://www.brewerydb.com/developers/docs)  to execute queries for breweries,beers... To use the BrewaryDB service Api an API key is needed. You can register for a new key here (http://www.brewerydb.com/developers/apps) or reuse the same key provided in this article.

Steps

1) Create a new OSB configuration project or you may reuse existing one.

2) Right-click the OSB configuration project and create new proxy-server and name it VMProxy Make sure the proxy settings are correctly entered and save it. 

3)  Create a new OSB project and name it "creating-generic-restful-gateway" .

4) Create business and proxy folders.

5) Create a new business service under business folder and name it as "BreweryService"

6)  Double-click the business service and select "messaging service" in the General Tab.

7) In the Messaging tab select XML for both request and response Message Types.

8) Navigate to the transport tab and add below endpoint

https://api.brewerydb.com/v2/

9) Navigate to the "HTTP Transport" tab and select the proxy server created earlier in the Advanced Settings.

10) Save all the changes.
11) Right-click the business service and select "Generate Proxy Service" and label it as BreweryService and place it under proxy folder.
12) Navigate to the Transport tab and enter /BreweryService into the EndpointURI field.
13) Navigate to the Message Flow tab and check that a Route node with a Routing action, which invokes the business service, has been generated.
14) Insert an Insert action into the Request Action flow of the Routing action.
15) On the Properties of the Insert action, enter outbound into the In Variable field.
16) Click <Expression>, enter <http:http-method>{$inbound/ctx:transport/ctx:request/http:http-method}</http:http-method> into the Expression field and click OK.
17) Click <XPath>, enter ./ctx:transport/ctx:request into the Expression field and click OK.
18) Leave the Location on as first child of.
19) Duplicate the Insert action by copying and pasting it into the Request Action.
20) On the Properties of the second Insert action, click on the link to the right of Expression, enter <http:query-string>{$inbound/ctx:transport/ctx:request/http:query-string}</http:query-string> into the Expression field and click OK.
21) Duplicate the Insert action by copying and pasting it into the Request Action.
22) On the Properties of the third Insert action, click on the link to the right of Expression, enter <http:relative-URI>{$inbound/ctx:transport/ctx:request/http:relative-URI}</http:relative-URI> into the Expression field and click OK.
23) Insert a Log action into the Response Action flow of the Routing action.
24) On the Properties tab of the Log action, click <Expresssion>, enter $body and click OK.
25) Select Warning for the Severity drop-down listbox.
26) Save all and deploy the project in the OSB server.
27) Open the browser and hit below URL and couple of beer details should be listed down.

http://localhost:7001/BreweryService/brewery/8z0ZCd/beers?key=<<key-name>>&format=xml

Sources:

Oracle Service Bus 11g Development Cookbook By Guido Schmutz , Edwin Biemond ,Eric Elzinga ,Mischa Kölliker ,Jan van Zoggel
https://blogs.oracle.com/knutvatsendvik/entry/using_proxy_server_with_osb
https://www.youtube.com/watch?v=TvIqpBjSsE4
http://www.brewerydb.com/developers/apps

1 comment:

Unknown said...

Your have provided a great information about java programmer,programmers
. That are very informative for me. Thanks A Lot