Monday, 12 May 2014

INVOKING EJB SERVICE FROM OSB


1.     Create ejb Project:

·         Open eclipse in J2EE mode.
·         Click file -> new  -> other -> ejb Project.



·         Enter project name SampleEJB.
·         Target Runtime Server name. I’m using Weblogic server 10.3.6.
·         EJB module version 3.0
·         Click to add project to an EAR (use existing EAR project name or create new EAR project )
·         Click finish.
 
2.     Create New Session Bean:
·         Click file -> new -> Session Bean


·         Select EJB project Name (in this case SampleEJB )
·         Enter java Package (com.acc )
·         Enter class name (TheBean)
·         State Type (stateless)
·         In business interface Click Remote
·         Click next

 
·         Enter mapped name TheBean
·         Click finish
 
3.     Write Code:
·          Add new method to TheBeanRemote session bean interface
            public String saySomething(String name);
·         Save it.
·         Go to TheBean.java. Click on error. Click Add unimplemented methods
 
·         Now write
public String saySomething(String name)
{                   return "My name is "+ name;
}
·         Save it.
4.     Deploy in server
·         Right click to SampleEJBEAR -> Run As -> Run on Server.

 
·         After deploying on server, SampleEJBEAR project become Synchronized.
 
·         Now Write click on SampleEJBEAR , Export -> EAR file
 
·         Enter Destination location and click finish.
·         Open SampleEJBClient.ear file and copy SampleEJBClient.jar to a folder.
·         For JNDI name:
·         Go to http://localhost:7001/console
·         Click on server

 
·         Click Admin Server
·         Click View JNDI Tree
 
·         Click TheBean#Com
·         And get Binding Name: TheBean#com.acc.TheBeanRemote
·         This is JNDI name.
·         JNDI name : TheBean#com.acc.TheBeanRemote
5.     Create Oracle Service Bus Project
·         Switch eclipse Resource J2EE to Oracle Service Bus.
·         Click file -> new -> Oracle Service Bus Configuration Project.

 
·         Enter name OSB_Config_Project.
·         Click finish.
·         Right click on Configuration project -> new -> Oracle Service Bus Project
·         Enter name TestEJBProject.
·         Click Finish.
6.     Create JNDI Provider
 
·         Right click on OSB configuration project -> new -> JNDI Provider
 
·         Enter JNDI provider name myJNDIProvider
 
·         Click next
·         Enter server Credential
o   Description : Local WLS server
o   JNDI Cache : Enable
o    Provider URL : t3://localhost:7001
o   JNDI Request Timeout : 0
o   Username : weblogic
o   Password : welcome1


 
·         Click finish.
7.     Create Business service:
·         Create two folders inside TestEJBProject OSB project.
o   BusinessServices
o   Jars
·         Copy SampleEJBClient.jar to Jars folder.
·          Right click on BusinessServices folder and create Business Service.


 
·         Enter Business Service Name SampleEJBBusinessService.
·         Business Service Configuration
·         General tab:
o    Click Transport Type
·         Transport tab :

 
Protocol Type: ejb
Endpoint URI: ejb:myjndiprovider:TheBean#com.acc.TheBeanRemote
[ejb:<JNDIProvider name>:<JNDI Name>]
 
·         EJB Transport tab:
o   EJB 3.0 : Check
o   Client Jar: SampleEJBClient.jar  (Browse it)
o   Business Interface : Com.acc.TheBeanRemote
·         Save it.
8. Deploy and Run :

 

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