Skip to Content
Author's profile photo Ujjwal Kumar

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:

/wp-content/uploads/2014/08/1_513348.png

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.

/wp-content/uploads/2014/08/2_513388.png

Adapter Module Creation Process for SAP PI 7.4:

The configurations and steps required to build adapter module is mentioned in detail below:

  1. Install the latest version of NWDS 7.3 EHP 1. The latest version of NWDS available is NWDS 7.3 EHP1 SP 12.
  2. Use the JDK 1.6.0_07 or higher in NWDS for building the project.
  3. 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:
  4. 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

            /wp-content/uploads/2014/08/3_513463.png
         

              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.

          /wp-content/uploads/2014/08/4_513501.png         

          Uncheck the client interfaces and classes checkbox. Select the “Generate ejb-jar.xml” deployment descriptor checkbox and click on Finish.

          /wp-content/uploads/2014/08/5_513502.png

          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.

          /wp-content/uploads/2014/08/6_513503.png

    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.

      /wp-content/uploads/2014/08/7_516040.png

        Select Library tab and click on Add Variable

    /wp-content/uploads/2014/08/8_516050.png

    Select the JAR Files Folder from machine and click on Extend:

      /wp-content/uploads/2014/08/9_516051.png

    Select all the JAR Files and click on OK.

    /wp-content/uploads/2014/08/10_516052.png

    6.  Adding the Stateless Session bean into the EJB Project:

        Right click on the EJB Project and select New – Session Bean(EJB 3.x)

        /wp-content/uploads/2014/08/11_516067.png

         

          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.

          /wp-content/uploads/2014/08/12_516086.png

        Click on Next and Finish. Session bean will be added in the mentioned package in the EJB Project as shown below:

          /wp-content/uploads/2014/08/13_516087.png

    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.

/wp-content/uploads/2014/08/14_516088.png

   

    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:

    /wp-content/uploads/2014/08/15_516145.png

Maintain ejb-j2ee-engine.xml file as below:

Capture.PNG


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.

    /wp-content/uploads/2014/08/16_516176.png

    Select the EJB Project and Destination as mentioned below:

    /wp-content/uploads/2014/08/17_516178.png

    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.

/wp-content/uploads/2014/08/18_516192.png         

    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.

      /wp-content/uploads/2014/08/19_516204.png

/wp-content/uploads/2014/08/20_516205.png

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.

/wp-content/uploads/2014/08/21_516273.png

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:

/wp-content/uploads/2014/08/22_516274.png

/wp-content/uploads/2014/08/23_516278.png

/wp-content/uploads/2014/08/24_516279.png

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.

Sender File.png

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.

Receiver File.png

  • 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.

/wp-content/uploads/2014/08/26_516305.png

Assigned Tags

      25 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Pablo Lopez
      Pablo Lopez

      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

      Author's profile photo Ujjwal Kumar
      Ujjwal Kumar
      Blog Post Author

      Thanks for the suggestion !!

      Author's profile photo Artem Solohin
      Artem Solohin

      Verybigthanks

      Author's profile photo Sandeep Maurya
      Sandeep Maurya

      Hi Ujjwal,

      If I import these jar files "Add External JAR".. will it not work?

      Thanks

      Sandeep Maurya.

      Author's profile photo Former Member
      Former Member

      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

      Author's profile photo Oscar Navas Serrano
      Oscar Navas Serrano

      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

      Author's profile photo Oscar Navas Serrano
      Oscar Navas Serrano

      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

      Author's profile photo Ujjwal Kumar
      Ujjwal Kumar
      Blog Post Author

      Thanks for sharing your analysis !

      Author's profile photo Mark Dihiansan
      Mark Dihiansan

      Thank you, this is really helpful.

      Author's profile photo Ujjwal Kumar
      Ujjwal Kumar
      Blog Post Author

      Thanks for your comments.

      Author's profile photo Former Member
      Former Member

      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.

      Capture.JPG

      I am using nwds-extsoa-7.3-EHP1-SP06-PAT0015-win32 tool for deployment

      Author's profile photo Praveen Gandepalli
      Praveen Gandepalli

      Hi Pavan,

      You need to open a new thread for this and provide the complete error trace.

      Regards,

      Praveen.

      Author's profile photo Former Member
      Former Member

      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

      Author's profile photo Antony FERMINUS
      Antony FERMINUS

      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.

      Author's profile photo Antony FERMINUS
      Antony FERMINUS

      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.

      Author's profile photo Ashish Goyal
      Ashish Goyal

      Ujjwal,

      Great Blog! will this work for PI 7.31 as well?

      -Ashish

      Author's profile photo Former Member
      Former Member

      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

      Author's profile photo Joe S
      Joe S

      Hello,

      Were you able to get the attachment?

      Thanks

      Author's profile photo Former Member
      Former Member

      HI Ujjwal,

      If possible,can you please provide the reference code to my email id : gandhamraghu001@gmail.com

      Thanks
      Raghu

      Author's profile photo Shivduttsinh Mahida
      Shivduttsinh Mahida

      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

      Author's profile photo Former Member
      Former Member

      Can you please add ejb-jar.xml?

      Author's profile photo Brian Byrne
      Brian Byrne

       

      Can you please provide the source code for this I can not find the attachment section mentioned.

      Author's profile photo Orland Louie Reyes
      Orland Louie Reyes

      Where is the attachment section? Please point me in the right direction. thanks!

      Author's profile photo Manoj Pothuganti
      Manoj Pothuganti

      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"

      Author's profile photo Sathish Venkataraman
      Sathish Venkataraman

       

      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>