Skip to Content
0

Creating a zip attachment from java mapping after read an iDoc

Feb 01, 2017 at 05:03 PM

193

avatar image
Former Member

Hi, experts.

I have a requirement to send a zip file to a SFTP scenario from an iDoc.

The flow is:

- iDoc in XML with files in segments in base64.

- I have to read those files, extract them from the iDoc and compress all of them in one ZIP.

- Put the XML of the iDoc also in the ZIP file.

- Send the ZIP file to the SFTP.

I am reading the iDoc XML with jdom.

I have tried two approach:

1º) Trying to write it directly to the outputstream using something like

"out.write(decoded, 0, decoded.length);"

but this only sends the xml file, not the binary data to the receiver.

2º) Trying to create an attachment using:

"Attachment newAttachment = outputAttachments.create("factura.zip","application/zip", data);
outputAttachments.setAttachment(newAttachment);
"

But my problem is my execute method to read the XML is only using two parameters:

InputStream in, OutputStream out, and when I use the outputAttachments variable is empty (obviously)

Any idea how can I read the xml and send the zip at the same time?

Thanks and regards,

Joaquín.

10 |10000 characters needed characters left characters exceeded

Hi Joaquin,

I'm not sure if "SAP NetWeaver" is the best primary tag for this. Is this a Java Development question? There's a tag for that. Also, there are a handful of tags related to Process Integration, and I see you chose one of them as a secondary. Would one of those be a better primary tag? It's just that "NetWeaver" tends to be more about architecture, platform, and Basis topics, and this reads like a development question.

Cheers,
Matt

0
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Evgeniy Kolmakov Feb 01, 2017 at 06:09 PM
0

Hi Joaquin!

In java mapping you create class that extends AbstractTransformation class. By default you should implement method "transform" that has parameters of type TransformationInput and TransformationOutput.

Using these parameters you can get access to main payload and attachments.

Regards, Evgeniy.

Show 3 Share
10 |10000 characters needed characters left characters exceeded

If the IDoc adapter does not support attachments and that is the sender can they be generated in the mapping?

Regards,

Ryan Crosby

0

Hi Ryan!

It's my fault, I've missed the point that IDoc sender is used.

I've never tried it but help says that interface OutputAttachments:

Contains methods to set, change, or remove attachments of the XI message in the mapping. You can always use these methods, even if the Operation Mapping declares that it does not read attachments.

Or in case of IDoc sender OutputAttachments object is null and we can't create new attachments?

Regards, Evgeniy.

0

Hi Evgeniy,

I was curious to know if you have ever had success with an adapter that does not support it on the sending side? I still have an open ticket for the AS2 adapter which supposedly supports attachments on the sender side but for some reason I'm not able to generate one inside the message mapping (Try to collect up all errors and attach as an error report in case of a message mapping issue - an optional field that for some business reason must have a value for instance). Strangely enough, I am able to do attachments using the same mechanism for other adapters where attachments are supported. That's why I was wondering if it's tied to the sender adapter and if you had any other experience with that use case.

Regards,

Ryan Crosby

0
avatar image
Former Member Feb 02, 2017 at 09:51 AM
0

Hi, everybody.

Thanks for your answers!

Ryan is rigth, I cannot create the attachment because the sender is an iDoc.

The code

OutputAttachments outputAttachments = out.getOutputAttachments();
Attachment newAttachment = outputAttachments.create("factura.zip","application/zip", data);
outputAttachments.setAttachment(newAttachment);

Is giving a runtime error because the out variable is TransformationOutput (one of the imput for the transform method) and it comes null.

Kr,

Joaquín.

Share
10 |10000 characters needed characters left characters exceeded