1. Create a Service bus project with the name 'JavaCallout'.
Click on Finish.
2. Now create a proxy service.
Check the checkbox 'Generate Pipeline'. Click on Next.
Select Service Type as 'Any XML' and click Next and then Finish.
3. Double click on the pipeline. Drag and drop a pipeline pair.
Now, drag and drop a Java Callout activity in the request pipeline.
Select the jar file in the Method value. In my case, I'm selecting a jar file which contains the java class to add two numbers. The code of the Java class is as below for your reference:
Now, give the Expression for the int variables under Arguments. As I used the type of both variables as int, it is showing me as int in Arguments section.
Give the values as below:
For the first int variable: xs:int($body/*:result/*:Num1)
For the second int variable: xs:int($body/*:result/*:Num2)
Return variable: Result
4. Now, drag and drop a Replace activity in the response pipeline.
Select the values as below:
Location: body
XPath value: . ('.' represents the current node)
Value: $Result
Replace option: Replace node contents
Here, $Result is the variable that we assigned output to in Java Callout.
6. We've done with all the steps. Now, deploy the project into OSB server and click on the Proxy service or pipeline to test the service. Give the input in XML as below:
<result>
<Num1>18</Num1>
<Num2>45</Num2>
</result>
Of course, you can give any numbers that you want. Cheers!!
No comments:
Post a Comment