Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
In our project there was a requirement in the Receiver side, that the data file will be created only when the flag file will be present in the XI server directory, if the flag file is not present then no data file will be created in the XI server directory and an exception message will be raised the flag file already exists. so this blog describes the steps to create a Customized Adapter Module.  To create a customized Adpter Module the following are the prerequisites. you have NWDS installed on your local machine.  Now to create a Customized Adapter Module follow the following steps. *Step1.* Open the NWDS. *step2.* Go to Menu, select File and then click on New and then select Project as shown below. *Step3.* A new window will be opened, select the option as J2EE in the left pane and the EJB Module Project in the Right pane of the window as shown below. *Step4.* Click on Next and give the project name in my case i have given as SDNProject and click Finish as shown below.  *Step5.* When you click on Finish a new project will be created in the J2EE window of the NWDS as shwon below. *Step6.* Now next step is select the project and right click and select properties as shown below. *Step7.* A new window will  be opened and select the option as Java Build Path in the left pane and select the Libraries Tab in the right pane of the window as shown below. *Step8.* Now select the Add External Jars button and add the following jars into the project and click on OK. aii_af_ms_spi.jar, aii_af_cci.jar, aii_af_ms_api.jar, aii_af_trace.jar, aii_af_mp.jar, aii_utilxi_misc.jar, aii_adapter_xi_svc.jar, aii_af_cpa.jar, aii_af_svc.jar, aii_util_xml.jar, ejb20.jar, exception.jar. These all jar file you can download from the SAP Maketplace or from your XI server. *Step9.* Now expand the whole project created and select the ejbmodule node and right click and select new package as shown below.   *Step10. *Give the package name, in my case i have given as com.sap.module and click on Finish as shown below.

 Now

*Step11.* Now expand the ejbmodule node the package will be added in the project.  *Step12.* Next Step, right click on the module node and select new EJB, a new window will be opened as shown below. *Step13.* Give the EJB class name, in my case i have used SDN,select the bean type as Stateless Session Bean and click on Next, uncheck the Remote Interface CheckBox and click on Finish as shown below.  *Step14.* Now expand the module node, three java classes will be generated as shown below.    *Step15.* Now double click on the first .java class and writh the following lines on code.In my case the logic for the adpter module will be write in the SDNBean.java class. package com.sap.module; import javax.ejb.SessionBean; import javax.ejb.SessionContext; import javax.ejb.CreateException; import java.io.*; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import com.sap.aii.af.mp.module.ModuleContext; import com.sap.aii.af.mp.module.ModuleData; import com.sap.aii.af.mp.module.ModuleException; import com.sap.aii.af.ra.ms.api.Message; import com.sap.aii.af.service.auditlog.AuditDirection; import com.sap.aii.af.service.auditlog.AuditMessageKey; import com.sap.aii.af.service.cpa.Channel; /** * @ejbLocal <{com.sap.module.SDNLocal}> * @ejbLocalHome <{com.sap.module.SDNLocalHome}> * @stateless * @transactionType Container */ public class SDNBean implements SessionBean { public void ejbRemove() { } public void ejbActivate() { } public void ejbPassivate() { } public void setSessionContext(SessionContext context) { myContext = context; } private SessionContext myContext; /** * Create Method. */ public void ejbCreate() throws CreateException { // TODO : Implement } public ModuleData process(ModuleContext moduleContext, ModuleData inputModuleData) throws ModuleException { String SIGNATURE = "process(ModuleContext moduleContext, ModuleData inputModuleData)"; Object obj = null; Message msg = null; String fileName= null; Writer output = null; try { obj = inputModuleData.getPrincipalData(); msg = (Message) obj; AuditMessageKey amk = new AuditMessageKey(msg.getMessageId(),AuditDirection.INBOUND); String archivedir = null; archivedir = (String) moduleContext.getContextData("archivedir"); Date d1 = new Date(); DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); DateFormat dateFormat1 = new SimpleDateFormat("hhmmss"); String date = dateFormat.format(d1); String time = dateFormat1.format(d1); Channel channel = new Channel(moduleContext.getChannelID()); String dirName = channel.getValueAsString("file.targetDir"); String filename = channel.getValueAsString("file.targetFileName"); int a = filename.lastIndexOf("."); int b = filename.length(); String str0 = filename.substring(0,3); String str1 = filename.substring(3,a); String genfilename = str0 + "FLAG" + str1 + date + ".flg"; String str2 = dirName + genfilename; String str3 = filename.substring(0,a); String str4 = filename.substring(a,b); String dir = checkDir(dirName); if (dir.equals("false")) { throw new ModuleException("Data File Directory Path " + dirName+ " Not Found"); } try { String create = createFile(str2); if(create.equals("true")) { throw new ModuleException("Flag File " + genfilename + " Already Exists"); } else { { File f2 = new File(str2); boolean success = f2.createNewFile(); if(!success) { throw new ModuleException("No Permission For Flag File Creation"); } } } } catch (Exception e) { ModuleException me = new ModuleException(e); throw me; } } catch(Exception e1) { ModuleException me = new ModuleException(e1); throw me; } return inputModuleData ; } public static String checkDir(String dirName) //Checking for the Existence of the Receiver Communication { //Channel Directory , if the Directory will File f1 = new File(dirName); //not present Exception will be raised "Directory Path Not Found". boolean success = f1.exists(); if(success) { return "true"; } else { return "false"; } } public static String createFile(String str2) //Checking for the Existence of the flag file, { //if present return true else false. File f2 = new File(str2); boolean success = f2.exists(); if( success ) { return "true"; } else { return "false"; } } } The above code is reterving the file name and the directory name from the receiver communication channel and generating the flag file name as, suppose you give the file name in the receiver communication channel as SDN111.xml, then the flag file will be generated as SDNFLAG111CCYYMMDD.flg. The code is checking for the flag file on the server if the flag file will not be present on the server then the flag file will be created and the data file will also be created and if the flag file is already present it raise the exception as Flag file already exixts and no data file will be created. The code is also checking for the directory path, if the directory will not be present the exception will be raised directory path not found. To archive the data file created in the specified directory i have used the following line of  command line code.     copy %1 G:\Work\%2     "c:\Program Files\WINZIP\wzzip" -a G:\Work\%~n2.zip G:\Work\%2
    set Time_HHMMSS=%time%
    set Time_Append=%Time_HHMMSS:~0,8%     for /f "tokens=1-5 delims=: " %%t in ("%Time_Append%") do rename G:\Work\%~n2.zip %~n2_%%t%%u%%v.zip    del G:\Work\%2 write the above code in a notepad file and save the file as SDN.bta file. *Step16.* After writing the code in the SDNBean.java class save the file. *Step17.* Now open the  ejb-j2ee-engine.xml file and add the following line of code after the *Step18.* Now open the ejb-jar.xml file remove the selected line of code in image as shown below.*Step19.* Save all the files and right click on the project and select BuildEJBArchive to create the .jar file as shown below. The Created Jar file is shown below.   *Step20.* Next step is to create the Enterprise Application Project, to create the Enterprise Application Project select New-->Project-->EnterpriseAPplicationProject. *Step21.* Give the name of the project and click on Next add the jar file project in the Enterprise Application project and click on Finish as shown below. *Step22.* Open the application-j2ee-engine.xml file and add the references to the file and save the file. *Step23.* Next step is to create the EAR file. To create the EAR file right click on the project and and select the option as Build Application Archive as shown below. *Step24.* Deploy the created EAR file on the server. *Step25.* Now to test the Adapter Module create a simple file to file scenario and add the following entries in the receiver communication channel. *Step26.* To use the Customized Adapter module in the receiver communication channel add the following in the module tab of the adapter as shown below. *In Processing Sequence:* *In Module Configuration:* *SDNReceiver *is the jndi name .

*archivedir *is the parameter name.

*Step27.* To archive the file created in the directory add the following entry in the communication channel.

1 Comment