PI 7.4 – Adapter Module Creation using EJB 3.0
Hello,
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 Scenario:
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
runtime.
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.
Hi,
Your blog is very useful.
Just a small suggestion, you don't need to Import Jar files from the server anymore. Rather than using "Add Variable" you can use "Add Library" and select XPI Libraries which includes all the necessary jars.
Thanks,
Pablo
Thanks for the suggestion !!
Verybigthanks
Hi Ujjwal,
If I import these jar files "Add External JAR".. will it not work?
Thanks
Sandeep Maurya.
Hi,
Can we deploy the module externally?. Like the option we have in 7.1, export EAR file -> Convert to .sda and then deploy externally. Do we have it here?. if yes, How would i do it?.
Thanks,
Nisar
Hi Ujjwal,
Thanks for this document.
I tried to import in SAP PO 7.4 (java only) from NWDS 7.31 SP16, but a warning occurs without the correct deployment of the module. Can you help me about it?
It's the log:
Exception has been returned while the [sap.com/FileAdapModuleEAR] was starting. Warning/Exception :[
][ASJ.dpl_ds.006153 Error occurred while starting application [sap.com/FileAdapModuleEAR]: It is not started successfully on server nodes [32754650]. In order to bring the server in consistent state stop operation will be performed.
Error occurred on server 32754650 during startApp of sap.com/FileAdapModuleEAR : com.sap.engine.services.deploy.container.DeploymentException: Cannot load bean class com.sap.module.FileAdapModule for component sap.com/FileAdapModuleEAR*xml|FileAdapModuleEJB.jar*xml|FileAdapModule
at com.sap.engine.services.ejb3.container.ContainerInterfaceImpl$Actions.perform(ContainerInterfaceImpl.java:963)
at com.sap.engine.services.ejb3.container.ContainerInterfaceImpl.prepareStart(ContainerInterfaceImpl.java:462)
...
>>Update: See solution in my next post
Hi all,
Finally I have found the issue: some imagen have a reference to sap.com.modules but in the code example the packet are sap.com.module (also in some images too).
Finally I have found the issue: some images in this ticket have a reference to sap.com.modules but in the code example the reference point to packet sap.com.module (in some images too).
At the end, I deployed the component with a script because from NWDS I have others issues because the previous deploy exist.
Scripts path
/usr/sap/<SID>/J<nr>/j2ee/deployment/scripts
Run the deploy command
deploy.bat <user>:<password>@<host>:<P4 port> <full path to ear file>
Example:
deploy.bat j2ee_admin:password@saphost:50304 /usr/sap/nwds/FileAdapModuleEAR.ear
Thanks for sharing your analysis !
Thank you, this is really helpful.
Thanks for your comments.
Thank you very much for the useful blog,
I followed all the steps that you explained.but while deploying it I am getting the below error. I am trying deploy it with my user ID, So do i need to deploy it with PI admin credential only??. Please help me
Error:
Deploy Exception.ASJ.dpl_dc.001085 Operation [deploy] of [sap.com_FileAdapModuleEAR] failed [ERROR: 4/1/16 6:36 PM /userOut/daView_category (eclipse.UserOutLocation) Thread[Deploy Thread,5,main]]
[#1]: Deployment Items status: [
[INFO: 4/1/16 6:36 PM /userOut/daView_category (eclipse.UserOutLocation) Thread[Deploy Thread,5,main]]
[#1]: Deployment Exception during deployment phase [DeploymentException], cause=[ASJ.dpl_dc.001085 Operation [deploy] of [sap.com_FileAdapModuleEAR] failed] [INFO: 4/1/16 6:36 PM /userOut/daView_category (eclipse.UserOutLocation) Thread[Deploy Thread,5,main]]
[#1]: Deployment of [name: 'FileAdapModuleEAR', vendor: 'sap.com' (sda)] finished. [INFO: 4/1/16 6:36 PM /userOut/daView_category (eclipse.UserOutLocation) Thread[DC_API-ClientSideAsyncNotification#1,5,main]]
snap for reference.
I am using nwds-extsoa-7.3-EHP1-SP06-PAT0015-win32 tool for deployment
Hi Pavan,
You need to open a new thread for this and provide the complete error trace.
Regards,
Praveen.
Hello Praveen,
Thanks for the prompt reply.
I opened the new thread for this.Please let me know if you need any additional details for error trace.
Placing files in multiple folders using single receiver channel
Hi Ujjwal,
Thanks for the nice article.
I did the steps as you mentioned.
I get an error on the receiver cc like below.
The Adapter Message Property Directory was configured as mandatory element, but
was not supplied in the XI Message header
The directory is checked on the receiver cc advance tab. I have also a question which values i have to put for the receiver Target directory and File name scheme in the receiver target tab.
Any suggestions would be appreciated.
Regards,
Antony.
Hi All,
The issue is solved.
PI7.4 Adapter module configuration mandatory element problem.
The test files were not with the correct name like Source1.txt, Source2.txt .......
I changed the file names and it is working fine now.
Regards,
Antony.
Ujjwal,
Great Blog! will this work for PI 7.31 as well?
-Ashish
Hi Ujjwal,
The information you provided was very useful.
Can you please provide the source code for this deployment.I am unable to find the attachment.
Please share for the link source code in the attachment section.
Thanks
Raghu
Hello,
Were you able to get the attachment?
Thanks
HI Ujjwal,
If possible,can you please provide the reference code to my email id : gandhamraghu001@gmail.com
Thanks
Raghu
Hi Ujjwal,
I guess the configuration of the ejb-jar.xml is missing the blog. I tried to deploy the adapter module and was getting error because of that. Once i modified the ejb-jar.xml with the below code, the adapter module worked for me.
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:ejb="http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" version="3.0">
<display-name>
addBOMBean </display-name>
<enterprise-beans>
<session>
<icon/>
<ejb-name>addBOMBean</ejb-name>
<home>com.sap.aii.af.lib.mp.module.ModuleHome</home>
<remote>com.sap.aii.af.lib.mp.module.ModuleRemote</remote>
<local-home>com.sap.aii.af.lib.mp.module.ModuleLocalHome</local-home>
<local>com.sap.aii.af.lib.mp.module.ModuleLocal</local>
<ejb-class>com.sap.module.addBOMBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
Thanks
Shiv
Can you please add ejb-jar.xml?
Can you please provide the source code for this I can not find the attachment section mentioned.
Where is the attachment section? Please point me in the right direction. thanks!
Nice Blog, on how to create a Custom adapter Module.
But for the current requirement, we can directly route using the receiver rules in Interface Determination , using Context Object "fileName"
application-j2ee-engine.xml
Is this the file? This is missing in the blog,
<?xml version="1.0" encoding="UTF-8"?>
<application-j2ee-engine xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="application-j2ee-engine.xsd">
<reference reference-type="hard">
<reference-target target-type="service"
provider-name="sap.com">
engine.security.facade
</reference-target>
</reference>
<reference reference-type="hard">
<reference-target target-type="library">
engine.j2ee14.facade
</reference-target>
</reference>
<reference reference-type="hard">
<reference-target target-type="service">
com.sap.aii.af.svc.facade
</reference-target>
</reference>
<reference reference-type="hard">
<reference-target target-type="interface">
com.sap.aii.af.ifc.facade
</reference-target>
</reference>
<reference reference-type="hard">
<reference-target target-type="library">
com.sap.aii.af.lib.facade
</reference-target>
</reference>
<reference reference-type="hard">
<reference-target target-type="library">
com.sap.base.technology.facade
</reference-target>
</reference>
</application-j2ee-engine>