cancel
Showing results for 
Search instead for 
Did you mean: 

SOAP to FTP with attachment

Former Member
0 Kudos

Hello everybody!

We have a following scenario: SOAP payload with attachment -> PI -> FTP payload with attachment. The requirement is to send the payload as XML file and application attachments, which can differ in the number and format, to FTP server.

AFAIK SOAP Axis receiver Adapter with an option "keep attachments" can be used. Is it possible to accomlish the task using the File FTP Adapter as a receiver?

Thanks!

Daiga

Accepted Solutions (1)

Accepted Solutions (1)

bhavesh_kantilal
Active Contributor
0 Kudos

Here is what I would do,

  • Define a Generic MessageType / Service Interface for Attachments. Something like,

          <MT_Attachment>

               <AttachmentContent> 0..N

  • Operation Mapping will be a 1:N Operation Mapping ( Multi Mapping ) with 2 Target Message Service Interfaces. One for the Main Payload and other for attachments.
  • Message Mapping will also be a 1:N MessageMapping ( Multi Mapping ). Within this message mapping, you can access the attachment content using the standard API's SAP provides and push them into the <AttachmentContent> Tag.

In your Integration Directory, you may use the same or different File channels with the filename logic being set constant or dynamically as required.

Regards,

Bhavesh

Former Member
0 Kudos

Hello Bhavesh, That sounds good. Unfortunately I am not a Java programmer. Could you please provide some code snippet, how to access the SOAP attachment content? Or any useful links? Thank you in advance! Regards, Daiga

bhavesh_kantilal
Active Contributor
0 Kudos

Hello Daiga,

Have not tried this in a long time but this is what the code should look like,


GlobalContainer gc = container.getGlobalContainer();

InputAttachments ia = gc.getInputAttachments();

String ContentID = new String();

String base64 = "";

String contentType = "";

AbstractTrace trace = container.getTrace();

try

{

  if(ia.areAttachmentsAvailable())

  {

  trace.addInfo("Input attachment available");

  Collection<String> collectionIDs = ia.getAllContentIds(true);

  for (Iterator<String> it = collectionIDs.iterator(); it.hasNext();)

  {

  ContentID = it.next();

  Attachment attachment = inputAttachments.getAttachment(ContentID);

  contentType = attachment.getContentType();

  base64 = attachment.getBase64EncodedContent();

  }

  }

}

catch(Exception e)

{

}

  • The string base64 will contain the base64 encoded content of the attachment.
  • You can put this into the Output as appropriate.

Regards,

Bhavesh

Former Member
0 Kudos

Hello Bhavesh,

thanks! Message splitting is working and so far I got Base64 encoded content into the tag . How can I convert this content to binary data and sent them to ftp server?

Regards,

Daiga

bhavesh_kantilal
Active Contributor
0 Kudos

Hello Daiga,

  • In the code i had provided previously, we were reading the content as a Base64 Content.
  • Instead of Base64Content you can read the same as a ByteArray using the method getContent() instead of getBase64EncodedContent();
  • Subsequently, convert this as a String and push this as the output of your UDF.
  • When written to a file, this should open it as required.

In my code below the content of output should be written as the output of your UDF.


GlobalContainer gc = container.getGlobalContainer(); 

InputAttachments ia = gc.getInputAttachments(); 

String ContentID = new String(); 

String contentType = ""; 

AbstractTrace trace = container.getTrace(); 

try{ 

    if(ia.areAttachmentsAvailable()){

        trace.addInfo("Input attachment available"); 

        Collection<String> collectionIDs = ia.getAllContentIds(true); 

        for (Iterator<String> it = collectionIDs.iterator(); it.hasNext();){ 

            ContentID = it.next(); 

            Attachment attachment = inputAttachments.getAttachment(ContentID); 

            contentType = attachment.getContentType();

            byte[] bytes = attachment.getContent();

            String output= new String(bytes);

        } 

      } 

catch(Exception e){ 

Regards

Bhavesh

Former Member
0 Kudos

Hello Bhavesh, Okay this is clear. The question is, how to send that binary to the FTP server instead of this XML, which is generated for the attachment message:

    rthrth Regards Daiga

bhavesh_kantilal
Active Contributor
0 Kudos

Hello Daiga,

As per my previous reply,

  • Define a Generic MessageType / Service Interface for Attachments. Something like,

          <MT_Attachment>               <AttachmentContent> 0..N

  • Operation Mapping will be a 1:N Operation Mapping ( Multi Mapping ) with 2 Target Message Service Interfaces. One for the Main Payload and other for attachments.
  • Message Mapping will also be a 1:N MessageMapping ( Multi Mapping ). Within this message mapping, you can access the attachment content using the standard API's SAP provides and push them into the <AttachmentContent> Tag.

So for every attachment you should create the target message type through your mapping. Your Interface determination will use this multi mapping and will split and create as many files as the attachments.

Let me know if there is something in specific you are unclear about.

Regards

Bhavesh

Former Member
0 Kudos

Hello Bhavesh,

Okay this is clear. The question is, how to send that binary to the FTP server instead of this XML, which is generated for the attachment message:

Regards

Daiga

bhavesh_kantilal
Active Contributor
0 Kudos

On your receiver file adapter perform content conversion. As the entire content is in a single XML Field, this is a very straight forward content conversion.Output that will then be written is the binary content.

Regards

Bhavesh

bhavesh_kantilal
Active Contributor
0 Kudos

In the example you have provided,

RecordsetStructure: Attachment

Attachment.fieldSeparator : ,

Attachment.endSeparator: 'nl'

As there is only one field, the fieldseparator will not have any effect on the runtime

I am not sure if having endSeparator as nl will have a effect when you try to open the file or not. You can also leave this as blank.

Regards

Bhavesh

Answers (1)

Answers (1)

former_member182412
Active Contributor
0 Kudos

Hi Daiga,

File adapter does not support attachments, you can use SFTP adapter if your receiver support this because SFTP adapter supports attachment processing.

Regards,

Praveen.

Former Member
0 Kudos

Hi Praveen,

thank you for your replay. Unfortunately the partner supports FTP not SFTP.

Regards,

Daiga