Sometimes Oracle Service Bus is not sufficient to meet our requirements. To do so OSB provides Java Callout activity that is used to call java code from OSB.
Restrictions to use Java Callout activity:
• Java code must be packaged as jar
• The java method that will be called from OSB, must be static.
Implementation:
Create an Custom application
Create a simple java class:Application⇾Project⇾Java class
Jar file is created and Copy the jar file in the OSB project
Create a OSB project to use the created Jar file
Create a Proxy WSDL using the created XSD.
Move the jar file in JAR folder under resources folder
Create a Proxy service using that created WSDL
Proxy and pipeline created
Drag the Java Callout activity in the pipeline and configure the properties
Select the class from jar
Give a variable name for storing the response will be received from the java callout.
Go the expression and select the inputs
Export the OSB project and deploy to the service bus server,
Testing: from pipeline
You can see the response in concatenation of the hello and names under invocation trace
Restrictions to use Java Callout activity:
• Java code must be packaged as jar
• The java method that will be called from OSB, must be static.
Implementation:
Create an Custom application
Create a simple java class:Application⇾Project⇾Java class
Create jar that will contain the .class file.
Jar file is created and Copy the jar file in the OSB project
Create a OSB project to use the created Jar file
Create folder structures like, proxyServices, businessServices, resources etc
Create a XSDCreate a Proxy WSDL using the created XSD.
Move the jar file in JAR folder under resources folder
Create a Proxy service using that created WSDL
Proxy and pipeline created
Drag the Java Callout activity in the pipeline and configure the properties
Give a variable name for storing the response will be received from the java callout.
Go the expression and select the inputs
Method: Browser the jar and select the method that you want to call and click OK
Arguments: Set the value of arguments
Return: Assign the variable in which you want to get the output of the method
Drag the log activity and print the variable.
Export the OSB project and deploy to the service bus server,
Testing: from pipeline
You can see the response in concatenation of the hello and names under invocation trace
You can observe following issue during the development.
Issue details:
<May 30, 2017 7:17:49 AM MDT> <Error>
<oracle.osb.stages.transform.transformloggables> <OSB-382516>
<Failed to evaluate expression for callout to java method "public
static java.lang.String
helloproject.HelloWorld.hello(java.lang.String,java.lang.String)".
Argument index: 1, exception: Value of type 'org.apache.xmlbeans.impl.values.XmlAnyTypeImpl'
cannot be type-cast to 'java.lang.String'>
Solution:
The error is occurring because it can't pass XmlAnyType TO your static java method. You aren't specifying what you pass to the Java method, so I can only assume you aren't casting it properly to the right type. It gets an XmlAnyTypeImpl which needs to be converted to something else (String, int, boolean, etc.). You can probably just tweak what you're passing to the Java callout using some form of the XS Constructors: