Chapter 4
Configuration

Hibersap configuration consists of a set of properties. There are two possibilities to configure Hibersap:

While bootstrapping, Hibersap first tries to configure itself looking for the /META-INF/hibersap.xml file in the classpath. When creating a SessionManager, configuration can be set or overwritten using programmatic configuration.

Using an XML file is the preferred way to configure Hibersap.

4.1 XML file configuration

The format of the XML configuration file is heavily inspired by JPA’s persistence.xml. If you have to access different SAP systems, you can define more than one SessionManager by multiplying the session-manager XML element.

<?xml version=1.0 encoding=UTF-8?> 
<hibersap xmlns=urn:hibersap:hibersap-configuration:1.0> 
  <session-manager name=A12> 
    <context>org.hibersap.execution.jco.JCAContext</context> 
 
    <jca-connection-factory>java:/eis/sap/A12</jca-connection-factory> 
    <jca-connectionspec-factory> 
      org.hibersap.execution.jca.cci.SapBapiJcaAdapterConnectionSpecFactory 
    </jca-connectionspec-factory> 
 
    <properties> 
      <property name=jco.client.client value=800 /> 
      <property name=jco.client.user value=sapuser /> 
      <property name=jco.client.passwd value=password /> 
      <property name=jco.client.lang value=en /> 
      <property name=jco.client.ashost value=10.20.80.76 /> 
      <property name=jco.client.sysnr value=00 /> 
    </properties> 
 
    <annotatedClasses> 
      <class>org.hibersap.examples.flightlist.FlightListBapi</class> 
      <class>org.hibersap.examples.flightdetail.FlightDetailBapi</class> 
    </annotatedClasses> 
 
    <interceptorClasses> 
      <class>com.mypackage.MyHibersapInterceptor</class> 
    <interceptorClasses> 
  </session-manager> 
</hibersap>
Listing 4.1: hibersap.xml

Table 4.1 shows a list of the configuration parameters.


Parameter Description
context The fully qualified class name of the Context class. This class must implement org.hibersap.session.Context and acts as a facade to the actually used interfacing technology. Existing implementations are org.hibersap.execution.jco.JCoContext for the SAP Java Connector (JCo) or org.hibersap.execution.jca.JCAContext for a JCA compatible Resource Adapter. (Default: JCoContext.)
jca-connection-factory The JNDI name of the JCA Connection Factory. This parameter has to be specified if the application uses a JCA compatible resource adapter. The resource adapter has to be deployed on the application server independently from Hibersap and the application, defining a JNDI name. Hibersap will use this name to look up the resource adapter’s ConnectionFactory.
jca-connectionspec-factory The fully qualified class name of the ConnectionSpecFactory implementation used to get a ConnectionSpec object. A ConnectionSpec is is used to provide data such as a user name and password for the current session. An existing implementation is SapBapiJcaAdapterConnectionSpecFactory.
properties Zero or more additional properties. These depend on the interfacing technology in use. For the SAP JCo, all the JCo-specific properties must be defined here.
annotatedClasses All annotated BAPI classes which are used with the SessionManager must be listed here.
interceptorClasses A list of the interceptor classes. These must implement org.hibersap.session.ExecutionInterceptor and are called before and after a SAP function module gets executed.

Table 4.1: Hibersap configuration parameters

To build a SessionManager using the hibersap.xml file, you simply have to create an object of class org.hibersap.configuration.AnnotationConfiguration, specifying the SessionManager name as an argument. Note that there is also a default constructor for AnnotationConfiguration which can be used if there is only one configured SessionManager. Hibersap will issue a warning when there are more than one SessionManagers configured, but the no-args constructor is used.

AnnotationConfiguration configuration= new AnnotationConfiguration(A12); 
SessionManager sessionManager = configuration.buildSessionManager();

4.2 Programmatic configuration

After creating a Configuration object which will be used to build the SessionManager, configuration can be set or overwritten programmatically.

The information from the XML file is internally converted into a Java data structure reflecting the structure of the XML document. All configuration classes have Java Bean style accessor methods (get.. and set..) for their fields.

For programmatic configuration you have to change or create SessionManagerConfig for each SessionManager you want to use. You can use method chaining to build the object. The following example creates a SessionManagerConfig object that is equal to the one created internally by the hibersap.xml example in section 4.1.

SessionManagerConfig cfg = new SessionManagerConfig( A12 ) 
    .setContext( JCoContext.class.getName() ) 
    .setJcaConnectionFactory( java:/eis/sap/A12 ) 
    .setJcaConnectionSpecFactory( org.hibersap.execution.jca.cci. 
                              + SapBapiJcaAdapterConnectionSpecFactory ) 
    .setProperty( jco.client.client, 800 ) 
    .setProperty( jco.client.user, sapuser ) 
    .setProperty( jco.client.passwd, password ) 
    .setProperty( jco.client.lang, en ) 
    .setProperty( jco.client.ashost, 10.20.80.76 ) 
    .setProperty( jco.client.sysnr, 00 ) 
    .addAnnotatedClass( FlightListBapi.class ) 
    .addAnnotatedClass( FlightDetailBapi.class ) 
    .addInterceptor( MyHibersapInterceptor.class ); 
 
AnnotationConfiguration configuration = new AnnotationConfiguration(cfg); 
SessionManager sessionManager = configuration.buildSessionManager();
Listing 4.2: Programmatic configuration