cancel
Showing results for 
Search instead for 
Did you mean: 

Adapter moduler in file adapter receiver - get Target Directory from param

Former Member
0 Kudos

Hi everybody,

We are in PI 7.1

I need in an adapter module (file adapter receiver) to access to the Target Directory comming from parameters

I foound the code in a weblog

/people/sap.user72/blog/2005/07/15/copy-a-file-with-same-filename-using-xi

Here is the code I found

public ModuleData process(

ModuleContext moduleContext,

ModuleData inputModuleData)

throws ModuleException {

Object obj = null;

Message msg = null;

try {

Channel ch = new Channel(moduleContext.getChannelID());

obj = inputModuleData.getPrincipalData();

msg = (Message) obj;

XMLPayload xmlpayload = msg.getDocument();

String path = ch.getValueAsString("file.targetDir");

if (!path.endsWith("
") && !path.endsWith("/"))

if(path.indexOf("
")!=-1)

path+="
";

else

path += "/";

if (xmlpayload != null) {

convert(xmlpayload.getContent(), path);

}

inputModuleData.setPrincipalData(msg);

} catch (Exception e) {}

return null;

}

private void convert(byte[] bs, String path) throws Exception {

String bs_out = new String(bs);

String filename =

bs_out.substring(

bs_out.indexOf("<FileName>") + 10,

bs_out.lastIndexOf("</FileName>"));

bs_out =

bs_out.substring(

bs_out.indexOf("<Base64>") + 8,

bs_out.lastIndexOf("</Base64>"));

byte bb[] = com.sap.aii.utilxi.base64.api.Base64.decode(bs_out);

File f1 = new File(path + filename);

FileOutputStream fos = new FileOutputStream(f1);

fos.write(bb);

fos.close();

}

The object Channel come s from the package import com.sap.aii.af.service.cpa.Channel;

The jar is in the build path (com.sap.aii.af.service.cpa.jar);

When I write in NWDS

Channel ch = new Channel(moduleContext.getChannelID());

NDWS gives me an error "Cannot instantiate the type Channel".

Can somebody help me about that, please?

Does that code dosn't work in pi 7.1?

Thanks in Advance for your help.

Best Regards.

E. Koralewski

Edited by: Eric Koralewski on Feb 3, 2011 1:40 PM

Accepted Solutions (1)

Accepted Solutions (1)

stefan_grube
Active Contributor
0 Kudos

> When I write in NWDS

> Channel ch = new Channel(moduleContext.getChannelID());

> NDWS gives me an error "Cannot instantiate the type Channel".

it should be:



Channel ch = (Channel) LookupManager.getInstance().getCPAObject(CPAObjectType.CHANNEL, moduleContext.getChannelID());

(taken from sample module ConvertCRLFfromToLF)

http://help.sap.com/javadocs/pi/pi711sp03/index.html?com/sap/aii/af/service/cpa/Channel.html

Edited by: Stefan Grube on Feb 3, 2011 2:02 PM

Former Member
0 Kudos

Dear Stefan,

Thanks a lot.

You solved my problem.

Best regards.

E. Koralewski

Answers (1)

Answers (1)

RaghuVamseedhar
Active Contributor
0 Kudos

Hi Eric Koralewski,

Can you please tell me why you are going for "Adapter module"? Is it not possible to achive your requirment by Dynamic Configuration?

Regards,

Raghu_Vamsee