Saturday, December 20, 2014

Helloworld in OSB

'Helloworld' example is very confusing in OSB specially for SOA developers, so lets do it.

For creating this Helloworld web service in OSB we will need XSD and concrete WSDL, we can can get these from JDeveloper.

Step 1.) From JDeveloper I created a simple schema file as below


Step 2.) In JDeveloper create a synchronous BPEL process with input and output using this schema file, deploy this BPEL to server and get the concrete WSDL file from server.






Download this wsdl file, and we are ready to start the development in OSB.

Now lets go to Eclipse OSB IDE.

Step 3.) Create OSB configuration project as shown below



Now create a new OSB project





Now create different folders as below and copy the schema and WSDL files in the respective folders, also remember to change the xsd file location in wsdl file.



Step 4.) To create a Helloworld in BPEL we would have a exposed web service adapter and a BPEL process, however there is no adapter on external reference, so in OSB we wont have any business service, See the screen shot below, this is the first confusion of any SOA developer, better understand this here.




Step 5.) Create a proxy service 'Helloworld_PS' and use the concrete WSDL which we have downloaded from SOA server.




Select WSDL and web service, browse for wsdl file and select port and press OK.




Select Yes for transport configuration changes.


This gives us a synchronous OSB web service, more like a sync BPEL process without any activity.

Step 6.) Now all we have to do is use a assign activity which will concat Hello !! with our input and pass us as output, so simple isn't it ? this is the next confusion and quit a confusion honestly.

Click on flow tab and go to the flow.



From the design pallet > Oracle Service Bus design flow > Nodes > Pipeline Pair drag and drop it after Helloworld_PS.

Pipeline pair separates the input and output flow and makes it easier to customize transformations and other operations on either the request or response side of the node. Right now we only have a entry node and if we test it, it will echo with the input.

In the response pipeline drag and drop a stage and inside it drag and drop a replace activity.

The replace activity helps us to replace contents inside any variable or particular element inside the variable.


In Variable is the target variable
XPath is the precise node of the target variable where we want the replace to happen
Expression is the content you want to be copied (source XML)

Now deploy and test this to be confused again.



The response is what we passed in the request, now why is this happening, OSB is slightly different in behavior from BPEL, in OSB the output variable inside the body is not created if we define it inside the WSDL file, like it happens in BPEL where if we don't pass anything to the output of BPEL still we will get the empty output XML.

This is not working because the OSB is unable to find anything inside body which can be picked by this XPath "./v1:HelloworldRes/v1:response", in BPEL terms selection failure, however OSB does not gives this error and we remain in confusion why is the service echoing.

Typically we use a XSLT where we will create a final output XML which we want to receive from OSB and use a replace activity and copy it to the body.

For this example I am hard coding a output XML



Deploy and test


We can see whatever the XML we hard coded in the expression the same has got replaced in the body and coming up in the response.

No comments:

Post a Comment