Thursday, November 7, 2013

Retrieving URL Parameters through OSB

Hello Folks !!

   Many of the times we come across wherein the source system passes some username / password or some id in URL and expects a response corresponding to those parameters . That is nothing but a GET method which invokes a REST based Proxy Service . I am here to explain you step by step on how to obtain the URL Parameters with the help of OSB . I am using Eclipse as a tool to perform this , but , you can do the same steps directly on console as well .

Just Follow below simple steps :


  • Create a Fresh Project and make a Dummy Proxy Service. In my case , the Project name is DemoParameter and the Proxy Name is ObtainParameterPS.proxy.
  • Next i am making my proxy service as Any XML Based (REST Based) as this service will do nothing but will fetch me the Parameter values which i gave in URL .


  • Next go to the Transport Tab and modify the end point URI which will be used by source system in order to call this proxy service . I am keeping the URI as "/DemoParameter" .

  • Next go to the Message Flow tab and add a Pipeline pair and Stage Activities .





  • Put a Assign Action in the Request Stage, and open the Expression Builder . On Right Hand Side , under Variables section , expand variable inbound->transport->request-http->query-parameters as shown down in figure .


  • After that, drag and drop the 'value' option (selected in above figure) to the left and then add [@name='id'] to make the syntax as : $inbound/ctx:transport/ctx:request/http:query-parameters/http:parameter[@name="id"]/@value

  • Assign this value to a variable which in my case is queryParameterValue.

  • Next , in Response Stage , add a replace activity and the add the values as shown below . Note that i am replacing the body with the expression : <Output>{$queryParameterValue}</Output>

  • The code is complete and now we are ready to test this . So export the jar file from Eclipse and import that to sbconsole. After that go to the Project Explorer and select the project DemoParameter. Next click on the little bug icon symbol on right to proxy service to test it as shown in figure.



  • When Test Console is launched , we need not give anything in Payload Section . Just expand the Transport Section . By default, the query-parameter field will have the tags already defined. You just need to add a tag for each parameter you want to pass into the service . Like i have passed for id as follows: 
                  <tp:query-parameters xmlns:tp="http://www.bea.com/wli/sb/transports/http">
            <tp:parameter name="id" value="1234" />
           </tp:query-parameters>


  • Click on execute button and note the output in the Response document as shown below.

  • You can also test the service by directly putting the URL in the browser as : http://<HostName>:<PortNumber>/<endpointURIOfProxy>?id=123. Below in browser i have written in browser :
 http://dvc88600:27669/DemoParameter?name=AshishHarjani&id=123 .



  • After the special symbol '?' in browser , it will search for the parameter id and will fetch it's value.
          This is all about Retrieving the URL Parameters through OSB . Just try and Enjoy.. :) . Thanks .

7 comments:

  1. Good Explanation.. looking forward for more posts.

    ReplyDelete
  2. That was very helpful , Thanks!

    ReplyDelete
  3. Thanks Ashish for the useful blog :)

    ReplyDelete
  4. hi ashish,

    i need to get binding and port type information of input request of proxt service so that i can call appropriate proxy service in order ti continue processing the request.

    could you please help me get the transport protocol information in osb.
    i tried to capture inbound request parameters at transport level but didn't find any relevant information.
    My main aim is to find the binding/port type of incoming request and route it to appropriate BS/PS

    Thanks in advance.

    ReplyDelete
  5. Thanks ...it was really helpful..!!

    ReplyDelete