Skip to Content

Idoc to Rest as file attachment

Hi Folks,

I have a requirement to Transform idoc into XML file & upload as rest attachment.

Can I use below approach:

1st ICO - IDOC to file

2nd ICO NO ESR objects dummy interface like pass through- File to Rest attachment using payload swap bean.

Is this possible or is there a better way to handle this requirement.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Oct 20, 2017 at 02:35 PM

    Hi Harry!

    OutputAttachments outAttachments;
    Attachment attachment = outAttachments.create(attName, attContentType, attBytes); outAttachments.setAttachment(attachment);

    You should get byte array for your main payload and put it to attachment.

    It's worth noting that you should mark "Read attachments" checkbox in Operation mapping.

    Regards, Evgeniy

    Add comment
    10|10000 characters needed characters exceeded

    • Thanks Evgeniy Kolmakov.

      The code is generating attachment.

      Thanks a lot for your help.

      For any one who'd like to reuse the code for attachment:

      public void transform(TransformationInput input, TransformationOutput output) throws StreamTransformationException {
        InputStream inStream = input.getInputPayload().getInputStream();
        OutputStream outStream = output.getOutputPayload().getOutputStream();
        try {
      // Transfer main payload content from input to output
      byte[] b = getInputStreamBytes(inStream);
         outStream.write(b);
      //Write Attachment
      OutputAttachments outAttachments = output.getOutputAttachments();
         Attachment attachment = outAttachments.create("Shipment.xml", "multipart/form-data", b);
         outAttachments.setAttachment(attachment);
        } catch (Exception e) {
         throw new StreamTransformationException("Exception: " + e.getMessage(), e);
        }
      }
      private byte[] getInputStreamBytes(InputStream inStream) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buffer = new byte[8192];
        int read = 0;
        while ((read = inStream.read(buffer, 0, buffer.length)) != -1) {
         baos.write(buffer, 0, read);
        }
        baos.flush();
        return baos.toByteArray();
      }
  • Oct 17, 2017 at 12:49 PM

    Hi Harry,

    Rest is adapter is capable of handling attachment only after 7.5 SP05> . If you are on the lower level you need to the pass the attachment as base64/binary format in one of the filed and ask third party to decode it back again.

    Br,

    Manoj

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 17, 2017 at 11:56 AM

    Hi Harry!

    Why to use two ICOs for that? Since your sender IDoc adapter converts source document to IDoc-XML format you can send it directly to REST receiver. But I doubt the ability of PayloadSwapBean to move main payload to attachment. I guess you should use java mapping to move your main payload to attachments section.

    Regards, Evgeniy.

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 20, 2017 at 01:14 PM

    Hi,

    Payload swap does not move the main payload to attachment. Could you please help me with java mapping on how to create attachment.

    Most of the blogs say how to read the attachments only, I'm looking for converting main payload to attachment. Any pointers is much appreciated.

    Thanks

    Add comment
    10|10000 characters needed characters exceeded