cancel
Showing results for 
Search instead for 
Did you mean: 

Create a file on FTP Server using Adapter Module

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member185881
Active Participant
0 Kudos

Hi Ranjeet

I have similar kind of requirement, need to discuss about that. May i ask ur cell no plz to discuss.

Regards

Dheeraj Kumar

9891802720

former_member185881
Active Participant
0 Kudos

Hi Ranjeet

I have similar kind of requirement, need to discuss about that. May i ask ur cell no plz to discuss.

Regards

Dheeraj Kumar

9891802720

Former Member
0 Kudos

Hi Ranjeet ,

File creation mechanism is correct . Before writing the xmlpayload string to file chcek for null.

if(xmltxt is not null )

{

outfile.write(xmltxt);

}

else

{

outfile.write("Data missing");

}

It should create file every time u can see the details.

Cheers,

Reddy

Former Member
0 Kudos

Hi Nanda,

Thanks for the input. But even if xmltxt is blank it should create a file with 0 content. Right? I have tested the program standalone,but it is not creating file on ftp server. Is there any limilation like only file can be created on XI server or something like that.?

Ranjeet Singh.

Former Member
0 Kudos

Hi Nanda,

I have put a check in the code where i am cheking whether the statement

boolean success = file.createNewFile();

is successful or not. And I am getting message 'File not created' , it mean

file.createNewFile(); call returned false and hence no file..

But when i am running file creation code on local Pc , it will creating a file.

Ranjeet SIingh.

Former Member
0 Kudos

Hi Ranjeet ,

Please check wether you have write permissions to create a file on FTP server .

Check this manually by logging into the FTP server .

Cheers,

Reddy

Former Member
0 Kudos

Hi Nanda,

yes I have write permission. I slight modified the code and printed the 'success' message result , File creation command is returning 'false'.

I think we need to have different of creating file in adapter module.

Former Member
0 Kudos

Hi Ranjeet ,

What is ur File CC ? Sender - give me the config details

Adapter module will create the file on a local directory and same file name u use in file CC to send that to other system using FTP .

You need to check wether u have access to create file locall on SAP R/3(XI) file system.

Check you have access to al11 T code and see for thr permissions.

Cheers,

Reddy

ravi_raman2
Active Contributor
0 Kudos

check runtime workbench and cc monitoring...to see if any error was thrown..if nothing was....then need more debugging of code....

Regards

Ravi Raman

Former Member
0 Kudos

Hi Ravi and Nanda,

File adapter is working and here is audit log .

Audit Log for Message: 4c774640-8e08-11dc-9502-001a4ba967d2

Time Stamp Status Description

2007-11-08 08:38:41 Success Using connection File_http://sap.com/xi/XI/System. Trying to put the message into the receive queue.

2007-11-08 08:38:41 Success Message successfully received by messaging system. Profile: XI URL: http://eimreyxid0:50000/MessagingSystem/receive/AFW/XI Credential (User): XIISUSER

2007-11-08 08:38:41 Success File adapter receiver: processing started; QoS required: ExactlyOnce

2007-11-08 08:38:41<b> Error AdapterModule:File Not Createdfalse</b>

2007-11-08 08:38:41 Success Message successfully put into the queue.

2007-11-08 08:38:41 Success The message was successfully retrieved from the receive queue.

2007-11-08 08:38:41 Success AdapterModule: Module called

2007-11-08 08:38:41 Success MP: processing local module localejbs/AdapterModule

2007-11-08 08:38:41 Success MP: entering

2007-11-08 08:38:41 Success MP: processing local module localejbs/CallSapAdapter

Former Member
0 Kudos

Hi Ravi and Nanda,

The issue is not yet resolved but i have found workaround to meet my requirment.

I wanted to put my receiver side file on twp FTP location using adapter module developemnt but now i have create a batch program ( having code to connect to FTP server and put the newly created file on an location in addition to where adapter is putting it).

I am calling this batch by the file adapter using OS level command facility of adapter.

Former Member
0 Kudos

Hi Ranjeet ,

Here the issue is the file is not getting created using the adapter module code you have written .

In the code you have written the file is getting created on local system where the File adapter is running . I feel you can check wether u have access to the local folder for writing a file .

You can write a log statement which will display the absolute path of the file location where you are trying to create the file. Please do this and check wether u have write access to the same.

I would appriciate if you can explain more about the OS level command alternative you have mentioned above.

Cheers,

Reddy

Former Member
0 Kudos

Hi Ranjeet,

I have seen you the following thread I am also facing the same problem. If you kindly help by providing the code for that batch program. I would be great help.

Thanks!

-Pavan