Skip to Content
Author's profile photo Anand V D

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.


Few key differences between EJB 2.1 and EJB 3.0 are


EJB 2.1

EJB 3.0


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

XML deployment descriptor is optional and annotations can be used instead


Bean implementation class must implement SessionBean interface

Not required to implement SessionBean interface


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


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

new ejb proj.jpg

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

new ejb proj2.jpg

Step 2: Configure Build Path

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

new ejb proj3.jpg

  1. Select Libraries tab
  2. Click in Add Library

new ejb proj4.jpg

  1. Select XPI Library
  2. Click Next

new ejb proj5.jpg

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

new ejb proj6.jpg

Step 3: Create a new Session Bean

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

new ejb proj7.jpg

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

new ejb proj8.jpg

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)

new ejb proj9.jpg

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

new ejb proj10.jpg

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

new ejb proj11.jpg

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

new ejb proj13.jpg

  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

new ejb proj14.jpg

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

new ejb proj15.jpg

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

new ejb proj16.jpg

  1. reference-target:
  2. reference-type: hard
  3. target-type: service
  4. provider-name:

new ejb proj17.jpg

Repeat the steps in step5 and add below references






















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

new ejb proj18.jpg

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

new ejb proj19.jpg

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

new ejb proj20.jpg

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

new ejb proj21.jpg

Step 6: Deploy EAR into PI Web AS Java

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

new ejb proj22.jpg

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

new ejb proj23.jpg

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

new ejb proj24.jpg

Open deployment perspective in NWDS

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

new ejb proj25.jpg

In Deployment Job view

  1. Click on Import button under Deployment List

new ejb proj26.jpg

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

new ejb proj27.jpg

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

new ejb proj28.jpg

The module should get deployed successfully without any errors

new ejb proj29.jpg

Step 7: Use module in communication channel and test

Use the module in channel

new ejb proj31.jpg

Audit log

new ejb proj30.jpg


  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

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Anupam Ghosh
      Anupam Ghosh

      Awesome Anand. Thank you for posting such an informative blog. 🙂

      Author's profile photo Former Member
      Former Member

      Hi Anand,

      This is just what I was after. The explanation given are really handy.

      Thanks  for sharing.



      Author's profile photo sungtae bang
      sungtae bang

      The information provided by you became great help to me.

      Thank you

      Author's profile photo vishal jain
      vishal jain

      Hi Anand,

      By referring to this blog I was trying to build an Adapter module.

      I was able to successfully deploy it on my PI server but I am getting below error while its execution. Can you please advise?

      Error: java.lang.NullPointerException: while trying to invoke the method of a null object loaded from the second parameter of the method



      Author's profile photo Anand V D
      Anand V D
      Blog Post Author

      Hi Vishal,

      The module that is created in the blog is bare skeleton. If you are getting exception in your module in run-time, then probably the exception is from your business logic.

      So double check your business logic in process method or share it here.



      Author's profile photo vishal jain
      vishal jain

      Hi Anand,

      You are correct, the issue was in my code.

      It is fixed now, thanks for help 🙂



      Author's profile photo Former Member
      Former Member

      I'm also getting a null pointer exception that the inputModuleData object is null when I call the getPrincipleData() method.  Do you recall what you changed or what the specific issue was that corrected this error?



      Author's profile photo Eng Swee Yeoh
      Eng Swee Yeoh

      Hi Craig

      Welcome to SCN.

      As you are new to SCN, please take some time to read The SCN Rules of Engagement

      Please note that if you have an issue, please raise this as a discussion thread. Using the comment section of the blog is not the appropriate place for this. In your own thread, in order to get valuable assistance, please provide as much details as possible about your issue (config, coding, error logs, etc).


      Eng Swee

      Author's profile photo Anand V D
      Anand V D
      Blog Post Author

      Hi Craig,

      I have checked the SAP Javadocs and there is no change that i could find in moduledata class.

      As Eng Swee suggested may be you should open a new discussion thread with details like code snippet, screenshot etc so that others also help you.