Skip to Content

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

To report this post you need to login first.

21 Comments

You must be Logged on to comment or reply to a post.

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

    (1) 
  2. Nisar Kavungal

    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

    (0) 
  3. 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

    (0) 
    1. 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

      (0) 
  4. Otto Frost

    Thanks for a good blog.

    How do you add security to the ae module? It should only be possible to start the module from the module chain. By default the ae module is open for RPC and any user can call the ae module. If you have databse calls or access the keystore you probably want to limit access.

    (0) 
  5. PAVAN Y

    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

    (0) 
  6. 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.

    (0) 
  7. Raghu gandham

    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

    (2) 
  8. 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

    (0) 

Leave a Reply