Skip to Content
0
Former Member
Nov 08, 2007 at 01:45 PM

Create a file on FTP Server using Adapter Module

11 Views

Hi All,

I am trying to create a file on ftp server using adapter module development.

Here is my code.

package com.eimskip.adaptermodule;

import javax.ejb.CreateException;

import javax.ejb.SessionBean;

import javax.ejb.SessionContext;

import com.sap.aii.af.mp.module.*;

import com.sap.aii.af.ra.ms.api.*;

import com.sap.aii.af.service.auditlog.*;

import java.io.*;

/**

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

*/

public class AdapterModule implements SessionBean, Module{

private SessionContext myContext;

public void ejbRemove() {

}

public void ejbActivate() {

}

public void ejbPassivate() {

}

public void setSessionContext(SessionContext context) {

myContext = context;

}

public void ejbCreate() throws CreateException {

}

public ModuleData process(ModuleContext moduleContext,

ModuleData inputModuleData) throws ModuleException {

Message msg = (Message) inputModuleData.getPrincipalData();

AuditMessageKey amk = new AuditMessageKey(msg.getMessageId(),

AuditDirection.INBOUND);

Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,

"AdapterModule: Module called");

//Added by ranjeet

try {

XMLPayload xmlpayload = msg.getDocument();

String xmltxt = xmlpayload.getText();

File file = new File("MLS_file.txt");

File file2 = new File("MLS_file.xml");

// Create file if it does not exist

boolean success = file.createNewFile();

BufferedWriter outfile = new BufferedWriter(new FileWriter("MLS_file.txt"));

// add the content to be written to the file.

outfile.write(xmltxt);

outfile.close();

if (success)

{

Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"AdapterModule:File Created");

}

else

{

Audit.addAuditLogEntry(amk, AuditLogStatus.ERROR,"AdapterModule:File Not Created");

}

//create the xml form of the file.

file.renameTo(file2);

} catch (IOException e) {

}

// Added code ends.

inputModuleData.setPrincipalData(msg);

return inputModuleData;

}

}/*

  • Created on Nov 8, 2007

*

  • To change the template for this generated file go to

  • Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments

*/

But file is not getting created on FTP Server though adapter module is getting called successfully. Is code for creating file correct?

Ranjeet Singh