28 EJB Transport

This chapter provides an overview of the EJB transport and describes how to use and configure it in your services.

Using the EJB transport, Oracle Service Bus supports native RMI invocation of EJB 2.1 or EJB 3.0 stateless session beans deployed on supported platforms. It allows transactional and secure communications. You can also leverage the EJB transport to expose an EJB as a Web Service through Oracle Service Bus.

This chapter includes the following sections:

28.1 Introduction

In Oracle Service Bus, you can configure business services to use the EJB transport. The EJB transport is fully integrated into the Oracle Service Bus Administration Console and Test Console. You can use business services configured with the EJB transport for publish, service callout, and service invocations. You cannot create proxy services that use the EJB transport.

The EJB transport provides the following capabilities:

Transactional Integrity – You can call an EJB business service in the context of a global transaction. The EJB transport can also suspend or start a global transaction before invoking an EJB.

Security Propagation – The security context established at the beginning of a message flow, from an Oracle Service Bus client, is propagated to the other system. For example, an incoming SOAP over HTTP request to Oracle Service Bus that requires authentication is authenticated by Oracle Service Bus and the authenticated subject can then be propagated to the EJB server. See "Important Information Regarding Cross-Domain Security Support" in Oracle Fusion Middleware Securing Oracle WebLogic Server.

HTTP Tunneling and Encrypted Communication – You can access EJBs that are behind a firewall with HTTP tunneling. For additional security, you can use SSL to encrypt all of the communications with the EJB Server.

JNDI Provider – EJB transport leverages the JNDI provider—an Oracle Service Bus resource. The JNDI provider defines communication protocols and security credentials for accessing remote servers. A JNDI provider can be reused by multiple EJB business services. This provides a centralized way for administrators to manage remote EJB server configurations.

For information about JNDI provider resources, see Section 2.1.8, "Creating and Editing JNDI Provider Resources."

High Performance Caching – The EJB transport is built on high performance cache. This allows the reuse of established connections and minimizes EJB stubs lookups.

Failover and Load Balancing – The EJB transport can take advantage of scenarios in which the same EJB is deployed in multiple domains or on a cluster for load balancing or failover or both.

Advanced XML to Java Binding Capabilities – The EJB transport leverages the Oracle WebLogic Server JAX-RPC stack to perform Java to XML bindings. The JAX-RPC stack is a high performance engine that supports advanced Java objects such as XML Beans. If the Java type is not recognized by the stack, an extension mechanism is provided to facilitate support of these Java types. For information about this extension mechanism (using the converter classes), see Section 28.4.2, "Supported Types and Converter Class."

Intelligent Retries – The EJB transport makes retry decisions based on the nature of the failure that can occur during the invocation of an EJB.

28.2 Invoking EJBs from Oracle Service Bus

Before you can configure a business service in Oracle Service Bus, you must register a JNDI provider resource and a client JAR resource. This section describes how to design and configure an EJB transport business service in Oracle Service Bus.

28.2.1 Register a JNDI Provider Resource

A JNDI Provider resource lets you specify the communication protocols and security credentials used to retrieve EJB stubs bound in the JNDI tree of remote Oracle WebLogic Server domains. (For more information on how to set up a JNDI tree, see Oracle Fusion Middleware Programming JNDI for Oracle WebLogic Server.

Typically, the target EJB is not located in the same domain as Oracle Service Bus. In this case, you must register a JNDI Provider resource. When the EJB is located in the same domain, you can define a provider to specify credentials and take advantage of stubs caching, although it is optional in this case.

The JNDI provider has a high performance caching mechanism for remote connections and EJB stubs. The preferred communication protocol from Oracle Service Bus to an Oracle WebLogic Server domain is t3 or t3s. If messages need to go through a firewall, you can use HTTP tunneling.

Note:

Although it is possible to use an Oracle WebLogic Server foreign JNDI Provider, Oracle recommends that you do not.

The transport does not support two-way SSL or CLIENT CERT to look-up JNDI tree or access a method on an EJB.

28.2.1.1 Adding a JNDI Provider

For information about registering and configuring a JNDI provider resource in Oracle Service Bus, see Section 4.8, "JNDI Providers."

28.2.2 Register an EJB Client JAR Resource

A client JAR must be registered as a resource in Oracle Service Bus. It is therefore part of the Oracle Service Bus configuration and can be exported from and imported into a project.

An EJB client JAR file must contain the interfaces and classes needed by Oracle Service Bus to access an EJB. This includes the remote and home interfaces (EJB 2.1) or business interfaces (EJB 3.0) and any dependent types to which the client is exposed, such as method parameter types or application exceptions.

If your business service requires converter classes, you can register a JAR file containing the converter classes as an Oracle Service Bus resource and subsequently use these classes to help map parameter and return value types to Java classes that can be mapped to XML. Alternatively, you can package these converter classes in the EJB client JAR. For information about converter classes, see Section 28.4.2.1, "Converter Classes."

Consider the following guidelines when using EJB client JARs:

  • Adding home and remote interfaces in the system classpath is bad practice and is not supported by Oracle Service Bus.

  • Oracle recommends that you keep the client JAR size small, include a single home interface per JAR and not register the entire ejb-jar file.

  • You can use Eclipse to obtain a client JAR for EJBs deployed on Oracle WebLogic Server.

  • Oracle Service Bus supports client-jars compiled with JDK 1.4 or later.

28.2.2.1 Adding a Client or Converter JAR

For information about registering and configuring a JAR resource in Oracle Service Bus, see "Adding JARs" in the Oracle Fusion Middleware Administrator's Guide for Oracle Service Bus.

28.2.2.2 Create a Service Account (Optional)

If the EJB methods are protected, you can specify the credentials you want to use for the invocations. Those credentials are often different than the credentials used by the JNDI provider. For information about adding and using service accounts, see Section 2.1.15, "Creating Service Account Resources."

28.2.2.3 Locate an EJB in the JNDI Tree

If you do not know the JNDI name for an EJB, you can browse the EJB Server JNDI tree. For information about browsing the JNDI tree using the Oracle WebLogic Server Administration Console, see "View objects in the JNDI" tree in the Oracle Fusion Middleware Oracle WebLogic Server Administration Console Online Help.

28.2.3 Transport Configuration Reference

An EJB business service is a Transport Typed Service, which means the type of the transport is determined by the configuration of the service.

The type of an EJB business service is equivalent to a SOAP XML service—in other words, you can use an EJB business service like any other SOAP XML business service. A WSDL is generated when you save the EJB Transport Configuration.

The WSDL is generated based on the interface of the EJB. The EJB transport configuration page provides configuration options for you to control the interface of the service and the WSDL that is generated.

This section describes the endpoint URL format and configuration options for the EJB transport.

28.2.3.1 EJB Endpoint URI

Following is the URI pattern for the EJB transport:

ejb:jndi_provider_name:ejb_jndi_name

where jndi_provider_name is the name of the Oracle Service Bus JNDI provider resource.

If the EJB is deployed locally, you need not provide a JNDI provider name. In this case, the URI format is:

ejb::ejb_jndi_name

For EJB 3.0 business services on Oracle WebLogic Server, ejb_jndi_name takes the form of mappedName#BusinessInterface.

Note:

If your EJBs are running on IBM WebSphere, ejb_jndi_name must be in the following format:

cell/nodes/node_name/servers/server_name/ejb_jndi_name

or

cell/clusters/cluster_name/ejb_jndi_name

as described in the IBM WebSphere documentation at http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.nd.iseries.doc/info/iseriesnd/ae/rnam_example_prop3.html

28.2.3.2 EJB Transport Configuration for Business Services

Table 28-1 describes the transport-specific configuration options for the EJB transport.

Table 28-1 EJB Transport Configuration Options for Business Services

Option To create or edit...

Pass Caller's Subject

Select this check box to have Oracle Service Bus pass the authenticated subject from the proxy service when invoking the EJB and no service accounts are configured. The Service Account field is disabled when this option is selected.

Service Account

Click Browse and select a service account from the list displayed. If no service account is specified, an anonymous subject is used. This option is not available if you use the Pass Caller's Subject option.

Supports Transaction

Select this check box to specify transaction support.

Client Jar

Click Browse and select an EJB client JAR resource from the list displayed.

Converter Jar

Click Browse and select an EJB converter class JAR resource from the list displayed.

For more information, see Section 28.2.2.1, "Adding a Client or Converter JAR" and Section 28.4.2.1, "Converter Classes."

Home Interface

EJB 2.1 only – Select the required EJBHome interface from the options populated by the JAR. The JNDI name in this URI sample must be associated with the EJBHome interface you select here. If the EJB is not of the required type or an EJBHome interface is not specified in the client-jar, Oracle Service Bus displays a warning.

Remote Interface

EJB 2.1 only – This field is automatically populated depending on the configuration of the Home Interface.

Business Interface

EJB 3.0 only – Select the business interface in the client JAR that you want to invoke.

Target Namespace

This field is populated by information picked up from the JAR.

Style

Select Document Wrapped or RPC according to your requirements. If two or more methods of your stateless session EJB have the same number and data type of parameters, and you want the operations to be document-oriented, you must specify that they be document-wrapped.

The style is important because when routing or publishing to the EJB, $body must have content that matches the style. Also when calling out to an EJB, the style affects the parameter contents, especially for document wrapped. Secondly one usage pattern is to define an EJB business service and then create a proxy service with the same WSDL that routes to the EJB. In this case care must be taken on the style of the WSDL because the client tool used to invoke the proxy might have limitations on the style of the WSDL.

Encoding

Select Encoded or Literal.

Methods

Select the required methods. Click + to expand the method, which lets you edit the default parameter values and select a converter if provided or required.

You must exclude the methods with parameters or return types that are not supported by the JAX-RPC stack, or you must associate such arguments with converter classes.

You can change the default operation name for a given method. By default, the operation name is the method name. If an EJB contains methods with same name, you must change the operation names so that they are unique. WSDLs require unique operation names.

Note: If the credentials or transaction settings are different between the methods for a given EJB, you can customize the methods for a given business service, and create a business service per method. This gives you fine-grained control over transactions and credentials.

Exceptions

This field appears if a method throws a business exception. If an EJB method throws an exception that has data types not supported by Java Web Services (JWS), such as an ArrayList, use the Exceptions field to select a converter class that converts the exception to a type supported by JWS.

Your converter class must implement com.bea.wli.sb.transports.ejb.ITypeConverter. Converter classes can only be configured for checked exceptions and not for runtime exceptions.

Package the converter class and the converted exception class in the client or converter JAR.


28.2.4 Invoking EJB Business Services

An EJB business service can be used as a SOAP XML business service. You can publish to, route to, or callout to an EJB business service. If you need transaction support, set the quality of service to Exactly-Once. See Section 28.4.1, "Transaction Processing, Retries, and Error Handling."

You can also use the Test Console to validate your configuration and to help you to determine the shape of the XML request.

28.3 Exposing EJBs as Web Services

You can leverage the EJB transport to easily expose EJBs as Web Services.

Note:

You cannot create a proxy service from an existing EJB business service—you must first get the WSDL generated from the EJB business service, and then create the proxy service based on that WSDL. To do so, complete the following steps.

  1. Create an EJB business service pointing to the EJB you want to expose, as described in Section 28.2.3, "Transport Configuration Reference."

  2. From the service details page, get the WSDL for the EJB business service.

    The WSDL is contained in a JAR file. You can obtain the WSDL only if there is no pending session.

  3. Extract the WSDL from the JAR and register it as a WSDL resource.

    If the configuration of the business service changes, a new WSDL is generated. If that happens, you must get the new WSDL and re-register it as a WSDL resource.

  4. Create a SOAP XML proxy service based on the WSDL.

  5. Edit the proxy service pipeline and route to the EJB business service.

You can now invoke the EJB as a Web Service with no need for purchasing an expensive Web Service toolkit or carrying out intrusive actions on the EJB server.

28.4 Advanced Topics

This section includes information about EJB transport that will help you understand how EJB business services behave at runtime depending on how they are configured at design time.

28.4.1 Transaction Processing, Retries, and Error Handling

This section describes the EJB transport's transaction processing, retries and failover, and error handling.

28.4.1.1 Transactions

The EJB transport can create, suspend, and propagate transactions. The transaction between Oracle Service Bus and the EJB server are XA transactions. If you use transactions with HTTP tunneling or have a dedicated communication channel, you must set the security interoperability mode for the transaction manager to performance. For information about setting the security interoperability mode and other transaction configurations, see "Configuring Transactions" in Oracle Fusion Middleware Programming JTA for Oracle WebLogic Server.

For the deployment descriptors to be set appropriately for XA-capable resources, you must set the XA attribute on the referenced connection factory before creating a proxy service.

To determine the behavior of the EJB business service, considerations include whether the proxy service pipeline has a transactional context, and what quality of service (QoS) settings are specified in the pipeline when invoking the service:

QoS Best-Effort – If Best-Effort QoS is specified in the pipeline, no transaction is propagated to the EJB—any ongoing transaction is suspended before invocation, and resumed after invocation.

QoS Exactly-Once – If Exactly-Once QoS is specified in the pipeline, and If the EJB does not support transactions (that is, if the Supports Transaction option on the EJB transport configuration page is unchecked), no transaction is propagated to the EJB. As in the case of Best-Effort, any ongoing transaction is suspended before invocation and resumed afterwards.

or

If the EJB supports transactions (that is, if the Supports Transaction option on the EJB transport configuration page is checked), the EJB is invoked in the context of a transaction—any ongoing transaction is propagated to the EJB. If no transaction is present, a transaction is created before invocation and committed afterwards.

For more information about QoS in Oracle Service Bus services, see "Quality of Service" in the Oracle Fusion Middleware Administrator's Guide for Oracle Service Bus.

28.4.1.2 Retries and Failover

Assuming that the EJB business service is configured for retries or failovers, the EJB transport distinguishes the following types of exceptions:

  • Runtime Exceptions or Remote Exceptions—typically unexpected fatal errors or communication exceptions

  • Exception raised by the JAX-RPC engine—exceptions that occur during the XML to Java conversion

  • EJB Checked Exceptions—exceptions declared in the EJB method signature specific to the EJB implementation; also called Business Exceptions

Retries and failover are based on the type of errors and also in the QoS:

QoS Best-Effort – If a runtime or remote exception is thrown, the EJB transport attempts retries or failovers.

If an exception occurs in the JAX-RPC engine, an error is raised to the pipeline and no retries or failover attempts are made.

If an EJB Checked Exception is thrown, an error is raised to the pipeline and no retries or failover attempts are made.

QoS Exactly-Once – If a runtime or remote exception is thrown and the ongoing transaction has been set as rollback only (likely by the EJB container), it means the EJB container has been reached and a fatal error either occurred within the EJB container or the EJB. In this case, no retries or failover attempts are made and an error is raised to the pipeline.

If a runtime or remote exception is thrown but the ongoing transaction has not been set as rollback only, it means an error occurred before the invocation of the EJB container and the EJB transport will attempt retries or failovers. Note that in this case, the EJB transport still respects the exactly-once semantic.

If an exception occurs in the JAX-RPC engine, the EJB transport sets the ongoing transaction to rollback only and an error is raised to the pipeline; no retries or failover attempts are made.

If an EJB Checked Exception is thrown, an error is raised to the pipeline and no retries or failover attempts are made.

See Section 28.4.1.1, "Transactions" for other repercussions of QoS specifications for an EJB business service.

28.4.1.3 Error Handling

When throwing a checked exception, according to the EJB specifications, the ongoing transaction can be specified as rollback only.

If the ongoing transaction is set as rollback only by the EJB developer, the transaction is eventually rolled back by its creator (most likely the proxy service).

If the ongoing transaction is not set to rollback only, and a checked exception is raised, it is important to catch EJB checked exceptions in the pipeline with an error handler. If those exceptions are not caught, the pipeline errors are propagated back to the proxy service. The proxy service, in turn, is likely to rollback the ongoing transaction (depending of the transport implementation)—this may not be the intended result.

For example, assume you have an EJB with the following method:

public void withdrawFunds(float amount) throws RemoteException, InsufficientFundsException {…}

Also assume that when an InsufficientFundsException exception is thrown, the EJB does not set the current transaction as rollback only. In most scenarios, it is wrong to allow the proxy service to roll back the transaction—you may need to configure an error handler in the pipeline to catch the error and avoid this scenario.

28.4.2 Supported Types and Converter Class

The EJB transport is responsible for the conversion between XML and Java. The conversion is performed by the Oracle WebLogic Server JAX-RPC engine.

The EJB transport natively supports the following types:

  • Primitive types

  • XmlObject (both Apache and Oracle versions)

  • Schema generated XMLBeans (both Apache and Oracle versions)

  • JavaBean classes

For the full list of natively supported types, see "Using JAXB Data Binding" in Oracle Fusion Middleware Getting Started With JAX-WS Web Services for Oracle WebLogic Server.

An EJB method can use parameters/return types that are either not supported by the JAX-RPC engine (an error is reported at design time) or that do not map directly to XML (errors occur at runtime). The most commonly used unsupported types are:

  • "Object", "Object[]"

  • Java Collections, as they are not strongly typed (for example, List, Set)

  • Java classes that do not follow the JavaBean pattern (for example, Map)

You can write a custom converter class that converts those types into types more suitable for conversion between XML and Java. The EJB transport supports custom converter classes.

28.4.2.1 Converter Classes

A Converter class is a Java class that implements and conforms to the contract defined by the com.bea.wli.sb.transports.ejb.ITypeConverter Java interface of the Oracle Service Bus public API.

To use a converter class for an EJB business service, you must:

  1. Create a converter class by implementing and compiling the interface.

  2. Add the converter class to the client JAR or to a converter class JAR file (See Section 28.2.2.1, "Adding a Client or Converter JAR").

  3. When customizing the method configuration during the creation of an EJB business service, navigate to one of the parameter/return types and select the desired converter. See Section 28.2.3, "Transport Configuration Reference"—the service configuration user interface displays a list of the converters available that can be applied to a particular parameter/return type.

28.4.3 Business Exception Classes

Business exception classes thrown by an EJB method must comply with JAX-RPC 1.1 Specification Section 5.5.5 to ensure proper mapping of the exception class details into the WSDL type definition for the fault element. All private, non-transient fields with corresponding getter methods in the exception class get mapped to the exception type definition in the WSDL.

28.5 Troubleshooting

The information in this section is provided to help you troubleshoot problems when designing or running an EJB business service.

28.5.1 Enabling Debug Mode

The EJB transport uses the same logger as other Oracle Service Bus transports. To enable the debug mode, before starting the server, edit the alsbdebug.xml file in the domain directory and set the category alsb-transports-debug to true. For more information about the alsbdebug.xml file and the debug flags, see "Debugging Oracle Service Bus" in the Oracle Fusion Middleware Administrator's Guide for Oracle Service Bus.

28.5.2 Temp Directories

During design time, the EJB transport generates files in a subfolder in the temp directory. It is safe to delete those folders and files, and sometimes may be useful to check them to determine what went wrong during activation.

28.5.3 Deployed Application

When an EJB business service is created an application is deployed on the Oracle Service Bus Server. You can use the Oracle WebLogic Server Administration Console to monitor and tune this application.

28.5.4 Errors

The following items may help in the event that you need to troubleshoot a problem with an EJB business service:

  • The following error when creating a business service is due to a Windows operating system limitation—paths containing more than 255 characters are not supported:

    The system cannot find the path specified):Probably the string length of the path of the file being extracted was too long 
    

    You can try to reduce the path length by creating a shorter path to the Oracle Service Bus domain, or you can use the following option to override the Oracle WebLogic Server temp directory when starting the server:

    -Dweblogic.j2ee.application.tmpDir=$desired_short_dir
    
  • If you get an XML marshalling error when invoking an EJB business service and you believe the request to be valid against the service WSDL, you probably need to write a converter class. For information, see Section 28.4.2.1, "Converter Classes."

  • If the EJB interfaces and stubs are changed on the remote server, the first time you try to invoke the new EJB, an error is thrown. Those changes on the remote server are not visible to Oracle Service Bus—it tries to invoke the cached EJB stubs, which are no longer valid. However, when the invocation error occurs, the transport assumes that those stubs are now invalid, and remove them from the cache—in this way, the error is prevented on subsequent attempts to invoke the EJB. To avoid this first-time error, you can reset the JNDI Provider in the Oracle Service Bus Administration Console.