cancel
Showing results for 
Search instead for 
Did you mean: 

UDF required

Former Member
0 Kudos

Hi,

In the source file structure, some of the fields are Filename, Directoryname, statuscode.

my requirement is I should check the status code, if it is other than 200, I should copy the file (Filename) from folder1 to folder2.(folder1 contains that file).

I need UDF for this...

once the file is copied, it should be deleted in the folder1

Let me know if its not clear.

Regards,

Varun

Edited by: Varun Reddy on Sep 23, 2009 8:00 PM

Accepted Solutions (0)

Answers (5)

Answers (5)

varun_k
Contributor
0 Kudos

Actually my Schema is financial one.

Its File to SOAP.

I need to do couple of validations before posting the message to webservice.

If it fails for any of the validations I should send mail(i am sending mail from UDF). Even when posting the message to webservice, if its not successfull(based on status code from the response file) I should retry the same message for 3 times, if I get Application error from webservice response, then send mail

So I had splited the flow into 3 sub flows

1) File to File flow which does all the validations and generate a file in the source folder to further process to webservice.

2) File to soap-which sends the validated file to webservice. (I am Archiving the validated file, because for that file, if the response from webservice has an error, then i should send the same message.)

3) File(response file from webservice) to mail - sends the mail if the status is not successfull (200 -represents success)

I am storing the Webservice response file in a folder

Now I should check the status from the fil, If its an error, copy the validated file from archive folder to Source folder to post to webservice.

i am currently looking at the 3rd flow

Let me know if anything is required

Regards,

Varun

Former Member
0 Kudos

HI Varun,

Why dont you then use a Script in your file Communication channel before processing ?

You can check the status using the script and if its 200 then you can first move the file from the archive folder to source folder and then your communication channel can pick the same and then process.

Also can you plz share how you are sending a mail using UDF. Aren't you using mail adapter here ?

shivhare
Active Contributor
0 Kudos

Hi

Can you explain your requirement

For more information moving file from one directory to other you see given link may useful for you

http://www.roseindia.net/java/example/java/io/MovingFile.shtml

Thanks ,

Amit

varun_k
Contributor
0 Kudos

please provice me a UDF to copy the file from one folder to another folder.... how to specify the folder path

Former Member
0 Kudos

Hi,

i also agree with satish, instead of UDF you should go with Multimapping, as with UDF its not possible to copy a file from a folder.

You can go for Multimapping as informed by Satish.

regards

Former Member
0 Kudos

Hi Varun,

Once you read the message into xi you need to do somethign with it. If you just want to copy then an os script in the file adapter also will work.

Regards,

---Satish

Former Member
0 Kudos

Hi Varun,

This is the java program for copying one file from one location to other location.

public class CopyFile

{

public static void main(String args[])

{

String source = "GiveHereSourceFile";
C://temp/test.txt

String dest = "GiveHereDestinationFolder";
D://test/temp.txt

copy(source, dest);

}

public static void copy(File source, File dest) throws IOException

{

FileChannel in = null, out = null;

try

{

in = new FileInputStream(source).getChannel();

out = new FileOutputStream(dest).getChannel();

long size = in.size();

MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);

out.write(buf);

}

finally

{

if (in != null) in.close();

if (out != null) out.close();

}

}

}

Former Member
0 Kudos

Hi Varun,

What do you want to do if it is 200? You want to process it or not?

Create multimapping and for the root node check the status code using if exists function. If it doesnot exists then do a straight record to record mapping and write to the folder where ever you want.

If it is 200 if you dont want to do anything then write to the same fodler from where you are picking.

Regards,

---Satish

Former Member
0 Kudos

hi Varun,

I have a doubt here:

Source Fields: Filename, Directoryname, statuscode

Target Fileds:????? Plz inform

And do you want to achive this copying of file from a folder to another folder using UDF???? I doubt if its possible.

Please elaborate more on the requirement.

Regards,

Rahul

varun_k
Contributor
0 Kudos

Hi Rahul,

target is mail.

If the status code is other than 200, mail will be triggered. In my case there is another flow file to soap. If the response file wich contains status code has other than 200, then i shd copy the file in the source folder and send the message agin to soap.

Regards,

varun