Skip to Content
0

HTTP POST multipart message error

Nov 28, 2016 at 01:42 PM

138

avatar image

I am facing an issue when posting a multipart message to extenal system.

To create the multipart message i am using a java mapping.

check the code below.

package com.peisa.arba.cot;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
//import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.sap.aii.mapping.api.AbstractTransformation;
//import com.sap.aii.mapping.api.DynamicConfiguration;
//import com.sap.aii.mapping.api.DynamicConfigurationKey;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;

public class MappingCOT extends  AbstractTransformation{
 
 final String CRLF = "\r\n";
    final String LF = "\n";
    String filecontent = "";
    String fresult="";
    String nombreFile = "";
    //private Map param;
 /**
  * method transform is called by the PI mapping program
 */
 public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException {
  // String filecontent = "";
   //String nombreFile = "";
  InputStream instream = in.getInputPayload().getInputStream();
  OutputStream outstream = out.getOutputPayload().getOutputStream();
   
     try
     {
       DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
          DocumentBuilder builder = factory.newDocumentBuilder();
         
          
          Document doc = builder.parse(instream);
          doc.getDocumentElement().normalize();
  
        //********************************************************************
      
               NodeList nList = doc.getElementsByTagName("Header");
         
               for (int temp = 0; temp < nList.getLength(); temp++) {
                  Node nNode = nList.item(temp);
                 
                  if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                     Element eElement = (Element) nNode;
                    filecontent =  filecontent.concat(eElement
                        .getElementsByTagName("TIPO_REGISTRO")
                        .item(0)
                        .getTextContent()+ "|" + eElement
                        .getElementsByTagName("CUIT_EMPRESA")
                        .item(0)
                        .getTextContent()+ LF);
                  }
               }
               
               NodeList xList = doc.getElementsByTagName("Detalle");
               
               for (int j = 0; j < xList.getLength(); j++) {
                  Node xNode = xList.item(j);
                     if (xNode.getNodeType() == Node.ELEMENT_NODE) {
                     Element xElement = (Element) xNode;
                     filecontent = filecontent.concat(xElement
                        .getElementsByTagName("TIPO_REGISTRO")
                        .item(0)
                        .getTextContent()+ "|" + xElement
                        .getElementsByTagName("FECHA_EMISION")
                        .item(0)
                        .getTextContent() +"|" +
                        xElement
                        .getElementsByTagName("CODIGO_UNICO")
                        .item(0)
                        .getTextContent() +"|" +
                        xElement
                        .getElementsByTagName("FECHA_SALIDA_TRANSPORTE")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("HORA_SALIDA_TRANSPORTE")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("SUJETO_GENERADOR")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("DESTINATARIO_CONSUMIDOR_FINAL")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("DESTINATARIO_TIPO_DOCUMENTO")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("DESTINATARIO_DOCUMENTO")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("DESTINATARIO_CUIT")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("DESTINATARIO_RAZON_SOCIAL")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("DESTINATARIO_TENEDOR")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("DESTINO_DOMICILIO_CALLE")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("DESTINO_DOMICILIO_NUMERO")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("DESTINO_DOMICILIO_COMPLE")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("DESTINO_DOMICILIO_PISO")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("DESTINO_DOMICILIO_DTO")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("DESTINO_DOMICILIO_BARRIO")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("DESTINO_DOMICILIO_CODIGOPOSTAL")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("DESTINO_DOMICILIO_LOCALIDAD")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("DESTINO_DOMICILIO_PROVINCIA")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("PROPIO_DESTINO_DOMICILIO_CODIGO")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("ENTREGA_DOMICILIO_ORIGEN")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("ORIGEN_CUIT")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("ORIGEN_RAZON_SOCIAL")
                        .item(0)
                        .getTextContent() +"|" +
                        xElement
                        .getElementsByTagName("EMISOR_TENEDOR")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("ORIGEN_DOMICILIO_CALLE")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("ORIGEN_DOMICILIO_NUMERO")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("ORIGEN_DOMICILIO_COMPLE")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("ORIGEN_DOMICILIO_PISO")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("ORIGEN_DOMICILIO_DTO")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("ORIGEN_DOMICILIO_BARRIO")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("ORIGEN_DOMICILIO_CODIGOPOSTAL")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("ORIGEN_DOMICILIO_LOCALIDAD")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("ORIGEN_DOMICILIO_PROVINCIA")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("TRANSPORTISTA_CUIT")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("TIPO_RECORRIDO")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("RECORRIDO_LOCALIDAD")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("RECORRIDO_CALLE")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("RECORRIDO_RUTA")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("PATENTE_VEHICULO")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("PATENTE_ACOPLADO")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("PRODUCTO_NO_TERM_DEV")
                        .item(0)
                        .getTextContent()+"|" +
                        xElement
                        .getElementsByTagName("IMPORTE")
                        .item(0)
                        .getTextContent()
                        + LF);
                  }
               }
               NodeList zList = doc.getElementsByTagName("Detalle_producto");
               
               for (int q = 0; q < zList.getLength(); q++) {
                  Node nNode = zList.item(q);
                  if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                     Element qElement = (Element) nNode;
                     filecontent = filecontent.concat(qElement
                        .getElementsByTagName("TIPO_REGISTRO")
                        .item(0)
                        .getTextContent() + "|" + 
                         qElement
                        .getElementsByTagName("CODIGO_UNICO_PRODUCTO")
                        .item(0)
                        .getTextContent() + "|" + 
                         qElement
                        .getElementsByTagName("RENTAS_CODIGO_UNIDAD_MEDIDA")
                        .item(0)
                        .getTextContent() + "|" + 
                         qElement
                        .getElementsByTagName("CANTIDAD")
                        .item(0)
                        .getTextContent()+ "|" + 
                         qElement
                        .getElementsByTagName("PROPIO_CODIGO_PRODUCTO")
                        .item(0)
                        .getTextContent()+ "|" + 
                         qElement
                        .getElementsByTagName("PROPIO_DESCRIPCION_PRODUCTO")
                        .item(0)
                        .getTextContent()+ "|" + 
                         qElement
                        .getElementsByTagName("PROPIO_DESCRIPCION_UNIDAD_MEDIDA")
                        .item(0)
                        .getTextContent()+ "|" + 
                         qElement
                        .getElementsByTagName("CANTIDAD_AJUSTADA")
                        .item(0)
                        .getTextContent()     + LF          
                     );
                  }
               }
               NodeList pList = doc.getElementsByTagName("Footer");
              
               for (int p = 0; p < pList.getLength(); p++) {
                  Node nNode = pList.item(p);
               
                  if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                     Element pElement = (Element) nNode;
                     filecontent = filecontent.concat( pElement
                        .getElementsByTagName("TIPO_REGISTRO")
                        .item(0)
                        .getTextContent()+ "|" + pElement
                        .getElementsByTagName("CANTIDAD_TOTAL_REMITOS")
                        .item(0)
                        .getTextContent() + LF);
                  }
               }
               NodeList mList = doc.getElementsByTagName("Control");
              
               for (int v = 0; v < mList.getLength(); v++) {
                  Node nNode = mList.item(v);
                  
                  if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                     Element vElement = (Element) nNode;
                    nombreFile =  nombreFile.concat(vElement
                        .getElementsByTagName("FileName")
                        .item(0)
                        .getTextContent());
                  }
               }
  //********************************************************************     
         
      //fresult = fresult.concat("Content-Type:multipart/form-data; boundary=--abcd"+CRLF+CRLF);
      fresult = fresult.concat("----abcd"+LF);
   fresult = fresult.concat("Content-Disposition: form-data; name=\"user\""+CRLF);
   fresult = fresult.concat(" "+LF); 
   fresult = fresult.concat("30708602309")+LF;
   fresult = fresult.concat("----abcd"+LF);
   fresult = fresult.concat("Content-Disposition: form-data; name=\"password\""+LF);
   fresult = fresult.concat(" "+LF);
   fresult = fresult.concat("801366"+LF);
   fresult = fresult.concat("----abcd"+LF);
   fresult = fresult.concat("Content-Disposition: form-data; name=\"file\"; filename=\""+ nombreFile +"\"" + LF);
   fresult = fresult.concat("Content-Type: text/plain"+LF);
   fresult = fresult.concat(" "+LF);
   fresult = fresult.concat(filecontent+LF);
   fresult = fresult.concat("----abcd"+LF);
   fresult = fresult.concat("Content-Disposition: form-data; name=\"submit\""+LF);
   fresult = fresult.concat(" "+LF);
   fresult = fresult.concat("Enviar"+LF);
   fresult = fresult.concat("----abcd--");
   
     
     }
       catch(Exception e){} 
    // String for constructing target message structure  
   try{
    outstream.write(fresult.getBytes());
      }
     catch(IOException e1){}
 }  // end of method transform
}  


this is the communication cannel configuration also

https://www.hidrive.strato.com/lnk/8QvMFJGW

This is the meesage i get from PIMON.

Now as i can see, the configuration i set in the cannel related to content type and enconding is not being considering at runtime. I am rigth?

Content-ID:<soap-5979a19bb3f711e697c000000064092e@sap.com>
Content-Type:text/xml; charset=utf-8; name="soap-5979a19bb3f711e697c000000064092e@sap.com.xml"
Content-Disposition:attachment;filename="soap-5979a19bb3f711e697c000000064092e@sap.com.xml"
Content-Description:SOAP
<SOAP:Envelope xmlns:SOAP='http://schemas.xmlsoap.org/soap/envelope/'><SOAP:Header>
<sap:Main xmlns:sap='http://sap.com/xi/XI/Message/30' versionMajor='3' versionMinor='1' SOAP:mustUnderstand='1'>
<sap:MessageClass>ApplicationMessage</sap:MessageClass><sap:ProcessingMode>synchronous</sap:ProcessingMode>
<sap:MessageId>5978f0ee-b3f7-11e6-8d44-00000064092e</sap:MessageId><sap:TimeSent>2016-11-26T16:42:42Z</sap:TimeSent>
<sap:Sender><sap:Party agency='http://sap.com/xi/XI' scheme='XIParty'></sap:Party><sap:Service>BS_xxxx_200</sap:Service>
</sap:Sender><sap:Receiver><sap:Party agency='http://sap.com/xi/XI' scheme='XIParty'></sap:Party><sap:Service>BC_ARBA</sap:Service>
</sap:Receiver><sap:Interface namespace='urn:peisa.com.ar:ERP:COT:Remitos'>SI_IS_xxxxxxxxxx</sap:Interface>
</sap:Main><sap:ReliableMessaging xmlns:sap='http://sap.com/xi/XI/Message/30' SOAP:mustUnderstand='1'>
<sap:QualityOfService>BestEffort</sap:QualityOfService></sap:ReliableMessaging>
<sap:System xmlns:sap='http://sap.com/xi/XI/Message/30' SOAP:mustUnderstand='1'>
<sap:Record namespace='http://sap.com/xi/XI/Message/30/general' name='interfaceDeterminationGUID'>56ecfee5b3f711e6a5dc00000064092e</sap:Record>
<sap:Record namespace='http://sap.com/xi/XI/Message/30/general' name='senderAgreementGUID'>da6f247fb1e3369a97d959d8e32301dd</sap:Record>
</sap:System><sap:HopList xmlns:sap='http://sap.com/xi/XI/Message/30' SOAP:mustUnderstand='1'>
<sap:Hop timeStamp='2016-11-26T16:42:42Z' wasRead='false'><sap:Engine type='AE'>xxxxxxx</sap:Engine>
<sap:Adapter namespace='http://sap.com/xi/XI/System'>XIRA</sap:Adapter><sap:MessageId>5978f0ee-b3f7-11e6-8d44-00000064092e</sap:MessageId>
</sap:Hop></sap:HopList></SOAP:Header><SOAP:Body>
<sap:Manifest xmlns:sap='http://sap.com/xi/XI/Message/30' xmlns:xlink='http://www.w3.org/1999/xlink'>
<sap:Payload xlink:type='simple' xlink:href='cid:payload-5978f0f0b3f711e680bd00000064092e@sap.com'>
<sap:Name>MainDocument</sap:Name><sap:Type>Application</sap:Type></sap:Payload></sap:Manifest>
</SOAP:Body></SOAP:Envelope>Content-ID:<payload-5978f0f0b3f711e680bd00000064092e@sap.com>
Content-Type:application/xml; name="MainDocument.xml"
Content-Disposition:attachment;filename="MainDocument.xml"
Content-Description:MainDocument
----abcd
Content-Disposition: form-data; name="user"
 
3070860xxxx
----abcd
Content-Disposition: form-data; name="password"
 
xxxxxx
----abcd
Content-Disposition: form-data; name="file"; filename="TB_20111111112_000000_20080124_000001.txt"
Content-Type: text/plain
 
01|2011111111202|20080124|91 R999900068148|20080124| |E|0| | |30682115722|COMPUMUNDO S.A|0|Ruta Prov |S/N| | | | |1200|PUERTO DE ESCOBAR|B| |NO|23246414254|COMPUMUNDO S.A.|0|San Martin 5797|S/N| | | | |1766|TABLADA|B|20045162673| | | | | | |1|123403|847150|3|100|23981|COMP. SP-3960 VP|UNIDAD|10004|01
----abcd
Content-Disposition: form-data; name="submit"
 
Enviar
----abcd--



however, if the message is set from Advance REST Client, the message is sent OK to extenal system.


https://www.hidrive.strato.com/lnk/2evMlr4m
https://www.hidrive.strato.com/lnk/5DPsFz3B
https://www.hidrive.strato.com/lnk/qHPslrDW
https://www.hidrive.strato.com/lnk/hPPMF6wt


Let me know if you have any idea about how to solve the issue.



Let me know also if you are able to download the pictures. I was unable to upload the pictures in the question.
 
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Alejandro Pertierra Nov 29, 2016 at 12:53 PM
0

also read the blog of Li

https://blogs.sap.com/2006/04/18/dynamic-configuration-of-some-communication-channel-parameters-using-message-mapping/

But something is not clear.

I have to set the value of the content-type in the section all raw.

DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey keyHeader1 = DynamicConfigurationKey.create( http://sap.com/xi/XI/System/HTTP“, “HeaderFieldOne”);

conf.put(keyHeader1, a);

return “”;

where "a" = multipart/form-data; boundary=--abcd

In the Communication channel, the value of HeaderFieldOne = Content-Type or HeaderFieldOne =HTTP_CONTENT_TYPE?

Rgds

Share
10 |10000 characters needed characters left characters exceeded