Skip to Content

I am writing this Scenario as I found it difficult to get the information for the Sender & Receiver Module configuration for the EAR deployed. Then by Trial & Hit process, I was able to get the solution :-). Audit Log is really helpful to trace the data flow along with the output result. This Scenario would give the overall information about the J2EE Adapter Module Development & Sender/Receiver Module Configuration. 

To give details on Adapter Development, I have taken a Sample Scenario which explains about the data flow between a Legacy System to a Third Party System via SAP XI. Legacy System would put data in MQ System. This data is in Text format which would be converted to XML format as XI understands it. In SAP XI, relevant mapping is executed and the target XML message has to be sent to Third party System in Text format via MQ System. So Receiver & Sender Adapters would be JMS Adapter. As the data is dynamic, we had to develop a JAVA module which converts the data format from Text to XML & vice-versa to meet the requirement.

!https://weblogs.sdn.sap.com/weblogs/images/251827888/A1.JPG|height=222|alt=image|width=554|src=https://weblogs.sdn.sap.com/weblogs/images/251827888/A1.JPG|border=0

 Prerequisites: 

1)      SLD should be configured.

 

Topics covered in this Scenario are:

  1)      Adapter Module Development (Referred from How to..Create modules for the J2EE Adapter engine).

2)      Module configuration of Sender & Receiver Adapters in ID for the EAR deployed.

  Following are steps of the Scenario.

   We’ll focus on J2EE Adapter Module Development & Module Configuration.

  1) Download the libraries for XI from SAP Service Marketplace.

 

2) Open the downloaded file using WinZip and extract

0.1.

aii_af_lib.sda0.1.

*aii_af_svc.sda </li><li>aii_af_cpa_svc.sda*.

 A) Open the above file *aii_af_lib.sda using WinZip and extract the following library    </p><p>   files:</p><ul><li>aii_af_cci.jar</li><li>aii_af_mp.jar</li><li>aii_af_ms_api.jar</li><li>aii_af_ms_spi.jar</li><li>aii_af_trace.jar*

B) Extract the following library file from aii_af_svc.sda:  

0.1.

aii_af_svc.jar* *

C) Extract the following library file from aii_af_cpa_svc.sda:  

0.1.

aii_af_cpa.jar  1)      Steps to be followed in SAP Net Weaver Developer Studio

0.1. Open SAP Net Weaver Developer Studio.

0.2.

Create a new Project as J2EE -> EJB Module.0.1. Choose Project -> Properties -> Java Build Path -> Libraries to assign the libraries to your project.

0.2. Create a package for your Java classes.    

!https://weblogs.sdn.sap.com/weblogs/images/251827888/A2.JPG|height=293|alt=image|width=581|src=https://weblogs.sdn.sap.com/weblogs/images/251827888/A2.JPG|border=0

 !https://weblogs.sdn.sap.com/weblogs/images/251827888/A3.JPG|height=259|alt=image|width=503|src=https://weblogs.sdn.sap.com/weblogs/images/251827888/A3.JPG|border=0!

Your J2EE Explorer view in Developer Studio should look as follows:   

!https://weblogs.sdn.sap.com/weblogs/images/251827888/A4.JPG|height=140|alt=image|width=243|src=https://weblogs.sdn.sap.com/weblogs/images/251827888/A4.JPG|border=0

Creating the Sample Java Class

 

<u>Functionality:</u> Conversion of data format from XML to Text.

I’ll be showing you sample Java Class with the above functionality. The Source code can be written as per the Requirement.

<u>Note:</u> SAX or DOM Parser can be used to build an XML file.(Not included in this Scenario)* ** </p><p>package com.demo.moduledevelopment;</p><p>//Classes for EJB<br />import javax.ejb.CreateException;<br />import javax.ejb.SessionBean;<br />import javax.ejb.SessionContext;</p><p>//Classes for Module development<br />import com.sap.aii.af.mp.module.Module;<br />import com.sap.aii.af.mp.module.ModuleContext;<br />import com.sap.aii.af.mp.module.ModuleData;<br />import com.sap.aii.af.mp.module.ModuleException;<br />import com.sap.aii.af.ra.ms.api.Message;<br />import com.sap.aii.af.ra.ms.api.MessageDirection;<br />import com.sap.aii.af.ra.ms.api.XMLPayload;<br />import com.sap.aii.af.service.auditlog.Audit;<br />import com.sap.aii.af.service.auditlog.AuditDirection;<br />import com.sap.aii.af.service.auditlog.AuditLogStatus;<br />import com.sap.aii.af.service.auditlog.AuditMessageKey;</p><p>/*

 

  • @author Ganesh Karicharla

 *

 

  • This XmlToText Class reads the XML Content &

 

  • converts it into Text Content.

 

  • Then the resultant data is put into ModuleData

 /</p><p>/*

 

  • @ejbHome <{com.sap.aii.af.mp.module.ModuleHome}>

 

  • @ejbLocal <{com.sap.aii.af.mp.module.ModuleLocal}>

 

  • @ejbLocalHome <{com.sap.aii.af.mp.module.ModuleLocalHome}>

 

  • @ejbRemote <{com.sap.aii.af.mp.module.ModuleRemote}>

 

  • @stateless

 /</p><p>public class XmlToText implements SessionBean, Module{<br />  <br /> private SessionContext myContext;<br /> AuditMessageKey amk;<br />      <br /> public void ejbRemove() {<br /> }<br />  <br /> public void ejbActivate() {<br /> }<br />  <br /> public void ejbPassivate() {<br /> }<br />  <br /> public void setSessionContext(SessionContext context) {<br />    myContext = context;<br /> }<br />  <br /> public void ejbCreate() throws CreateException {<br /> }<br />    <br />    public ModuleData process(ModuleContext moduleContext,<br />        ModuleData inputModuleData)<br />    throws ModuleException {<br /> <br />     //Handler to get Message object<br />        Message msg = null;</p><p>        try { <br />   //Fetch the PrincipalData<br />      msg = (Message)inputModuleData.getPrincipalData();<br />         <br />      if (msg.getMessageDirection() <br />        == MessageDirection.INBOUND)<br />       amk = new AuditMessageKey(msg.getMessageId(),<br />                AuditDirection.INBOUND);<br />   else<br />    amk = new AuditMessageKey(msg.getMessageId(),<br />      AuditDirection.OUTBOUND);<br />     <br />   XMLPayload xmlpayload = msg.getDocument();</p><p>   Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,<br />     “AO: Now got the xml payload object.”);<br />   <br />   String xmltxt = xmlpayload.getText();<br />   String convertedtext = swiftRead(xmltxt);<br />  <br />   Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,<br />     “AO: Value returned after calling swiftRead:”);</p><p>   xmlpayload.setText(convertedtext);<br />   inputModuleData.setPrincipalData(msg);<br />  <br />   Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,<br />     “AO: Text put into inputModuleData”);</p><p>        } catch (Exception e) {<br />   Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,<br />     “AO: Module Exception caught:”);<br />            ModuleException me = new ModuleException(e);<br />            throw me;<br />     }<br />  return inputModuleData;</p><p> }</p><p> /*

 

  • @param messageStr

 

  • @return strSwiftmesstext

 

  • @throws exception

  /<br /> private String swiftRead(String messageStr)<br />   throws Exception<br /> {</p><p>  int msgStart;<br />  int msgEnd;<br />  String strSwiftmesstext=null;<br />    <br />        try {<br />      if(null!=messageStr && !(“”.equals(messageStr))){ <br />    msgStart = messageStr.indexOf(XMLConstants.SWIFTMSG_STARTTAG);<br />    msgEnd = messageStr.indexOf(XMLConstants.SWIFTMSG_ENDTAG);<br />    //Fetch substring of swiftmesstext<br />    strSwiftmesstext = messageStr.substring(msgStart+14,<br />              msgEnd);<br />    strSwiftmesstext = strSwiftmesstext.replaceAll(<br />               XMLConstants.LESSTHAN,<br />               XMLConstants.LESSTHANSYM);<br />    <br />      <br />    Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,<br />         “Xml converted to Text: “);<br />   }<br />  }catch(StringIndexOutOfBoundsException strob){<br />      strob.printStackTrace();<br />   Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,<br />      “StringIndexOutOfBoundsException Caught: “);<br />  }catch(Exception e){<br />      e.printStackTrace();<br />   Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,<br />      “Generic Exception Caught: “);<br />  }<br />  return strSwiftmesstext;<br /> }<br />}</p><p>package com.demo.moduledevelopment;</p><p>/*

 

  • @author Ganesh Karicharla

 *

 

  • This XMLConstants Class declares all Constants

 

  • which will be used in AdapterModule development.

 

 /</p><p>public class XMLConstants {<br /> <br /> public XMLConstants(){<br />  <br /> } <br /> public static final String LESSTHAN = “<“;<br /> public static final String LESSTHANSYM = “<“;<br /> public static final String GREATERTHAN  = “>”;<br /> public static final String GREATERTHANSYM  = “>”;<br /> public static final String AMPERSAND  = “&”;<br /> public static final String AMPERSANDSYM  = “&”;<br /> public static final String QUOTATION = “””;<br /> public static final String QUOTATIONSYM = “””; <br /> public static final String APOSTOPHIE = “&apos;”;<br /> public static final String APOSTOPHIESYM = “‘”;<br /> public static final String SWIFTMSG_STARTTAG = “<SWIFTMESSAGE>”;<br /> public static final String SWIFTMSG_ENDTAG = “</SWIFTMESSAGE>”;<br /> <br />}<br /> </p><p>Comment lines such as @ejbHome are required to enable the Developer Studio to create the ebj-jar.xml file automatically. </p><p style=”margin: 0in 0in 0pt” class=”MsoNormal”>_Providing the EJB Environment_ :</p><p style=”margin: 0in 0in 0pt” class=”MsoNormal”> </p><p style=”margin: 0in 0in 0pt 9pt; text-indent: -9pt” class=”MsoNormal”>The Java class developed should appear in the navigation tree under EJB Candidates. In the context menu, choose Add to ejb-jar.xml.</p><p style=”margin: 0in 0in 0pt 9pt; text-indent: -9pt” class=”MsoNormal”> </p><p style=”margin: 0in 0in 0pt 9pt; text-indent: -9pt” class=”MsoNormal”>+ +ejb-jar.xml should look as follows: </p><p style=”margin: 0in 0in 0pt 9pt; text-indent: -9pt” class=”MsoNormal”> </p><p style=”margin: 0in 0in 0pt 9pt; text-indent: -9pt” class=”MsoNormal”><?xml version=”1.0″ encoding=”UTF-8″?><br /><!DOCTYPE ejb-jar PUBLIC “-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans<br />2.0//EN”<br />”http://java.sun.com/dtd/ejb-jar_2_0.dtd“><br /><ejb-jar><br /><description>EJB JAR description</description><br /><display-name>EJB JAR</display-name><br /><enterprise-beans><br /><session><br /><ejb-name>DemoBean</ejb-name><br /><home>com.sap.aii.af.mp.module.ModuleHome</home><br /><remote>com.sap.aii.af.mp.module.ModuleRemote</remote><br /><local-home>com.sap.aii.af.mp.module.ModuleLocalHome</local-home><br /><local>com.sap.aii.af.mp.module.ModuleLocal</local><br /><ejb-class>sample.CreateAttachment</ejb-class><br /><session-type>Stateless</session-type><br /><transaction-type>Container</transaction-type><br /></session><br /></enterprise-beans><br /></ejb-jar></p><p>JNDI name should be assigned in ejb-j2ee-engine.xml. This name is required for the configuration of the module. An example of this is the following:</p><p><?xml version=”1.0″ encoding=”UTF-8″?><br /><!DOCTYPE ejb-j2ee-engine SYSTEM “ejb-j2ee-engine.dtd”><br /><ejb-j2ee-engine><br /><enterprise-beans><br /><enterprise-bean><br /><ejb-name>DemoBean</ejb-name><br /><jndi-name>DemoBean</jndi-name><br /><session-props/><br /></enterprise-bean><br /></enterprise-beans><br /></ejb-j2ee-engine></p><p>After setting up the EJB environment, you receive the error message: Bean problem: No interface classes found. This occurs because there is no Java source available for the EJB interface classes. </p><ul><li><div class=”MsoNormal” style=”margin: 0in 0in 0pt 0.5in; text-indent: -0.5in”>Choose the Package Explorer view in the Developer Studio. </div></li><li><div class=”MsoNormal” style=”margin: 0in 0in 0pt 0.25in; text-indent: -0.25in”>Choose your project, and in the context menu, choose Close Project. </div></li><li><div class=”MsoNormal” style=”margin: 0in 0in 0pt 0.5in; text-indent: -0.5in”>Choose Open Project again.</div></li><li><div class=”MsoNormal” style=”margin: 0in 0in 0pt 0.5in; text-indent: -0.5in”>Finally, switch back to the J2EE Explorer view. *h5. Module configuration of Sender & Receiver Adapters in ID. 

I.Integration Repository: 

IR is configured as per the requirement. Data type should be created as per the Data Structure received in SAP XI.

  Following is the Sample Mapping structure that is configured in XI where the Data structure has three fields.

    

  image

 

Going ahead with ID Configuration with the assumption that all the objects in IR are created and activated.

 

II. ID: Configuration  

1)      Create a Configuration Scenario CS_MT_PAYMENT

2)      Add Business System i.e., Sys_DWebSphere to the Configuration Scenario.

 

 *A)    *SENDER COMMUNICATION CHANNEL: 

  • Communication Channel: CC_MT_PAYMENT_Server.

Following fields have to filled in Parameters tab:        mentioned while creating an .ear file) value in the second line after 

      SAP XI JMS Adapter/ConvertJMSMessageToBinary.

    8. * Module Type *is Remote Enterprise Bean.

*     *9. *Module Key *can be any value.

  !https://weblogs.sdn.sap.com/weblogs/images/251827888/A8.JPG|height=384|alt=image|width=578|src=https://weblogs.sdn.sap.com/weblogs/images/251827888/A8.JPG|border=0

  We are done with Sender Adapter Module Configuration. This configuration would process the Java code embedded in the above created *.ear *file. As per our Scenario, it would convert data format from Text to XML.

 

  *B)    *RECEIVER COMMUNICATION CHANNEL:  

1)   Assign the Receiver Business System configured in SLD to the corresponding

     Configuration Scenario.

2)  Receiver Communication Channel has to be created which will transfer the 

     data from SAP XI to MQ System.

3)  Communication Channel: CC_MT_POST_Client

4)  Select Receiver option.

5)  Fill all the field parameters which are necessary to configure JMS receiver adapter 

     under Parameters tab as we are not focusing on those details.    mentioned while creating an .ear file) value in the first line before

SAP XI JMS Adapter/ConvertJMSMessageToBinary.

9)*   Module Type *is Remote Enterprise Bean.

10) *Module Key *can be any value.

   !https://weblogs.sdn.sap.com/weblogs/images/251827888/A10.JPG|height=386|alt=image|width=581|src=https://weblogs.sdn.sap.com/weblogs/images/251827888/A10.JPG|border=0!</body>

To report this post you need to login first.

6 Comments

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

  1. Amit Kumar Singh
    Hi Ganesh,

    Good it seems u are really working hard.Could you please provide some information as to what is new in this blog when HOWTO guide on adapter module development is already available and which probably you might also have used in ur blog for reference?

    Regards

    (0) 
    1. Ganesh Karicharla Post author
      Hi Amit,

      Thanks for going through the blog.

      The points that I wanted to metion are:

      1) Using of Audit log which would help us to trace the data flow in the RWB–> Communication Channel. (Which is not mentioned in How To..guide)

      2)Adapter module Configuration in ID for both Sender & Receiver.

      So to consolidate the above two points, I have given the overall scenario as an example.

      Thanks,
      Ganesh Karicharla

      (0) 
      1. Michal Krawczyk
        hi Ganesh,

        >>>>1) Using of Audit log which would help us to trace the data flow in the RWB–> Communication Channel. (Which is not mentioned in How To..guide)

        both types of logging are covered in Stefan’s Grube article about adapter module devepment:
        https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e21106cc-0c01-0010-db95-dbfc0ffd83b3

        but if you didn’t find it maybe it was worth to
        put this blog with the same info, don’t know

        Regards,
        Michal

        (0) 
        1. Ganesh Karicharla Post author
          Hi Michal,

          Thanks for the going through the blog.

          I have gone through the article which you have provided. Previously I didnot come across this article.Anyways I think this blog would be useful as it is consolidatd one with the points you have mentioned along with the Sender & Receiver adapter module configuration.

          (0) 
  2. Matthew Harding
    It’s a pity when web 2.0 collaboration tools and the SDN points bonus system counteract each other.  No one should ever be hassled for posting something they think is useful as I suspect others believe it is just to get points.

    Anyway, only thing I would add is to check-out a previous blog of mine which talks about the use of NWDI for source code control and XI deployment:
    The specified item was not found.

    Something as complex as adapter development should not be created outside of NWDI for supportability reasons.

    Good concise article.

    Cheers,
    Matt

    (0) 

Leave a Reply