cancel
Showing results for 
Search instead for 
Did you mean: 

read external file in adapter module

Former Member
0 Kudos

Hi

I'm developing a module in which an external file need to be read. For example, I am developing a module to decrypt messages, so I need read a private key from an external file.

Any hint?

Thanks!

Regards,

Hui

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Hui,

in the adapter module you are developing, in the EJB, in process method....just use File class to open the external file.....get its file descriptor......then in a String variable read the file contents.......then use this data for decripting your XML message.

Thanks,

Rajeev Gupta

Former Member
0 Kudos

Hi Rajeev,

should I bundle the file into the EJB (if possible, how to?)

or Should I just upload the file to the XI server? And what's the file path?

Thanks!

Regards,

Hui

Former Member
0 Kudos

Hi Hui,

you dont need to bundle the file in EJB.......JUST PUT THE FILE IN YOUR XI SERVER AND GIVE THAT FILE PATH IN YOUR ejb process method like:

BufferedReader bwr1 = new BufferedReader(new FileReader("<your filepath>"));

<your filepath> will be the complete path of your file - means starting fromm root dir to our file.

Thanks,

Rajeev Gupta

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi

We are facing same problem as above said

I'm developing a module in which an external file need to be read. For example, I am developing a module to decrypt messages, so I need to read a private key from an external file.

In Module while reading the private key file it is failing to read and going to else block and throwing "Key is null"

secretkeylocation = moduleContext.getContextData("SecretKeyLocation"); //Reading the path dynamically from channel

try {

iinKey = getClass().getResourceAsStream(secretkeylocation);

if(inKey == null)

{

throw new ModuleException("$$$$ key is null $$$$$");

}

}

NOTE:We have tried placing the pblic and private key certificates in different folder .But faced same issue again.

Former Member
0 Kudos

hi Venkat,

== Forum Tips: ==

you should write your own post, explain your issue and give this URL thread as a reference (URL link).

By this way, your post will be not marked like "Closed. Response already providen".

By reusing a closed thread, you limit the number of people who will read it...

regards.

mickael

Former Member
0 Kudos

Hi Hui,

Check out my solution in this thread

The thread discuss about creating a file form User Defined function, you can use the same in Adapter module also.

In URL connection change type=i and get Input stream

<b>URL url = new URL("ftp://user-name:password@server/Test.txt;type=i");

URLConnection con = url.openConnection();

InputStream op = con.getInputStream();

byte [] b = new byte(op.available());

op.read(b);

op.close();

</b>

Now, "b" byte array will have the file content.

Regards,

Uma

Message was edited by:

Uma Maheswari

Former Member
0 Kudos
prabhu_s2
Active Contributor
0 Kudos

with java it shud possible....the below code is used in a udf whic creates a new file. probably with this as a base u can check how to read a file in a module.

URL url = new URL("ftp://user-name:password@server/Test.txt;type=o");

URLConnection con = url.openConnection();

OutputStream op = con.getOutputStream();

op.write("Hello".getBytes());

op.close();

and the classes imported for the above are:

import java.net.URL;

import java.net.URLConnection;

import java.io.OutputStream;