With Oracle Soa Suite 11G ( FMW11G R1 ) we can finally use the EJB adapter. This adapter can be used as a service or reference. This means we can start a BPEL process by calling a EJB session method or use an EJB to lookup or change data. Using an EJB as service or reference is very cool because it is fast ( RMI ) and we can use the same EJB's ( Multi Tier ) for your Java Web applications and your composites ( Who needs the Database Adapter now?) Here is a picture of the composite application with an EJB adapter as Service and Reference.
In this blog I will explain you first, how the SDO EJB is created and then how we use this as a Reference and as a Service
Create SDO Eclipse EJBFirst step is to create an EJB entity with Eclipselink as persistence provider. For this example I used the Employees table of the HR schema. Next step is to create an EJB Session Bean.Here is an overview of my EJB model project.
Select the Session Bean and generate a service interface on this
Now it goes totally wrong with the JDeveloper wizard 11G R1.
First step is fix the packages names of the SDO and SDOImpl classes, then we can refractor these classes and move it to the entities package. With this as result.
Select the session bean again and generate for the second time the service interface. Now we will get the WSDL.
Move the EJB WSDL and XSD to the Session bean package. With this as result.
Open the Entity XSD and change the target namespace and xmlns namespace to the same name as the package name in my case /nl/whitehorses/hr/ejb/entities/.before
after
Open the XSD of the WSDL and import the entity schema and fix the namespace.
Change /nl.whitehorses.hr.ejb.services/ to /nl/whitehorses/hr/ejb/services/ in every java, XSD or WSDL file
Create a Datasource to the HR schema in Weblogic and make sure you are using the XA Oracle Driver and target this Datasource to the Soa suite server.
Deploy the EJB to the Soa Suite instance.
Using the SDO Ejb as a reference in Soa Suite 11gOpen the composite application and drag the EJB adapter on the reference part of the composite.
Fill in the JNDI of the EJB on soa suite server , select the EJB jar and provide the Remote EJB interface class name. Select the WSDL , Go the classes folder of the EJB model project and select the Session bean WSDL. This will copy the WSDL and the XSD to the local project folders and also import the jar. That's all , now you can invoke this in a BPEL process.
Using the SDO Eclipselink Ejb as a Service in Soa Suite 11gWe can use the same EJB as starting point of our composite application. This time Soa Suite only uses the interface and does nothing with the Session Bean methods. Drag the EJB adapter to the Services side of the composite overview.
The Service ID is very important because we need this name in serviceFactory.createService, The rest is the same as in the reference part. Use this EJB Service in a BPEL process.
Now we only have to make a simple java class where we call this EJB composite service.
package nl.whitehorses.soa.ejb.service;
import commonj.sdo.helper.DataFactory;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import nl.whitehorses.hr.ejb.entities.EmployeesSDO;
import nl.whitehorses.hr.ejb.services.HrEmployeeEJB;
import oracle.integration.platform.blocks.sdox.ejb.api.SOAServiceFactory;
import oracle.integration.platform.blocks.sdox.ejb.api.SOAServiceInvokerBean;
import oracle.jbo.common.sdo.SDOHelper;
public class callejb {
public callejb() {
super();
}
public static void main(String[] args) {
try {
// very important to load every schema you use in the EJB
try {
SDOHelper.INSTANCE.defineSchema("nl/whitehorses/hr/ejb/entities/", "EmployeesSDO.xsd");
SDOHelper.INSTANCE.defineSchema("nl/whitehorses/hr/ejb/services/", "HrEmployeeEJBBeanWS.xsd");
} catch (Exception ex) {
ex.printStackTrace();
}
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
// soa suite server
props.put(Context.PROVIDER_URL, "t3://localhost:8001");
InitialContext ctx = new InitialContext(props);
SOAServiceInvokerBean invoker = (SOAServiceInvokerBean)ctx.lookup("SOAServiceInvokerBean#oracle.integration.platform.blocks.sdox.ejb.api.SOAServiceInvokerBean");
//-- Create a SOAServiceFactory instance
SOAServiceFactory serviceFactory = SOAServiceFactory.newInstance(invoker);
// use the Service Id in the EJB service adapter
HrEmployeeEJB hrEmployeeEJB = serviceFactory.createService("EmployeeService", HrEmployeeEJB.class);
EmployeesSDO employeesSDO = ( EmployeesSDO )DataFactory.INSTANCE.create(EmployeesSDO.class);
employeesSDO.setDepartmentId(1L);
employeesSDO.setEmail("aaa@aa.nl");
employeesSDO.setEmployeeId(1L);
employeesSDO.setFirstName("edwin");
employeesSDO.setJobId("aa");
employeesSDO.setLastName("biemond");
employeesSDO.setPhoneNumber("123");
employeesSDO.setSalary(1000);
EmployeesSDO resultEmployeesSDO = hrEmployeeEJB.persistEmployeesSDO(employeesSDO);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Here is the result of a EJB service instance.
Here the link to official EJB adapter(http://download.oracle.com/docs/cd/E12839_01/integration.1111/e10224/sca_sdo_ejb.htm) documentation. ( This can be a lot better )
Download here the EJB project(http://www.sbsframes.nl/jdeveloper/AdfEjbHr.zip) I used and here the Soa Suite project (http://www.sbsframes.nl/jdeveloper/SoaEjbReference.zip).