Introduction:

How to create SAP PI adapter modules in EJB 3.0: We all have worked on creating custom adapter module in various projects at some point. And we have mostly written all our custom modules in EJB(Enterprise Java Bean) 2.1 standard. In this blog, let’s look into few main differences between EJB 2.1 and 3.0 standards and how to develop and deploy your custom modules in EJB 3.0 standard. This document will be more helpful if you have basic knowledge on how to create/develop custom adapter modules in EJB 2.1 standard.

Differences:

Few key differences between EJB 2.1 and EJB 3.0 are

S.No

EJB 2.1

EJB 3.0

1

XML deployment descriptor(ejb-jar.xml) is mandatory

XML deployment descriptor is optional and annotations can be used instead

2

Bean implementation class must implement SessionBean interface

Not required to implement SessionBean interface

3

Bean implementation class must override all bean lifecycle methods  whether you use them or not

Add your own bean lifecycle methods if required using annotations

4

Complex, more work on developers

Simple, less work on developers as container does most of the work.

There are many other differences between EJB2.1 and 3.0, but we are not using them.

Let’s create a simple adapter module in EJB 3.0:

 

To keep the implementation simple our custom adapter module just prints a statement to the audit log.

 

Step 1: Create new EJB project in NWDS

  1. Project name: FileValidation_EJB
  2. EJB module version: 3.0
  3. Add EAR membership: FileValidation_EAR
  4. Click Next

  1. Uncheck option to create EJB client jar
  2. Uncheck Generate ejb-jar.xml deployment descriptor
  3. Click Finish

Step 2: Configure Build Path

  1. Right click on FileValidation_EJB
  2. Select Build Path > Configure Build Path

 

  1. Select Libraries tab
  2. Click in Add Library

 

  1. Select XPI Library
  2. Click Next

 

  1. Select Library Type: XPI Adapter Libraries
  2. Click Finish

 

Step 3: Create a new Session Bean

  1. Right click on FileValidation_EJB
  2. Select New > Session Bean(EJB 3.x)

 

  1. Java package: com.sap.pi
  2. Class name: Validation
  3. State type: Stateless
  4. Uncheck create remote and local business interface
  5. Click Finish

Add below annotations to the Validation class

  1. @Stateless(name=”ValidationBean”)
  2. @Local(value={ModuleLocal.class})
  3. @Remote(value={ModuleRemote.class})
  4. @LocalHome(value=ModuleLocalHome.class)
  5. @RemoteHome(value=ModuleHome.class)

 

Implement Module interface and add bean lifecycle methods using @PostConstruct and @PreDestroy annotations. Bean life cycle methods are optional and can be ignored.

 

Step 4: Provide JNDI name for module

  1. Expand FileValidation_EJB > ejbModule > META-INF
  2. Double click ejb-j2ee-engine.xml
  3. Right click on XML node ejb-j2ee-engine
  4. Select Add Child > enterprise-beans

 

  1. Right click on XML node enterprise-bean
  2. Select Add Child > jndi-name

 

  1. ejb-name: ValidationBean (This should be same as the value specified in @stateless annotation)
  2. jndi-name: SetValidation (This name will be used in the communication channel module tab)
  3. Save the file

 

Step 5: Add standard references to EAR

 

  1. Expand FileValidation_EAR > EarContent > META-INF
  2. Double click application-j2ee-engine.xml
  3. Right click on XML node application-j2ee-engine
  4. Select Add Child > reference

 

  1. Right click on reference-target
  2. Select Add Attribute > provider-name

 

  1. reference-target: engine.security.facade
  2. reference-type: hard
  3. target-type: service
  4. provider-name: sap.com

 

Repeat the steps in step5 and add below references

S.No

Reference-Target

Reference-Type

Target-Type

Provider-Name

1

engine.j2ee14.facade

hard

library

sap.com

2

com.sap.aii.af.svc.facade

hard

service

sap.com

3

com.sap.aii.af.ifc.facade

hard

interface

sap.com

4

com.sap.aii.af.lib.facade

hard

library

sap.com

5

com.sap.base.technology.facade

hard

library

sap.com
  1. Right click on XML node application-j2ee-engine
  2. Select Add Child > fail-over-enable

 

  1. Right click on XML node fail-over-enable
  2. Select Add Attribute > type

 

  1. Right click on the node fail-over-enable
  2. Select Add Attribute > mode

 

  1. xsi:type: fail-over-enableType_disable
  2. mode: disable
  3. Save the file

 

 

Step 6: Deploy EAR into PI Web AS Java

  1. Right click on FileValidation_EAR
  2. Select Export > SAP EAR file

  1. Select a target folder on the local file system
  2. Check Export source files and click Finish

 

Add SAP AS Java instance to NWDS

  1. Window > Preferences > SAP AS Java > Click Add button
  2. Enter your PI system hostname and instance number and click OK

 

Open deployment perspective in NWDS

  1. Select Window > Open Perspective > Other > Deployment
  2. Click OK

 

In Deployment Job view

  1. Click on Import button under Deployment List

 

  1. Select File System
  2. Click Finish and select the EAR file to deploy from local filesystem.

 

  1. Click on Start button to start the deployment
  2. Enter j2ee_admin credentials if prompted

 

The module should get deployed successfully without any errors

 

Step 7: Use module in communication channel and test

 

Use the module in channel

 

 

Audit log

 

 

Note:

  1. EJB3.0 solves the same problems as in EJB2.0 , but EJB3.0 is more developer friendly than EJB2.0
  2. I am using SAP NWDS (Net Weaver Developer Studio) 7.31 SP10, The screenshots in this document may vary depending on NWDS version that you are using.
  3. The perspective that am using in NWDS is Java EE

New NetWeaver Information at SAP.com

Very Helpfull

 

 

User Rating: Be the first one !