Skip to Content

HTTP Test Tool For Multipart Form Data Submission to PI 7.3 with attachments using POST method

This is known fact that HTTP java adapter is added in the SAP PI version of 7.3 and its subsequent releases. Previously data can be sent to PI with Plain HTTP adapter using POST method only. But now with the Sender HTTP adapter of Advanced Adapter Engine, data can be dispatched to PI with both GET and POST method. The parameters introduced for this in HTTP_AAE adapter are Set Form and Set Multipart. The main aim with this parameters is to catch the data from Form submission of a webpage. This feature will be immensely helpful to fetch user data directly from the webpage without processing through another application code. I tried to use all features of this adapter by making a test tool which leverages the existing functionalities of HTTP_AAE adapter.  As the Set Form property can be used to specify the name of only one request parameter whose value is copied to the XI main payload. This is kind of drawback where all the fields of the Form is required in one single payload. The Set Multipart property may include entire fields but the data is scattered in different payloads which is not very convenient for using in the mapping. The Keep Attachments property is used to embed the attached files from the HTML Form. Please check the below screen shot for your reference.

multipartData.jpg

I have created the below mentioned HTML webpage which sends the data to PI HTTP_AAE adapter by using the POST method. The Message Header part contains the data about the PI server for which the message is intended. The Multipart Payload Data part contains the data of the payload of the message.

HTTPtoolWebpage.jpg

The code of the above page is significantly dependent on JavaScript. Thorough java script coding the payload fields are concatenated as required. But before going into the details of the coding, please have a look at the configuration of HTTP_AAE sender adapter of SAP PI version 7.3.1. All the properties are checked under Request Details in General tab. Main Payload Parameter Name field value is given to send the data of this field to PI. This field is used to hold the concatenated data of the whole form.  Neither the modules nor the ASMA attributes are used here in the example.

HTTPadapter.jpg

Now please have a detailed look of the front end HTML and JavaScript Code. The JavaScript code generates the URL of the PI server dynamically using the values given in the form. It also creates the xml data from the payload fields of the Form. The Main Payload Parameter Name payloadData is not any actual field here but a hidden field used to send concatenated data to PI. Here it is tried to form xml file with concatenation but the data can be sent in any text format and later can be handled through either module or mapping to convert in XML format for mapping purpose.

<html>

<!– HTTP Client for PI 7.3.1 –>

<script type=“text/javascript”>;

      <!–

      window.onload = function() {

            document.MessageParameters.onsubmit = submitForm;

      }

     

      function submitForm() {

           

            createMainPayload();

            // escape “http://

            var senderNamespace = escape(document.MessageParameters.SenderNamespace.value);

            var reqString = http://

            reqString = reqString + document.MessageParameters.Server.value+“:”;

            reqString = reqString + document.MessageParameters.Port.value + “/HttpAdapter/HttpMessageServlet?”;

            reqString = reqString + “interfaceNamespace=” + senderNamespace;

            reqString = reqString + “&interface=” + document.MessageParameters.SenderInterface.value;

            reqString = reqString + “&senderService=” + document.MessageParameters.SenderService.value;

            reqString = reqString + “&senderParty=” + document.MessageParameters.SenderParty.value;

            reqString = reqString + “&qos=” + document.MessageParameters.Qos.value;

            reqString = reqString + “&sap-user=&sap-password=”;

            reqString = reqString + “&sap-client=” + document.MessageParameters.Client.value + “&sap-language=EN”;

            this.action = reqString;

      }    

     

      function createMainPayload(){

           

            var payload = “<?xml version=\”1.0\” encoding=\”UTF-8\” ?>”;

            payload = payload + “<User><Name>” + document.MessageParameters.name.value + “</Name>”;

            payload = payload + “<Email>” + document.MessageParameters.email.value + “<Email></User>” ;

            document.MessageParameters.payloadData.value = payload;

      }

      //–>

      </script>

<head>

      <!– Meta Tags –>

      <meta http-equiv=“Content-Type” content=“text/html; charset=utf-8” />

     

      <!– CSS –>

      <link rel=“stylesheet” href=“structure.css” type=“text/css” />

      <link rel=“stylesheet” href=“form.css” type=“text/css” />

      <link rel=“stylesheet” href=“theme.css” type=“text/css” />

</head>

<body>

      <div id=“container”>

            <h1><img alt=“” src=“/Users/pbhadra/workspace/HTTP_Client/src/SAP-XI-310×100.jpg”></h1><br>

            <div class=“info”>

                  <h3>HTTP Client for PI 7.3.1</h3>  

            </div>

            <form name=“MessageParameters” class=“wufoo” method=“POST” action=“” enctype=“multipart/form-data”>     

            <ul>

                  <li class=“complex”>

                        <h4>Message Header</h4>

                       

                        <table border=“0” cellpadding=“0” cellspacing=“0” style=“border-collapse: collapse” width=“100%”>

                              <tbody>

                                    <tr>

                                          <td width=“10%”><label>Server Host</label></td>

                                          <td width=“22%”><input type=“text” id=“host” name=“Server” value=“Your XI server” size= “20”/></td>

                                          <td width=“5%”>   </td>

                                          <td width=“10%”><label>Port</label></td>

                                          <td width=“22%”><input type=“text” id=“port” name=“Port” value=“50000” size=“10” /></td>

                                    </tr>

                                    <tr>

                                          <td width=“10%”><label>Client</label></td>

                                          <td width=“22%”><input type=“text” id=“client” name=“Client” value=“001” size=“3” /></td>

                                          <td width=“5%”>   </td>

                                          <td width=“10%”><label>QOS</label></td>

                                          <td width=“22%”><input type=“text” id=“qos” name=“Qos” value=“EO” size=“4” readonly=“readonly”/></td>

                                    </tr>

                                    <tr>

                                          <td width=“10%”><label>SenderService</label></td>

                                          <td width=“22%”><input type=“text” id=“senderService” name=“SenderService” value=“TestComponent” size=“40” /></td>

                                          <td width=“5%”>   </td>

                                          <td width=“10%”><label>Party</label></td>

                                          <td width=“22%”><input type=“text” id=“senderParty” name=“SenderParty” value=“” size=“40” /></td>

                                    </tr>

                                    <tr>

                                          <td width=“10%”><label>SenderInterface</label></td>

                                          <td width=“22%”><input type=“text” id=“senderInterface” name=“SenderInterface” value=“dummy3” size=“40” /></td>

                                          <td width=“5%”>   </td>

                                          <td width=“10%”><label>Namespace</label></td>

                                          <td width=“22%”><input type=“text” id=“senderNamespace” name=“SenderNamespace” value=“dummy” size=“40” /></td>

                                    </tr>

                              </tbody>

                        </table>

                  </li>

                  <p></p>

                  <h4>Multipart Payload Data</h4>

                        <table border=“0” cellpadding=“0” cellspacing=“0” style=“border-collapse: collapse” width=“100%”>

                 

                        <tbody>

                              <tr>

                                    <td width=“30%”>Name<input type=“text” name=“name” value=“J.Doe” size=“25”></td>

                                    <td width=“30%” align=“right”>Email<input type=“text” name=“email” value=abc@test.comsize=“25”></td>

                              </tr>

                              <tr>

                                    <td width=“30%” align=“right”>File Attachment</td>

                                    <td width=“30%”><input type=“file” name=“Attachment1” size=“40” /></td>

                              </tr>

                              <tr>

                                    <td width=“60%”><input type=“hidden” name=“payloadData” /></td>

                              </tr>

                              <tr>

                                    <td width=“60%” align=“right”> </td>

                              </tr>

                              <tr>

                                    <td width=“30%” align=“right”> </td>

                                    <td width=“30%” align=“left” ><input type=“submit” value=“Submit Data” id=“button1” name=“button1”/></td>

                              </tr>

                        </tbody>

                  </table>

            </ul>

            <br>

            </form>

           

      </div>

</body>

</html>

The inbound message payload in the Integration engine (as PI 7.3.1 Dual stack is used) can be checked below. Concatenated value in xml format of all the Form fields is there under MainDocument ( text/plain ) of Payloads. The xml attachment is also present which was uploaded in the webpage along with the data.

MainDoc.jpg

/wp-content/uploads/2012/08/attachment_128640.jpg

So in a nutshell, it is required to have a custom browser scripting to submit a form from webpage if no application code is used. Another approach may be to use payload swap bean if the main data is sent through attachment by uploading required file through webpage.

This is my first blog in this forum. So please let me know your feedback and suggestions. Thanks a lot for going through this blog. 🙂

To report this post you need to login first.

10 Comments

You must be Logged on to comment or reply to a post.

  1. Nageshwar Reddy

    Hi Prabhir,

    Welcome to blogging. Thanks for sharing this.

    Few corrections you should look at…

    Only POST was supported in earlier versions(HTTP Plain adapter). Check out the SAP Note 839803. The note clearly says that Plain HTTP Adapter only supports HTTP POST.

    Previously data can be sent to PI with HTTP adapter using GET method only. But now with the Sender HTTP adapter of Advanced Adapter Engine, data can be dispatched to PI with POST method which is more secure and reliable form of network traffic in http protocol.

    Also, sap-user and sap-pasword do not work with Java adapter. You need to use j_username and j_password. Check my blog Java based HTTP adapter – How to pass username and password in query string?.

    (0) 
    1. Prabir Bhadra Post author

      Hi Nageswar,

      Thanks for pointing out.

      I already discovered that mistake but dont really know how to update the blog. I am checking that only.

      Although I did not get any issue while working with parameters sap-user and sap-pasword. Since I have not provided it in the request url string, it is prompted for user ID and pw. And worked perfectly in my case.

      (0) 
  2. Rakesh Sharma

    Hi Prabir,

    Thanks for sharing this blog. I have read lots of blogs on HTTP PI 7.3 client. But this one clearly explains the purpose of the parameters Set Form (Main Paylod parameter name), Set Multipart, Keep Attachment in HTP_AAE sender adapter. I tried your HTTP Client by pasting entire payload in “name” field and configuring HTTP_AAE adapter with Main Paylod Parameter Name = name. I even attached an XML file. It shows the desired payload in MainDocument and also shows Attachment1.

    Keep on blogging…

    Thanks

    Rakesh

    (0) 
  3. Evgeniy Kolmakov

    Hi Prabir! Thanks for very useful blog.

    One question: how can we get form data if source form doesn’t contain that concatenated xml string? If the client just sends form data “as is”.

    (0) 
    1. Prabir Bhadra Post author

      Hi Evgeniy,

      I have concatenated the string data to a particular parameter as only one parameter can be used for MainDocument payload. Otherwise all the field data will be scattered and come under different fields. Please check the first screenshot of my blog for the reference.

      (0) 

Leave a Reply