This chapter describes how to integrate Enterprise JavaBeans with SOA composite applications. Integration is achieved through use of service data object (SDO) parameters or Java interfaces.
This chapter includes the following sections:
Section 36.2, "Designing an SDO-Based Enterprise JavaBeans Application"
Section 36.3, "Creating an Enterprise JavaBeans Service in Oracle JDeveloper"
Section 36.4, "Designing an SDO-Based Enterprise JavaBeans Client to Invoke Oracle SOA Suite"
Note:
Support is provided for Enterprise JavaBeans 3.0 and Enterprise JavaBeans 2.0 references (that is, when calling Enterprise JavaBeans 2.0 beans). Support is not provided for Enterprise JavaBeans 2.0 services (that is, when being called with Enterprise JavaBeans 2.0 beans).There are two options for integrating Enterprise JavaBeans with SOA composite applications:
Through use of SDO-based EJBs (uses a WSDL file to define the interface)
Through use of Java interfaces (does not use a WSDL file to define the interface)
This chapter describes both options.
You can also use the spring service component to integrate Java interfaces with SOA composite applications. For information about using the spring service component, see Chapter 49, "Integrating the Spring Framework in SOA Composite Applications."
SDOs enable you to modify business data regardless of how it is physically accessed. Knowledge is not required about how to access a particular back-end data source to use SDOs in a SOA composite application. Consequently, you can use static or dynamic programming styles and obtain connected and disconnected access.
Enterprise JavaBeans are server-side domain objects that fit into a standard component-based architecture for building enterprise applications with Java. These objects become distributed, transactional, and secure components.
Many Oracle SOA Suite interfaces are described by WSDL files. Enterprise JavaBeans interfaces are described by Java interfaces. Invocations between the two are made possible in Oracle SOA Suite by an Enterprise JavaBeans Java interface that corresponds to an Oracle SOA Suite WSDL interface.
Through this interface, Oracle SOA Suite provides support for the following:
Invoking Enterprise JavaBeans with SDO parameters through an Enterprise JavaBeans reference binding component. In this scenario, a SOA composite application passes SDO parameters to an external Enterprise JavaBeans application.
Invoking an Enterprise JavaBeans service binding component through Enterprise JavaBeans with SDO parameters. In this scenario, an Enterprise JavaBeans application passes SDO parameters into a SOA composite application.
Figure 36-1 provides an overview.
Figure 36-1 SDO and Enterprise JavaBeans Binding Integration
You use the Create EJB Service dialog in Oracle JDeveloper to define this integration, as described in Section 36.3.1, "How to Integrate SDO-based Enterprise JavaBeans with SOA Composite Applications." This option requires the use of a WSDL file. Once complete, the WSDL interaction is defined in the composite.xml
file through the interface.wsdl
entry, as shown in Example 36-1.
You can also integrate Enterprise JavaBeans with Oracle SOA Suite through Java interfaces, therefore eliminating the need for WSDL file definitions. This type of integration provides support with the following objects:
Native Java objects
Java Architecture for XML Binding (JAXB)
Java interfaces differ from SDO interfaces, which are defined in a WSDL file because of the XML-centric nature of service components such as Oracle BPEL Process Manager, Oracle Mediator, and others. No SDO parameters are required when using Java interfaces.
You use the Create EJB Service dialog in Oracle JDeveloper to define this integration, as described in Section 36.3.2, "How to Integrate Java Interface-based Enterprise JavaBeans with SOA Composite Applications." This option does not require the use of a WSDL file. Once complete, the interaction is defined in the composite.xml
file through the interface.java
entry, as shown in Example 36-2.
Example 36-2 Java Interface Definition Through interface.java Entry
<service name="PortfolioService">
<interface.java interface="com.bigbank.services.MyService" />
binding.ejb uri="MyJNDI" ejb-version="EJB3"/>
The Java class must be in the project's loader to be available to the user interface. The class must be in SCA-INF
to be deployed (not all JAR files in the project class path are deployed). This typically means that the class must be in the SCA-INF/classes
directory or in a JAR in the SCA-INF/lib
directory. However, it can also be an interface from the system class path.
For information about JAXB, see Oracle Fusion Middleware Developer's Guide for Oracle TopLink and Chapter 49, "Integrating the Spring Framework in SOA Composite Applications."
This section provides a high-level overview of the steps for designing an Enterprise JavaBeans application. For more information, see the following documentation:
Oracle Fusion Middleware Programming Enterprise JavaBeans, Version 3.0 for Oracle WebLogic Server
Oracle Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework
Oracle JDeveloper online help table of contents for the following topics:
Enterprise JavaBeans
SDO for Enterprise JavaBeans/JPA
Access the help by selecting Help > Table of Contents in Oracle JDeveloper.
Select one of the following options for creating SDO objects:
EclipseLink is an open source, object-relational mapping package for Java developers. EclipseLink provides a framework for storing Java objects in a relational database or converting Java objects to XML documents.
Use EclipseLink to create SDO objects. For instructions on installing, configuring, and using EclipseLink to create SDO objects, visit the following URL:
http://wiki.eclipse.org/EclipseLink/Installing_and_Configuring_EclipseLink
Oracle JDeveloper enables you to create an SDO service interface for JPA entities. While this feature is more tailored for use with the Oracle Application Development Framework (ADF) service binding in a SOA composite application, you can also use this feature with the Enterprise JavaBeans service binding in SOA composite applications. The SDO service interface feature generates the necessary WSDL and XSD files. If you use this feature, you must perform the following tasks to work with the Enterprise JavaBeans service binding:
Browse for and select this WSDL file in the SOA Resource Browser dialog, which is accessible from the WSDL URL field of the Create EJB Service dialog (described in Section 36.3, "Creating an Enterprise JavaBeans Service in Oracle JDeveloper").
Add the BC4J Service Runtime library to the SOA project. To add this library, double-click the project and select Libraries and Classpath to add the library in the Project Properties dialog. You are now ready to design the business logic.
For more information, see the SDO for Enterprise JavaBeans/JPA topic in the Oracle JDeveloper online help (this includes instructions on how create to an SDO service interface).
To create a session bean and import the SDO objects:
Create a simple session bean with the Create Session Bean wizard. For details on using this wizard, see the Creating a Session Bean topic in the Oracle JDeveloper online help.
Import the SDO objects into your project through the Project Properties dialog.
Add logic and necessary import and library files. In particular, you must import the Commonj.sdo.jar
file. JAR files can be added in the Libraries and Classpath dialog. This dialog is accessible by double-clicking the project and selecting Libraries and Classpath in the Project Properties dialog. You are now ready to design the logic.
Expose the method to the remote interface.
To create a profile and an EAR file:
Create an Enterprise JavaBeans JAR profile in the Project Properties dialog.
Create an application level EAR file in the Application Properties dialog.
An Enterprise JavaBeans bean must define the SDO types. Example 36-3 provides details.
Caution:
Where to calldefine
can be nontrivial. You must force the types to be defined before remote method invocation (RMI) marshalling must occur and in the right helper context. The EclipseLink SDO implementation indexes the helper instance with the application name or class loader.When you invoke the Enterprise JavaBeans method, an application name is available to the EclipseLink SDO runtime. The EclipseLink SDO looks up the context using the application name as the key. Ensure that the types are defined when the application name is visible. When an Enterprise JavaBeans static block is initialized, the application name is not created. Therefore, putting the define
in the static block does not work if you are using the default application name-based context. One way to get the application name initialized is to allocate more than two instance beans using the weblogic-ejb-jar.xml
file.Example 36-3 Definition of SDO Types
InputStreamReader reader = new InputStreamReader(url.openStream());
StreamSource source = new StreamSource(reader);
List<SDOType> list = ((SDOXSDHelper) XSDHelper.INSTANCE).define(source, null);
The weblogic-ejb-jar.xml
file is the descriptor file that must be added in the deployment jar. The weblogic-ejb-jar.xml
file is automatically created when you create a session bean. This file must be modified by adding the following entries shown in Example 36-4.
Example 36-4 weblogic-ejb-jar.xml File
<?xml version = '1.0' encoding = 'windows-1252'?> <weblogic-ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-ejb-jar http://www.bea.com/ns/weblogic/weblogic-ejb-jar/1.0/weblogic-ejb-jar.xsd" xmlns="http://www.bea.com/ns/weblogic/weblogic-ejb-jar"> <weblogic-enterprise-bean> <ejb-name>HelloEJB</ejb-name> <stateless-session-descriptor> <pool> <initial-beans-in-free-pool>2</initial-beans-in-free-pool> </pool> </stateless-session-descriptor> </weblogic-enterprise-bean> </weblogic-ejb-jar>
Figure 36-2 provides a code example of a session bean with SDO logic defined:
Figure 36-2 Session Bean with Defined SDO Logic
To generate the WSDL file, the Enterprise JavaBeans interface must use the following web service annotations. Use of these annotations is described in JSR 224: Java API for XML-Based Web Services (JAX-WS) 2.0. Visit the following URL for details:
http://www.jcp.org/en/jsr/detail?id=224
In addition, only a document/literal WSDL is currently supported by the Enterprise JavaBeans binding layer.
Table 36-1 describes the annotations to use.
Name | Description |
---|---|
|
Customizes the mapping of an individual parameter to a web service message part and XML element. Both annotations are used to map SDO parameters to the correct XML element from the normalized message payload. |
|
Denotes a method as a web service one-way operation that has only an input message and no output message. The Enterprise JavaBeans binding component does not expect any reply in this case. |
|
Tells the Enterprise JavaBeans binding components whether the deserialized object must be unwrapped or whether a wrapper must be created before serialization. An Enterprise JavaBeans interface can be generated from an existing WSDL or obtained by some other means. If the WSDL does not exist, it can be generated. |
|
Maps WSDL faults to Java exceptions. This annotation captures the fault element name used when marshalling the JAXB type generated from the global element referenced by the WSDL fault message. |
|
Specifies the @PortableWebService( targetNamespace = "http://hello.demo.oracle/", serviceName = "HelloService") The |
Add appropriate method parameter annotations |
Adds to control how message elements and types are mapped to the WSDL. For example, if your interface is in @WebMethod @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE) |
|
Adds to the interface class to use the existing schema instead of a generated one. For example: @SDODatabinding(schemaLocation = "etc/HelloService.xsd") |
Example 36-5 provides an example of an Enterprise JavaBeans interface with annotations.
Example 36-5 Enterprise JavaBeans Interface with Annotations
@Remote @PortableWebService(targetNamespace = "http://www.example.org/customer-example", serviceName = "CustomerSessionEJBService") @SDODatabinding(schemaLocation = "customer.xsd") public interface CustomerSessionEJB { @WebMethod(operationName="createCustomer") @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE) @WebResult(targetNamespace = "http://www.example.org/customer-example", partName = "parameters", name = "customer") CustomerType createCustomer(); @WebMethod(operationName="addPhoneNumber") @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE) @WebResult(targetNamespace = "http://www.example.org/customer-example", partName = "parameters", name = "customer") CustomerType addPhoneNumber(@WebParam(targetNamespace = "http://www.example.org/customer-example", partName = "parameters", name = "phone-number")PhoneNumber phNumber); }
This section describes how to create an Enterprise JavaBeans reference binding component or Enterprise JavaBeans service binding component in Oracle JDeveloper. The Enterprise JavaBeans service enables the Enterprise JavaBeans application to communicate with Oracle SOA Suite and Oracle SOA Suite to communicate with remote Enterprise JavaBeans.
This section describes how to create the following types of integrations:
Integration through an SDO interface
Integration through a Java interface
You can create the following types of SDO-based Enterprise JavaBeans integrations with SOA composite applications:
Invoke SDO-based Enterprise JavaBeans from a SOA composite application
Invoke a SOA composite application from Enterprise JavaBeans using SDO parameters
To integrate SDO-based Enterprise JavaBeans with SOA composite applications:
In the SOA Composite Editor, drag the EJB Service icon into the appropriate swimlane, as described in Table 36-2.
In the Interface section, click WSDL.
See the step in Table 36-3 based on the swimlane in which you dragged the EJB Service.
If You Dragged the EJB Service to this Swimlane... | Then Go To... |
---|---|
External References |
|
Exposed Services |
View the Create EJB Service dialog that displays in the External References swimlane, as shown in Figure 36-3.
Figure 36-3 Create EJB Service in External References Swimlane
View the Create EJB Service dialog that displays in the Exposed Services swimlane, as shown in Figure 36-4.
Figure 36-4 Create EJB Service in Exposed Services Swimlane
Enter values appropriate to your environment. The fields that display differ based on the swimlane in which you dragged the EJB Service icon. Table 36-4 provides details.
Table 36-4 Create EJB Service Dialog
Field | Value |
---|---|
Name |
Accept the default value or enter a different name. |
Type |
Displays the following value:
|
Version |
Select the version of EJB to support: EJB2 or EJB3 (the default selection). Note: This field only displays if you dragged the EJB Service icon into the External References swimlane. |
Interface |
Select WSDL. |
JNDI Name |
Note: This field only displays if you dragged the EJB Service icon into the External References swimlane. Enter the JNDI name of your Enterprise JavaBeans. |
Jar File |
Click the Search icon to select the EJB JAR file created in Section 36.2, "Designing an SDO-Based Enterprise JavaBeans Application." The SOA Resource Browser dialog searches for and displays JAR files starting in the Note: If you select a JAR file outside of the current project, Oracle JDeveloper creates a copy of the JAR file in the SCA-INF/lib directory of the current project. When prompted, click OK to accept. |
Java Interface |
Click the Browse icon to invoke the Class Browser dialog for selecting the fully qualified Java class name of the previously created Enterprise JavaBeans interface. This class must exist in the selected JAR file. If a JAR file is not specified, it is assumed that the class is in the Note: If you use the Jar File field, you do not need to add a new JAR file to the project by selecting Project Properties > Libraries and Classpath > Add JAR/Directory from the Application main menu. |
WSDL URL |
Note: Ensure that you have created the annotations for the Enterprise JavaBeans interface before generating the WSDL file, as described in Section 36.2.5, "How to Use Web Service Annotations." Click the second icon to the right to generate a WSDL file that represents the Enterprise JavaBeans interface. If you created SDO objects through Oracle JDeveloper, as described in Section 36.2.1, "How to Create SDO Objects Using the SDO Compiler," ensure that you select the WSDL file that was automatically generated with this option. |
Port Type |
Select the port type. |
Callback Port Type |
Select the callback port type (for asynchronous services). |
Click OK.
You can create the following types of Java interface-based Enterprise JavaBeans integrations with SOA composite applications:
Invoke Java interface-based Enterprise JavaBeans from a SOA composite application
Invoke a SOA composite application from Enterprise JavaBeans using a Java interface
To integrate Java interface-based Enterprise JavaBeans with SOA composite applications:
Drag an EJB Service icon into the appropriate swimlane:
To invoke an Enterprise JavaBeans reference binding component from a SOA composite application, drag the icon to the External References swimlane.
To invoke a SOA composite application from an Enterprise JavaBeans service binding component, drag the icon to the Exposed Services swimlane.
In the Interface section, click Java (if it is not already selected).
The Create EJB Service dialog displays the fields shown in Figure 36-5.
Figure 36-5 Create EJB Service for Java Interface
Enter the details shown in Table 36-5. The fields are the same regardless of the swimlane in which you dragged the EJB Service icon.
Table 36-5 Create EJB Service Dialog
Field | Value |
---|---|
Name |
Accept the default value or enter a different name. |
Type |
Displays the following value:
|
Version |
Select the version of EJB to support: EJB2 or EJB3 (the default selection). Note: This field only displays if you dragged the EJB Service icon into the External References swimlane. |
Interface |
Select Java. |
JNDI Name |
Enter the JNDI name of your Enterprise JavaBeans. |
Jar File |
Click the Search icon to select the EJB JAR file created in Section 36.2, "Designing an SDO-Based Enterprise JavaBeans Application." The SOA Resource Browser dialog searches for and displays JAR files starting in the Note: If you select a JAR file outside of the current project, Oracle JDeveloper creates a copy of the JAR file in the SCA-INF/lib directory of the current project. When prompted, click OK to accept. |
Java Interface |
Select one of the following options.
|
Click OK.
To invoke an SDO - Enterprise JavaBeans service from Enterprise JavaBeans, you must use the client library. Follow these guidelines to design an Enterprise JavaBeans client.
Look up the SOAServiceInvokerBean
from the JNDI tree.
Get an instance of SOAServiceFactory
and ask the factory to return a proxy for the Enterprise JavaBeans service interface.
You can include a client side Enterprise JavaBeans invocation library (fabric-ejbClient.jar
or the fabric-runtime.jar
file located in the Oracle JDeveloper home directory or Oracle WebLogic Server) in the Enterprise JavaBeans client application. For example, the fabric-runtime.jar
file can be located in the JDev_Home
\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1
directory.
If the Enterprise JavaBeans application is running in a different JVM than Oracle SOA Suite, the Enterprise JavaBeans application must reference the ejbClient
library.
Example 36-6 provides an example.
Example 36-6 Enterprise JavaBeans Client Code
Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); props.put(Context.PROVIDER_URL, "t3://" + HOSTNAME + ":" + PORT); 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); //-- Get a dynamice proxy that is essentially a remote reference HelloInterface ejbRemote = serviceFactory.createService("MyTestEJBService", HelloInterface.class); //-- Invoke methods Item item = (Item) DataFactory.INSTANCE.create(Item.class); item.setNumber(new BigInteger("32")); SayHello sayHello = (SayHello) DataFactory.INSTANCE.create(SayHello.class); sayHello.setItem(item); SayHelloResponse response = ejbRemote.sayHello(sayHello); Item reply = response.getResult();
To specify role names required to invoke SOA composite applications from any Java EE application, you add the roles names in the Enterprise JavaBeans service configuration. The Enterprise JavaBeans service checks to see if the caller principal has the security role. Example 36-7 provides details.
Example 36-7 Enterprise JavaBeans Roles
<service name="EJBService" ui:wsdlLocation="BPELEJBProcess.wsdl">
<interface.wsdl
interface="http://xmlns.oracle.com/EJBApplication/EJBProject/BPELEJBProcess#wsdl.int
erface(BPELProcess1)"callbackInterface="http://xmlns.oracle.com/EJBApplication/
EJBProject/BPELEJBProcess#
wsdl.interface(BPELEJBProcessCallback)"/>
<property name="rolesAllowed">Superuser, Admin</property>
<binding.ejb javaInterface="java.class.ejb.com" serviceId="EJBService"
jarLocation="soaejb.jar"/>
</service>
This section describes two methods for configuring JNDI access.
Follow these guidelines to configure JNDI access.
You can configure a foreign JNDI provider to link a foreign JNDI tree to your local server instance and access the object as if it is local. See Oracle Fusion Middleware Programming JNDI for Oracle WebLogic Server.
You can also provide JNDI environment variables as the properties for the Enterprise JavaBeans reference, as shown in Example 36-8. An Enterprise JavaBeans binding component enables you to create your own map or use the default EJBBC
binding component map. Note that the map
property is optional if you use EJBBC
. For security reasons, the JNDI security credentials must be stored in a CSF store and referenced as shown in Example 36-8.
Example 36-8 Environment Variables for Enterprise JavaBeans Reference
<property name= "java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</property> <property name="java.naming.provider.url">t3://host:7001</property> <property name="oracle.jps.credstore.map">default</property> <property name="oracle.jps.credstore.key">weblogic</property>
The security credential can also be stored in the credential store framework. For more information, see Oracle Fusion Middleware Security Guide.
If you create your own credential store framework (CSF) map instead of using the default Enterprise JavaBeans BC CSF map, you must modify the Domain_Home
/config/fmwconfig/
system-jazn.data.xml
file and add the permission shown in Example 36-9 to the entry for the fabric-runtime.jar
permission grant.
Example 36-9 Permission to Add
<class>oracle.security.jps.service.credstore.CredentialAccessPermission</class> <name>>context=SYSTEM,mapName=*,keyName=*</name> <actions>*</actions> </permission>
You must then restart Oracle WebLogic Server.
For more information on CSF, see Oracle Fusion Middleware Security Guide.