cancel
Showing results for 
Search instead for 
Did you mean: 

SAP PO-HTTP_AAE RECEIVER - FORM DATA WITH XML ATTACHMENT

0 Kudos

Hi All,

My scenario is Proxy to HTTP_AAE FormData, which is the service I need to send data to.

While sending the API formdata, I am experiencing the 400-Bad Request issue.

We are able to post the data via Postman, and the following are the API logs for Postman

In the receiver HTTP communication channel, the following configuration is used.

The next java mapping sends this information. The import mode of the .xml file is "NORMAL" which sends it through the form data service.

package com.test.sap.pi.file;

import java.io.*;
import java.net.HttpURLConnection;
import java.util.Map;

import com.sap.aii.mapping.api.StreamTransformation;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.Reader;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.*;
import java.io.*;

import com.sap.aii.mapping.api.StreamTransformationException;

import com.sap.aii.mapping.api.TransformationInput;

import com.sap.aii.mapping.api.TransformationOutput;
@SuppressWarnings("deprecation")

public class CreateForm implements StreamTransformation {

     private String boundary;
     private String boundary2;

     private static final String LINE_FEED = "\r\n";

     private HttpURLConnection httpConn;

     private String charset;

     private String body;

     private OutputStream outputStream;

     private PrintWriter writer;

     public void execute(InputStream arg0, OutputStream arg1)

  throws StreamTransformationException {

  // TODO Auto-generated method stub

         // creates a unique boundary based on time stamp

        // boundary = �===� + System.currentTimeMillis() + �===�;

         boundary = "--ejjeeffe1";
         boundary2 = "--ejjeeffe1--";

         //body = "Content-Type: multipart/form-data; boundary=";

        // body =  boundary + LINE_FEED ;

//        body.concat(boundary);

         addFormField("import_mode","NORMAL" );

        // addFormField("Filename","PriceFeed.xml" );

  

         body =body + boundary;

  

         body = body + LINE_FEED + "Content-Disposition: form-data; name=\"" + "file" +

         "\"" + "; " + "filename=\"" + "PriceFeed.xml" + "\"" +

          LINE_FEED + "Content-Type: text/xml"  + LINE_FEED + LINE_FEED;

 

         byte[] buffer = new byte[4096];

         byte[] message = body.getBytes();

     //    int bytesRead = -1;

         ByteArrayOutputStream outbody = new ByteArrayOutputStream();

   

         try {

  arg1.write(message);

  int len = -1;

  while ((len = arg0.read(buffer)) != -1) {

  arg1.write(buffer, 0, len);

  }

  } catch (IOException e) {

  e.printStackTrace();

  }

  

        String endchar = LINE_FEED + boundary2;

  try {

  arg1.write(endchar.getBytes());

  } catch (Exception e) {

  e.printStackTrace();

  }

  }

  public void setParameter1(Map arg0) {

  // TODO Auto-generated method stub

  }

    /**

     * Addsa form field to the request

     * @param name field name

     * @param value field value

     */

    public void addFormField(String name, String value) {

    	  body =  boundary + LINE_FEED + "Content-Disposition: form-data; name=\"" + name + "\""

+ LINE_FEED + LINE_FEED

    			    + value + LINE_FEED;

    }

	public void setParameter(Map param) {
		// TODO Auto-generated method stub
		
	}

}<br>

I receive the following response after submitting

The SWC was removed from the ICO.

Could you please suggest a solution to this scenario?

Your comments would be greatly appreciated,

Regards,

Harinath

Accepted Solutions (1)

Accepted Solutions (1)

stefan_grube
Active Contributor

I think that in the end there should be two new lines:

String endchar = LINE_FEED + LINE_FEED + boundary2;

Answers (2)

Answers (2)

emorillo
Discoverer
0 Kudos

I have the same case. But my interface not working. Can you help me?, please.

My java mapping code

package com.sap.mapping;
import java.io.*;
import java.net.HttpURLConnection;
import java.util.Map;

import com.sap.aii.mapping.api.StreamTransformation;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import com.sap.aii.mapping.api.StreamTransformationException;

import com.sap.aii.mapping.api.TransformationOutput;
@SuppressWarnings("deprecation")

public class BajaClientes implements StreamTransformation {

	private String boundary;
	private String boundary2;

	private static final String LINE_FEED = "\r\n";

    private HttpURLConnection httpConn;
    
	private String charset;

	private String body;

	private OutputStream outputStream;

	private PrintWriter writer;
	
	private String NombreServicio;
	private String Parametros;
	private String par1 ; 
	private String par2 ;

	public void execute(InputStream arg0, OutputStream arg1) throws StreamTransformationException {
		
		NombreServicio = "Baja_Clientes";
		Parametros  = "{\"pv_gpart_kk\":\"58175\",\"pv_vkont_kk\":\"4568\",\"pv_vtref_kk\":\"2145\",\"pv_anlag\":\"kmssdis\",\"pv_e_kofiz_sd\":\"PR\",\"pv_e_vbeginn\":\"20221220\",\"pv_e_vend\":\"20221220\"}";
        boundary = "--ejjeeffe1";
        boundary2 = "--ejjeeffe1--";
        
        par1 = "NombreServicio";
        par2 = "Parametros";
        
		body = boundary;
		body = body + LINE_FEED + "Content-Disposition: form-data; name=\"" + par1 + "\"" + LINE_FEED + LINE_FEED + NombreServicio + LINE_FEED;
		body = body + boundary;
		body = body + LINE_FEED + "Content-Disposition: form-data; name=\"" + par2 + "\"" + LINE_FEED + LINE_FEED + Parametros + LINE_FEED + LINE_FEED;
		
		
		byte[] message = body.getBytes();
		
		byte[] buffer = new byte[4096];

		ByteArrayOutputStream outbody = new ByteArrayOutputStream();

		try {

			arg1.write(message);

		} catch (IOException e) {

			e.printStackTrace();

		}

		String endchar = LINE_FEED + LINE_FEED + boundary2;
		
		try {

			arg1.write(endchar.getBytes());

		} catch (Exception e) {

			e.printStackTrace();

		}

	}

    public void addFormField(String name, String value) {

  	  body =  boundary + LINE_FEED + "Content-Disposition: form-data; name=\"" + name + "\""

+ LINE_FEED + LINE_FEED

  			    + value + LINE_FEED;

  }
	@Override
	public void setParameter(Map arg0) {
		// TODO Auto-generated method stub
		
	}

}

Postman Configuration

Communication Channel Configuration

Message Monitoring

Any suggestions?.

Regards

0 Kudos

HI Stefan,

After making the suggested changes, the service responded correctly.

Thank you so much.

Regards,

Harinath