Skip to Content

Rest Receiver with HTTP_AAE Adapter, Attachment and multipart/form-data

Hello, I'm trying to consume a Rest Service from PO 7.5 SP07, using HTTP_AAE Adapter at Receiver and java mapping for buid payload with attachment in HTTP format


For testing service, use Postman

using TraceHTTP in module adapter, show in monitor 3 message

HTTP_CLIENT : 1193 REQUEST:

POST /xxxxx/xxxx HTTP/1.1
Authorization: xxxxxxxxxxxxxxxx
Content-Type: multipart/form-data;
boundary="----=_Part_371_617392626.1532724363684"
User-Agent: SAP HttpClient v1.0
Content-Length: 1161
Host: xxx.abc.com:443


HTTP_CLIENT : 1193 REQUEST:

------=_Part_371_617392626.1532724363684
Content-Type: application/xml
content-id: <payload-005056A0750C1ED8A4BBC26D38B1B4CE@sap.com>


------=_Part_371_617392626.1532724363684
Content-Type: application/vnd.ms-excel
Content-Disposition: form-data; name="file"; filename="20422488198-01-0E001-0000118.csv"
Content-Disposition: attachment;filename="file.bin"

Content-ID: <payload-005056A0750C1ED8A4BBC26D38B194CE@sap.com>
Content-Description: file

2018-07-10,R067-0000003,2
------=_Part_371_617392626.1532724363684--


HTTP_CLIENT : 1193 REQUEST:

POST /xxxxx/xxxx HTTP/1.1

Authorization: xxxxxxxxxxxxxxxx
Content-Type: multipart/form-data;
boundary="----=_Part_371_617392626.1532724363684"
User-Agent: SAP HttpClient v1.0
Host: xxx.abc.com:443
Content-Length: 1161

There are 2 Content-Disposition, and I think a null payload, I dont know is it why return error

Java Mapping:

    public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException {
        // TODO Auto-generated method stub

        AbstractTrace trace = getTrace();

        String json = new String();

        InputStream ins = in.getInputPayload().getInputStream();
        // TransformationOutput outs = null;

        try {

            // ***************************************************************

            // Get document XML from input stream.

            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

            DocumentBuilder builder = factory.newDocumentBuilder();

            Document doc = builder.parse(ins);

            // ***************************************************************

            // ***************************************************************

            // Convertir XML a JSON - y Escribir nuevo Payload con content-type
            // editado

            // ***************************************************************

            // Instanciamos la clase para convertir el Payload

            parseDocument pDoc = new parseDocument();

            // Guardamos el nuevo Payload en variable String

            // json = pDoc.ConvertDocumentXML2JSON(doc);
            json = " ";
            out.getOutputPayload().getOutputStream().write(json.getBytes("UTF-8"));

            // Se obtienen los ContentID de los Adjuntos

            Collection<String> contId = in.getInputAttachments().getAllContentIds(false);

            String contentId = null;

            // Iteramos para obtener el String del ContentID

            for (Iterator iterator = contId.iterator(); iterator.hasNext();) {

                contentId = (String) iterator.next();

                // Creamos un Objeto Adjunto de entrada y lo tomamos con el
                // ContentID obtenido
                Attachment adjuntoIn = in.getInputAttachments().getAttachment(contentId);

                // Guardamos en Variables los 3 parámetros del adjunto de
                // entrada

                // 1) ContentID ya lo teniamos

                // 2) el contenido del archivo en Bytes[]

                byte[] content = adjuntoIn.getContent();

                // 3) el content-type del header del adjunto

                contentType1 = adjuntoIn.getContentType();
                
                // Editamos el content-type del header del adjunto al valor nuevo
                // deseado
                contentType1 = contentType1 + LINE_FEED
                        + "Content-Disposition: form-data; name=\"file\"; filename=\"20422488198-01-0E001-0000118.csv\"";
                
                // Eliminamos de la Salida el Adjunto que teniamos
                out.getOutputAttachments().removeAttachment(contentId);
                
                // Creamos un nuevo adjunto con los valores deseados
                Attachment adjuntoOut = out.getOutputAttachments().create(contentId, contentType1, content);
                //Attachment adjuntoOut = out.getOutputAttachments().create("file", contentType1, content);
                
                // Seteamos el nuevo adjunto como adjunto de Salida

                out.getOutputAttachments().setAttachment(adjuntoOut);
            }

        } catch (Exception e) {

            trace.addDebugMessage(e.getMessage());

        }

    }

Return Error:

MP: exception caught with cause com.sap.aii.adapter.http.api.HttpAdapterException: ERROR_SENDING_HTTP_REQUEST-Message Processing Failed. Reason : com.sap.httpclient.exception.ProtocolException: Data is not repeatable.

Please help, what am I doing wrong?

jrg04.png (17.0 kB)
c1dvn.png (16.1 kB)
huirj.png (25.4 kB)
Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Jan 23 at 11:20 AM

    Hi ,

    Can you please let me know is this issue solved. I also have the same scenario.

    Regards,

    Ramalakshmi.G

    Add comment
    10|10000 characters needed characters exceeded