PI 7.4 – Adapter Module Creation using EJB 3.0
The below mentioned scenario is very common and an adapter module needs to be implemented for the same.
This example below will also help to build an adapter module in SAP PI 7.4 using EJB 3.0.
The business requirement is to transfer files from one folder to multiple folders on FTP. The files are present in a consolidated manner at source side, it needs to put in different folders at destination side according to the file names.
For this Scenario: Configurations are done in Integration Directory only and no ESR objects are built.
ESR objects are not required as files need to be transferred as it is from one directory to other directory. And there is no message mapping or data processing required. Hence configurations are done directly in the ID which involves Communication channels, Receiver Determination, Interface Determination, Sender Agreement and Receiver Agreement.
The two major components involved in the scenario are:
Sender Communication Channel:
This channel needs to pick multiple files from the source directory. For this either “Advanced Selection for Source File” option in sender communication channel can be used or we can put *.* in File Name to pick all the files from Source Directory.
Advanced Selection for Source File option is shown below:
Receiver Communication Channel:
This channel needs to put the files in different folders on FTP. For a single communication channel to
put the files dynamically in different folders, an adapter Module needs to be developed which will select the Target Directory Name and File Name Scheme at
The Adapter Module FileAdapModule is highlighted below.
Adapter Module Creation Process for SAP PI 7.4:
The configurations and steps required to build adapter module is mentioned in detail below:
- Install the latest version of NWDS 7.3 EHP 1. The latest version of NWDS available is NWDS 7.3 EHP1 SP 12.
- Use the JDK 1.6.0_07 or higher in NWDS for building the project.
- Following JAR files need to be imported from SAP PI system for creating the Adapter Module.The JAR files and their location on PI system is mentioned below:
- EJB Project and Session Bean creation in NWDS: For building an Adapter Module EJB Project needs to be created and stateless session bean needs to be created in the EJB project which holds the business logic.
In NWDS: Go to File – New – EJB Project
Enter the details for EJB as mentioned below and click on Next: Select the EJB Module Version as 3.0 and add it to EAR project.
Uncheck the client interfaces and classes checkbox. Select the “Generate ejb-jar.xml” deployment descriptor checkbox and click on Finish.
An EJB and EAR project will get created as shown below. EJB Project holds the business logic where as EAR Poject is required for deployment.
5. JAR files addition to EJB project: As the Adapter Module needs standard SAP JAR files for compilation, these JAR files need to be added to the EJB project.
Put all the JAR files mentioned in Step 3 in a Folder in your local machine.
Right click on EJB project and select Build Path – Configure Build Path.
Select Library tab and click on Add Variable
Select the JAR Files Folder from machine and click on Extend:
Select all the JAR Files and click on OK.
6. Adding the Stateless Session bean into the EJB Project:
Right click on the EJB Project and select New – Session Bean(EJB 3.x)
Enter the session bean details as mentioned below:
- Enter the Java package and Class names.
- Select the State type as “Stateless”.
- Select the checkboxes for Remote and Local Interfaces.
Click on Next and Finish. Session bean will be added in the mentioned package in the EJB Project as shown below:
Open the FileAdapModule.java file and logic to determine the Directory and File names will be added in this java file. Add one Method ModuleData process (ModuleContext, ModuleData) in the bean as shown below . Reference code is attached in attachment section.
Right click on EJB and Build the Project.
7. In the EJB Project maintain the META-INF Files as mentioned below for correct deployment. The ejb-jar.xml file is attached for reference:
Maintain ejb-j2ee-engine.xml file as below:
8. Exporting the EJB Jar file: The source code and class files of the EJB are stored in JAR file which gets deployed on the J2EE server.
Right click on the EJB Project and select Export – SAP EJB JAR File.
Select the EJB Project and Destination as mentioned below:
9. EAR Project Settings:
This Project holds the EJB project JAR file and has SAP Standard EAR Content in the form of application-j2ee-engine.xml file.
Open the application-j2ee-engine.xml file and put the source code as attached below. Build the EAR Project like EJB Project.
10. Exporting the EAR file for deployment:
- Right click on the EJB Project and select Export – SAP EJB JAR File.
- Select the EAR Project and Destination as mnetioned below.
11. EAR Deployment and Settings: Setting the PI system as the deployment system in NWDS:
- Go to Window – Preferences – SAP AS Java and click on Add.
- Provide the Details and system will be added as shown below.
Deploy the EAR Project on PI system as follows:
- Right click on EAR Project and select Run As – Run on Server.
- Select the PI system on which deployment needs to be done.
- Select the EAR project which needs to be deployed and click Finish.
The steps screenshots are mentioned below:
In the Deployment View Console, the deploymnet status can be checked. The depoyment should take place without any errors.
This is shown in the screenshot below:
12. Communication channel settings:
Sender Communication channel – As source file names need to be picked by the receiver adapter module for selecting the corresponding directory.
In the Sender channel the ASMA attributes – File Name checkbox needs to be checked.
Receiver Communication Channel
The adapter module needs to set the Directory Name and File name dynamically, hence in the ASMA attributes checkbox for File Name and Directory needs to be selected.
- The custom adapter module (identified by JNDI Name mentioned in EJB) needs to be added in the Module tab above the standard SAP Module.
- The Directory path is passed as the parameter to the custom adapter module logic, hence that need to be added in the Module Configuration section as shown below.
- Then Run the scenario and the audit log can be checked in Communication Channel monitoring which will also have traces of custom Adapter Module call.