Tuesday, 18 December 2012

How to use java callout in osb


Key Concepts:


·         POJOs are used for the java Callout

·         No Special libraries or compilation is required

·         Java method must be static(technically public and static ) in order to be call by OSB

·         Java code must be packaged in a JAR file

·         The same Java Callout JAR can be called from multiple proxy services

Using Java Primitives:


There are few following steps

1.      Create simple java project ex: Java callout project and inside project create package ex: com.oracle.osb.project . Inside project create a class file SimpleCallout.java.

2.      Inside class file create two methods

Ø  One takes a string argument and return hello and whatever given string argument. its typically  Hello worlds type of scenario .

Ø  And next one takes two arguments and multiply both the arguments and returns product the two arguments.
3.      Java Code :
package com.oracle.osb.project;
public class SimpleCallout {
 public static String getGreeting(String name)
 {
  return "hello" + name;
 }
 public static int multiply(int a,int b)
 {
  return a*b;
 
 }
}
4.      Basically Compile this. Right click on Java callout project -> Build Path->Add external archives.
5.      In order to access oracle Service Bus project change Recourse to oracle Service Bus.
6.      Create OSB configuration project and inside configuration project create OSB project.
7.      Now create 3 folders
Ø  WSDLs
Ø  Proxy services
Ø  JAR
8.      Inside WSDLs folder create wsdl file that defines the element.
Ø  Define two elements getGreeting and Multiplication.
Ø  getGreeting takes string argument and returns string back
Ø  Multiplication takes two different integer argument and return single integer result argument.
Ø  Wsdl file look like
 
9.      Now copy the Java callout.jar to JAR folder.
10.       Create proxy service inside proxy services folder.
Ø  Select general view and select WSDL Web Services.
Ø  Browse WSDL particular WSDL file and port.
Ø  Now go to Message fellow Create Operational branch one for Greeting and another for Multiplication
Ø  Select getGreeting Branch and drag and drop Pipeline pair.
Ø  Create stage in Request pipeline and inside stage create Java callout.
Ø  And go to Java callout properties tabs. Browse to the jar file. ex: javacallout.jar and specific operation in case is greeting.
Ø  Now pass the arguments. Click on expression and pass getGreeting argument. Ex: $body/proxy:getGreeting/in/text()
Ø  Result come back . and map that into greeting. Result value is greeting.
Ø  In Response pipeline Create stage. And inside stage create Assign and replace operation .
Ø  Select Assign operation. Click on Expression and write particular expression, Ex: <proxy:getGreetingResponse>
<out>{$greeting}</out>
</ proxy:getGreetingResponse>
Ø  And variable is responseDoc.
Ø  Now select Replace operation.
                                                              i.      XPath: .
                                                            ii.      In Variable: body
                                                          iii.      Expression : $responseDoc
                                                           iv.      And check Replace node contents  
11.      Do same steps for multiplication branch
12.      Message Fellow Look Like
 
13.      Now debug on server.

When to use a java call out:

Ø  New to the oracle service bus programmer.
Ø  Custom Validation
Ø  Custom Transformation
Ø  Custom Authentication
Ø  Lookups for message enrichment
Ø  Custom routing rules
 

Best Practices :

Ø  Keep JavaCallout JAR file small and simple
Ø  The JAR is dynamically loaded when they are first referenced
Ø  Large Java frame work libraries should be on the system class of the server
Ø  Avoid creating threads in JavaCallout code
Ø  POJOs must be thread safe

1 comment: