cancel
Showing results for 
Search instead for 
Did you mean: 

PI 7.3: SFTP Adapter module - AttachmentSplitterBean - File name error

peter_wallner2
Active Contributor
0 Kudos

Dear experts,

I have a custom adapter module that connects to a SFTP server and polls JPEG files and attaches those

to the payload (

Eng Swee Yeoh then suggested to use

to retrieve the attached JPEG files from the payload and write them to the FTP receiver.

I do have multiple attachments on the message but the "AttachmentSplitterBean" gives me the following error:

MP: exception caught with cause com.sap.engine.interfaces.messaging.api.exception.MessagingException: com.sap.aii.adapter.file.configuration.DynamicConfigurationException: The Adapter Message Property 'FileName' was configured as mandatory element, but was not supplied in the XI Message header

In my adapter module I am writing the FileName to the Message header


MessagePropertyKey msz = new MessagePropertyKey( 

                                        "FileName", "http://sap.com/xi/XI/System/File"); 

                                msg.setMessageProperty(msz, Filename);

but still I am getting this error.

I think it is connected to the Module configuration. Currently it looks like this:

In ASMA I have ticked "File Name" but the actual Sender Channel is NFS because Adapter Module "SFTPSender" does the actual SFTP connection.

In ASMA of FTP Receiver Channel "File Name" is also ticked.

Thank you for any help with this.

Best regards,

Peter

Accepted Solutions (1)

Accepted Solutions (1)

engswee
Active Contributor
0 Kudos

Hi Peter

The error is at the receiver adapter processing and not at the custom module. This is because by default the custom module does not write the filename into the child messages' dynamic configuration.

Try adding storeFileName = Y to the parameters of the splitter. You can refer to the Module Parameter Reference section for more details.

Rgds

Eng Swee

peter_wallner2
Active Contributor
0 Kudos

Hello Eng Swee,

I can see in RWB that I always get 2 messages:

- one that contains only the JPEG file

- one that contains the SFTP trigger file and the JPEG

Somehow I am doing something wrong in my Adapter module code. I should only get one message with the trigger file and the JPEG.

Or is the AttachmentSplitterBean creating a second message?

Thank you again,

Peter

peter_wallner2
Active Contributor
0 Kudos

Hello Eng Swee,

I also adapted the module configuration:

In RWB I can see the AttachmentSplitterBean is working and it gets the correct name "test3.jpg" of the

attached image but it actually writes not the jpg file to the receiver FTP but the trigger file from my SFTP module:

I am lost now. I could not find anything related to my issue on

would you have an idea please?

Best regards, Peter

peter_wallner2
Active Contributor
0 Kudos

My java code to handle JPEG files in the SFTP Adapter Module now looks like this:


if (Filename!=null && Filename.endsWith(".jpeg")||Filename.endsWith(".JPEG")||

                                Filename.endsWith(".jpg")||Filename.endsWith(".JPG")){

                           

                            Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"We deal with a jpg file");

                           

                            Payload payload = msg.createPayload();

                            Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"empty payload created");

                           

                           

                            String workingdir = sftpChannel.pwd();

                            Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, 

                                    "working DIR : " + workingdir);

                           

                            Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"List content: "+list);

                               

                            

                            //loop over all picture files and create attachments to the payload

                            for (ChannelSftp.LsEntry entry : list) {

                                bis = new BufferedInputStream(sftpChannel.get(entry 

                                        .getFilename())); 

                                Filename = entry.getFilename(); 

                                //continue;

                                Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, 

                                        "File read sucessfully in loop : " + Directory + "/" 

                                                + Filename); 

                               

                                Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"entry" + Filename);

                               

                                byte[] binbytearray = convert(bis);

                                Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"byte array created");

                               

                                payload.setContent(binbytearray);

                                payload.setContentType("application/octet-stream;" + "name=\"" + Filename + "\"");

                                payload.setName(Filename);

                                String localname = payload.getName();

                                Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"file name set: "+localname);

                               

                                String conttype = payload.getContentType();

                                Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"cont type: "+conttype);

                               

                                msg.addAttachment(payload);

                                Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"payload attachment added");

                               

                                //inputModuleData.setPrincipalData(msg);

                            }

I think I did everything correct here.

Best regards,

Peter

engswee
Active Contributor
0 Kudos

Hi Peter

The module determines the child messages' filename from the attachment's content type. Please refer below to the comment for the logic of that part.


// Filename normally is included in the name parameter

// It can be enclosed in double quotes

// It can also be followed by other parameters or white spaces

// Some sample below:-

// text/plain;charset="UTF-8";name="file.txt" ;otherParam=ParamValue

// text/plain; charset=us-ascii; name=sample.txt

From the RWB audit log, it looks like the file name of the trigger file test3.jpg is being set as the attachment's filename. Can you double check your SFTP module coding on the part that sets the attachment names? I see that the variable Filename is used in many places, maybe it is causing some shadowing issue. Try to use unique variables for filename of the trigger file and also filename for the list of files from SFTP server.

Rgds

Eng Swee

peter_wallner2
Active Contributor
0 Kudos

Hello Eng Swee,

I adapted variable names for file names and now it works. Thank you again for your help.

Best regards,

Peter

engswee
Active Contributor
0 Kudos

Great. Really glad to know that it's working now. Thanks for updating the thread

Answers (0)