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.