You are on page 1of 32

Java Connector

Siddhartha Bhattacharya
SAP Java Resource Adapter Overview

Contents:
z J2EE Connector Architecture Overview
z SAP Java Resource Adapter Overview
z Installing SAP Resource Adapter using Deploy Tool
z Programming model of the SAP Resource Adapter

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector


SAP Java Resource Adapter : Unit Objectives

After completing this unit, you will be able to:


z Know what a JCA Resource Adapter is
z Understand the SAP Resource Adapter
z Know how to install the SAP Resource Adapter
z Learn how to program using the SAP resource
adapter

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector


JCA (J2EE Connector Architecture) : Topic Objectives

After completing this session, you will be able to:


z Understand the J2EE Connector Architecture.

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector


JCA (J2EE Connector Architecture)

z Standard architecture for the communication between the J2EE platform


platform
and heterogeneous non-
non-Java application systems.
z A resource adapter based on the J2EE Connector Architecture can be
developed by any vendor of application systems, thus implementing
implementing the
standard interfaces.
z SAP offers the SAP Java Resource Adapter (SAP JRA) for this purpose
purpose

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector


JCA (J2EE Connector Architecture)

Architecture

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector

„ For seamless integration with an application server, a resource adapter must abide by guidelines -- known
as system-level contracts -- that are defined by the Connector Architecture. These contracts exist between
the application server and an EIS, and are implemented through the resource adapter. They specify how a
system external to the J2EE platform can integrate with it by supporting basic functions that are handled
by the J2EE container. The most important functions are those involved with connection management,
transaction management, security, message inflow, work management, and lifecycle management
JCA (J2EE Connector Architecture)

What are the different system level contracts that any JCA
compliant adapter must follow ?

„ Connection Management Contract:


Contract: Lets applications connect to an
EIS through the resource adapter. It also allows the application server
to pool connection requests to the EIS.
„ Transaction Management Contract:
Contract: Allows an application to
manage and perform transactional access across one-one-to-
to-many EIS
resource managers.
„ Security Contract:
Contract: Provides support for secure access to the EIS.

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector


JCA (J2EE Connector Architecture) : Topic Summary

You should now be able to :


z Understand the J2EE Connector Architecture.

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector


SAP Java Resource Adapter : Topic Objectives

After completing the next session, you will be able to:


z Understand the SAP Java Resource Adapter.

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector


SAP Java Resource Adapter

SAP Java Resource Adapter...

„ Is a Resource Adapter for SAP R/3.


„ Implemented according to JCA version 1.0
„ Is a wrapper for Java Connector 2.0
„ Allows remote function call to SAP using native RFC over
TCP/IP

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector


SAP Java Resource Adapter

Architecture

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector


SAP Java Resource Adapter

The SAP Resource Adapter provides the


implementation from two packages

„ javax.resource.cci – This part of the API enables the


client-side connectivity to the EIS.
„ javax.resource.spi – This part of the API enables the
server to create the physical connection to the EIS and to
access the system level contracts.

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector


SAP Java Resource Adapter

SAP Java Resource Adapter limitations

„ No Support for 2 phase commit


„ No Support for inbound calls
„ No Support for re-authentication

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector

„ 2 phase commit and re-authentication of connections is not supported by SAP R/3 so they are not
supported by SAP JRA.
SAP Java Resource Adapter

SAP Java Resource Adapter future release plans to...

„ Implement the Resource Adapter using the JCA 1.5


specification
„ Support for inbound calls

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector


SAP Java Resource Adapter : Topic Summary

You should now be able to :


z Understand the SAP Java Resource Adapter.

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector


Installing SAP Resource Adapter : Topic Objectives

After completing the next session, you will be able to:


z Install the SAP Resource Adapter using the Deploy
tool.

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector


Installing SAP Resource Adapter

Installing the SAP Java Resource Adapter

„ The Resource Adapter is available for download as a .rar


file from http://service.sap.com/connectors
„ This .rar file has to be deployed on the Web Application
Server via the deploy tool.

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector

„ Link to download SAP JRA is http://service.sap.com/connectors -> SAP Java Connector ->Tools and
Services -> SAP Java Resource Adapter
Installing SAP Resource Adapter

Installing the SAP Java Resource Adapter using Deploy Tool

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector

„ Start Deploy Tool – Create a new project.


„ Go to Deploy tab and choose Deploy -> EAR -> Load Module
„ Select the .rar file
„ Edit the Server configuration ( server name, host no., user, password, system no)
„ Click on Deploy-> Deployment-> Deploy module
„ Connects to the WAS J2EE and deploys the Resource Adapter on to the application server.
Installing SAP Resource Adapter

Installing the SAP Java Resource Adapter using Deploy Tool

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector

„ Link to download SAP JRA is http://service.sap.com/connectors -> SAP Java Connector ->Tools and
Services -> SAP Java Resource Adapter
Installing SAP Resource Adapter : Topic Summary

You should now be able to :


z Install the SAP Java Resource Adapter using the
deploy tool.

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector


Programming Model : Topic Objectives

After completing the next session, you will be able to:


z Program using the Common Client API.

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector


Programming Model : Common Client Interface

The CCI provides the access from J2EE clients, such as enterprise
beans, Java Server Pages (JSP) technology, and servlets, to an
underlying enterprise information system (EIS).

These are the Java classes defined in the CCI and some of the
more important methods

• ConnectionFactory Establishes a connection instance with EIS

• getConnection() creates a Connection instance (managed by


either a container or a component)

• getRecordFactory() creates a RecordFactory instance

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector

Methods are in green.


Class description is followed by method description in them.
Programming Model : Common Client Interface

• Connection Represents a connection (using the resource


adapter) to an EIS

• createInteraction() creates an Interaction object so that


database operations can be performed

• ConnectionSpec Defines user name, password, and other


properties in a connection request; serves as properties parameter

• getLocalTransaction() creates a LocalTransaction object

• close() closes a connection to EIS

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector


Programming Model : Common Client Interface

• Interaction Creates an interaction with the connected EIS


execute invokes procedures stored in an EIS for performing database
operations

• InteractionSpec Defines an interaction with the connected EIS,


including schema, catalog, and stored function names

• RecordFactory Creates Record object

• createIndexedRecord() creates an ordered collection of Record


instances

• createMappedRecord() creates a collection of Record instances


ordered by key-value pairs

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector


Programming Model : Common Client Interface

• createResultSet() creates a collection of Record instances as a


result set of tabular data

• Record Superclass for Record instances

• add() adds data to input record

• LocalTransaction Establishes a context for a local transaction

• begin() starts a database transaction

• commit() completes an atomic database transaction

• rollback() cancels transaction, returning database to initial state

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector


Programming Model : Getting a Connection

Getting a Connection
„ Assume that the name “eis/SAPJRAFactory” is already refined in the
web.xml deployment descriptor. The first step is to lookup the
ConnectionFactory by this JNDI name.
„ Next step is to create a Connection object using the ConnectionFactory
method getConnection()

//Step 1. Obtain the initial JNDI context

ctx = new InitialContext();

// Step 2. Look up for ConnectinFactory

connectionfactory = (ConnectionFactory)

ctx.lookup("java:comp/env/eis/SAPJRAFactory");

// Step 3. Get Connection

connection = connectionfactory.getConnection();

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector

„ The JNDI name “eis/SAPJRAFactory” actually resolves to the runtime SAP JRA
Connection Factory.
Programming Model : Create RecordFactory and Interaction

Creating a Record factory and Interaction


„ A Recordfactory is needed to create a Record Object. An interaction is needed
to create a connection to the EIS.

// Step 4. Create a record factory

RecordFactory recordfactory =
connectionfactory.getRecordFactory();

// Step 5. Create Interaction

Interaction interaction =
connection.createInteraction();

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector


Programming Model : Execute the function module

Execute the function module


„ The SAP R/3 function module name is specified and the remote function call is
made. The output of the function call is stored in the ResultSet.

//Step 6. Call the R/3 function module


//BAPI_COMPANYCODE_GETLIST

MappedRecord input =
connectionfactory.getRecordFactory().createMappedRecord("
BAPI_COMPANYCODE_GETLIST");

MappedRecord output = (MappedRecord)


interaction.execute(null, input);

ResultSet list = (ResultSet)


output.get("COMPANYCODE_LIST");

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector

„ interaction.execute (null, input) is the remote function call.


Programming Model : Displaying Results

Display the Details in Tabular Format


„ Iterate on the Resultset and display the results in the form of a HTML Table.

//Step 7. Display the list in tabular format

out.println ( "<table border=1><tr><td><b>Company


Code</b></td><td><b>Company Name<b></td></tr>");

while( list.next())

out.println("<tr><td>" + list.getObject(1).toString()
+"</td><td>"+list.getObject(2).toString()+
"</td></tr>");

out.println ( "</table>");

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector

„ list.next() moves to the next object in the list


„ list.getObject(1) gets the first column value for the current row. This value could also be retrieved using
the name of the column (“COMP_CODE”)
Programming Model : Closing the Connection

Closing the connection


„ After the remote call the interaction should be closed using the close()
method on interaction.

// Step 8. Release interaction

interaction.close();

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector

„ The Resultset contains a list of Company codes and Company names.


Programming model : Topic Summary

You should now be able to :


z Program using the Common Client API.

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector


SAP Java Resource Adapter : Unit Objectives

You should now be able to:


z Understand what a JCA Resource Adapter is
z Understand the SAP Resource Adapter
z Know how to install the SAP Resource Adapter
z Learn how to program using the SAP resource
adapter

© SAP AG 2004 / Siddhartha Bhattacharya / Java Connector

You might also like