Show TOC Start of Content Area

Procedure documentation Using Resource Adapter to Obtain a Connection  Locate the document in its SAP Library structure

Use

Once you have deployed a resource adapter on the AS Java, you can use it to obtain a connection to an EIS. To do that, you need to access a ConnectionFactory instance by performing a lookup operation in the naming system. This operation does not depend on whether the resource adapter is a standalone component or has been deployed as a part of an application. In both cases it is accessible for all other application components – Web components, enterprise beans, or application clients, deployed on the server. You can use a resource adapter deployed with another application by setting a resource reference to this resource adapter.

Using resource references has several purposes:

      Resource references are defined by the Java EE standard. Using them makes your applications portable.

      By specifying a resource reference, you can access connection factories on the AS Java even if they are not deployed with your application.

      Declaring resource references enables you to manage the use of other features, such as connection sharing and authorization.

The mechanism for obtaining a connection depends on the resource authorization that you have specified in the res-auth tag of the deployment descriptor of the application component that uses the resource adapter. If you choose Application authorization, you have to supply credentials (user name, password) in the application code. In case of Container authorization, the Connector Container Service is responsible for the security issues when obtaining a connection.

Prerequisites

To obtain a connection to an EIS from a resource adapter deployed on the AS Java, you must include a resource reference for the connection factory provided by the adapter.

Procedure

Obtaining a Connection

To look up a ConnectionFactory, include the following code in the source of the application component:

       1.      Get initial context:

Example

Context ctx = new InitialContext();

 

       2.      Look up the ConnectionFactory, using the initial context. Note that the ConnectionFactory can be a DataSource, a javax.resource.cci.ConnectionFactory instance, and so on, depending on the interface that is implemented. The ConnectionFactory interface and the relevant implementation class are specified in the standard ra.xml for the resource adapter.

Example

ConnectionFactory cf = ctx.lookup("java:comp/env/<res-ref-name>");

 

       3.      Get a connection using the ConnectionFactory object that you have looked up. The interface and the implementation class for the connection are also defined in the ra.xml file. The type of the connection is arbitrary, depending on the type of the ConnectionFactory object.

Example

Connection conn = cf.getConnection();

 

       4.      After you finish working with the connection, close it explicitly by invoking Connection.close().

Application-Managed Sign-On

The mechanism for obtaining the ConnectionFactory from the naming is the same as in the container-managed scenario.

To obtain a connection in this case, you need to specify a valid user and password for EIS authentication. They are entered as properties:

Example

ConnectionSpecImpl connectionSpec = new ConnectionSpecImpl();

connectionSpec.setUserName("SAPUser");

connectionSpec.setPassword("sap");

javax.resource.cci.Connection conn = cf.getConnection(connectionSpec);

 

 

End of Content Area