Skip to Content

Many web applications we are asked to integrate with may not be XML-based or webservice-enabled. They are existing web applications using the HTTP/HTML protocol, requiring us to post data to them. The HTTP adapter can be used for this situation. However, using it can sometimes lead to uncertainty as to what exactly are being sent or posted to these 3rd-party web application. The url element contains the value of the URL to be used when posting to the 3rd-party application. It will override whatever has been hardcoded in the HTTP receiver communication channel.

The parmValue contains all the parameter values in the URL. In another word, they are the values to be posted. The key values for the URL parameters are configured in the HTTP receiver communication channel (see below). </p><p>The HTTP receiver communication channel configuration for the URL parameter key values: (the order of the parameter values in the source XML correspond to the order of the Parameter configuration below)<br/>!https://weblogs.sdn.sap.com/weblogs/images/4172/HPT1.jpg|height=400|alt=image|width=507|src=https://weblogs.sdn.sap.com/weblogs/images/4172/HPT1.jpg|border=0! <br/>Also, please note below that the “Target Host”, “Service Number” and “Path” are irrelevant. They will be replaced by the URL in the source XML.<br/>!https://weblogs.sdn.sap.com/weblogs/images/4172/HPT2.jpg|height=400|alt=image|width=513|src=https://weblogs.sdn.sap.com/weblogs/images/4172/HPT2.jpg|border=0! </p><p>The Message Mapping: <br/>!https://weblogs.sdn.sap.com/weblogs/images/4172/HPT3.jpg|height=382|alt=image|width=600|src=https://weblogs.sdn.sap.com/weblogs/images/4172/HPT3.jpg|border=0! </p><p>The User-Defined Function, “AssignURLValue”: <br/><textarea cols=”65″ rows=”20″>public void AssignURLValues(String[] url,String[] urlParm,ResultList result,Container container){
     DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
     DynamicConfigurationKey parmValue;

     // TargetURL
     parmValue = DynamicConfigurationKey.create( “http://sap.com/xi/XI/System/HTTP”, “TargetURL”);
     conf.put(parmValue, url[0]);

     // URL Parameters
     switch(urlParm.length) {
     case 6:
       parmValue = DynamicConfigurationKey.create( “http://sap.com/xi/XI/System/HTTP”, “UrlParamSix”);
       conf.put(parmValue, urlParm[5]);
     case 5:
       parmValue = DynamicConfigurationKey.create( “http://sap.com/xi/XI/System/HTTP”, “UrlParamFive”);
       conf.put(parmValue, urlParm[4]);
     case 4:
       parmValue = DynamicConfigurationKey.create( “http://sap.com/xi/XI/System/HTTP”, “UrlParamFour”);
       conf.put(parmValue, urlParm[3]);
     case 3:
       parmValue = DynamicConfigurationKey.create( “http://sap.com/xi/XI/System/HTTP”, “UrlParamThree”);
       conf.put(parmValue, urlParm[2]);
     case 2:
       parmValue = DynamicConfigurationKey.create( “http://sap.com/xi/XI/System/HTTP”, “UrlParamTwo”);
       conf.put(parmValue, urlParm[1]);
     case 1:
       parmValue = DynamicConfigurationKey.create( “http://sap.com/xi/XI/System/HTTP”, “UrlParamOne”);
       conf.put(parmValue, urlParm[0]);
     }
}
</textarea> <br/>As you can see, we do not map anything to the target XML. The only thing we are interested is to populate the URL and URL parameters. Therefore, the user-defined function does no mapping, instead its only purpose is to assign values dynamically from the source XML to the communication channel configuration. </p>h4. 2. Verifying What Has Been Posted
Now we have, supposely, configured the URL and the URL parameters to be posted. But, how can we be sure. Will all the parameters be sent? One way to find out is just to send it and hope that everything works out. But, if it doesn’t, how do we determine where is the problem? Was it because we did not post the parmaeters correctly, or the receiving application doesn’t work as expected? <p>In order to determine what has been sent, I developed a simple .asp application which returns all the URL information, including the following: query parameter, header information, payload, etc. The reason .asp was used is because most of us has a Windows system, where IIS can easily be installed or already installed. The .asp application can simply be copied to the “wwwroot” directory. The filename must be “displayPostData1.asp”. You can change the filename, but, at the same time, you must also change the URL in this example. </p><p>Below is the displayPostData1.asp program: <br/><textarea cols=”65″ rows=”30″><%

‘dim fs,f
‘set fs=Server.CreateObject(“Scripting.FileSystemObject”)
‘set f=fs.GetFile(“C:\data\HTTP\foo.txt”)
‘f.Attributes=32
‘Response.Write(“The attributes of the file are: “)
‘Response.Write(f.Attributes)
‘set f=nothing
‘set fs=nothing

‘Adjust this depending on the size of the files you’ll
‘be expecting; longer timeout for larger files!
Server.ScriptTimeout = 5400

‘Yank the file (and anything else) that was posted
PostData = “”

PostData = “Query String ” & Chr(13) & Chr(10)
PostData = PostData & “=============” & Chr(13) & Chr(10)
PostData = PostData & Request.QueryString & Chr(13) & Chr(10)
PostData = PostData & Chr(13) & Chr(10)

PostData = PostData & “Header Fields” & Chr(13) & Chr(10)
PostData = PostData & “=============” & Chr(13) & Chr(10)
for each header in Request.ServerVariables
     PostData = PostData & header & “=” & Request.ServerVariables(header) & Chr(13) & Chr(10)
next
PostData = PostData & Chr(13) & Chr(10)

PostData = PostData & “Payload Data ” & Chr(13) & Chr(10)
PostData = PostData & “=============” & Chr(13) & Chr(10)

Dim biData
biData = Request.BinaryRead(Request.TotalBytes)
‘Careful! It’s binary! So, let’s change it into
‘something a bit more manageable.
For nIndex = 1 to LenB(biData)
     PostData = PostData & Chr(AscB(MidB(biData,nIndex,1)))
Next

‘IIS may hang if you don’t explicitly return SOMETHING.
‘So, redirect to another page or provide some kind of
‘feedback below…
%>
<%response.write(PostData)%>
</textarea> <br/>The above .asp program displays everything about the URL, not just the URL parameters, so you can use it to examine every piece of information sent by your HTTP communication channel. </p><p>To use it, the interface needs to be synchronous, and you can use the test tool in the Runtime Workbench. </p><p>For our example, after executing it, we can go to the SXI_MONITOR and look at the response document, which contains the content of the URL information sent by the HTTP receiver communication channel. </p><p>The content is of the URL is: <br/>!https://weblogs.sdn.sap.com/weblogs/images/4172/HPT4.jpg|height=400|alt=image|width=595|src=https://weblogs.sdn.sap.com/weblogs/images/4172/HPT4.jpg|border=0!</body>

To report this post you need to login first.

14 Comments

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

  1. Praveen Sirupa
    In the ADF code, you are setting only last parameter based on the number of parameters in the source XML. How come you are able to see all the parameters returned by your ASP?

    in the example you only the 3rd parameter(URLParamThree) will be set. How 1st and 2nd params were set? You dont have a loop either.

    please clarify

    (0) 
    1. William Li Post author
      Hi,
      If you notice in the code, there is no “break;” after each “case” statement.  Therefore, if there are 3 values for the urlParam, then after it processed “case 3”, it will also proceed to process “case 2” and “case 1”.

      Regards,
      Bill

      (0) 
  2. Amit Valecha
    Hi Li,
    Thanks for blog,Blog is of much help to me,really appreciate your post.
    I have the following url which contains xml structure as a query in it,I need to access it and get back the response from it.
    http://www.oanda.com/cgi-bin/fxml/fxml?fxmlrequest=XYZUSDGBP5/13/2008
    I need to pass the values for client_id,exch,expr,date at runtime.I want to know how we can use the header parameters(Fieldone,Field two,etc) in this case.

    early help would be really appreciated.

    Thanks,
    Amit

    (0) 
    1. William Li Post author
      Hi,
      You might try the following:
      1)  Create a simple UDF, with 4 input parameters (give the names: client_d, expr, exch, date), and 1 output parameter (the output parameter can be assigned to anything, just change the ‘return’ statement as approprieate.

      2)  The code of the UDF is as follow:

      public String AssignParmValues(String client_id, String exch, String expr, String date, Container container){
           DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
           DynamicConfigurationKey parmValue;

           // URL Parameters
           parmValue = DynamicConfigurationKey.create( “http://sap.com/xi/XI/System/HTTP“, “UrlParamOne”);
           conf.put(parmValue, client_id);
            
           parmValue = DynamicConfigurationKey.create( “http://sap.com/xi/XI/System/HTTP“, “UrlParamTwo”);
           conf.put(parmValue, exch);
            
           parmValue = DynamicConfigurationKey.create( “http://sap.com/xi/XI/System/HTTP“, “UrlParamThree”);
           conf.put(parmValue, expr);

           parmValue = DynamicConfigurationKey.create( “http://sap.com/xi/XI/System/HTTP“, “UrlParamFour”);
           conf.put(parmValue, date);
           
           return client_id;
      }

      Regards,
      Bill

      (0) 
  3. Arman Eker
    Hi,

    I tried to make the scenario but the query string I get is different. I get something like this

    msgguid=16880E49E0EEC432E1000000C0146B67&service=BS_HTTP_SEN&namespace=http…

    I also unchecked the “Fail if missing parameters” checkbox because if I check it I get an error with the message: “ATTRIBUTE_MISSING_PARAMS”

    Appreciate help.

    Thanks,
    Arman

    PS: Great Blog 🙂

    (0) 
    1. Arman Eker
      Hi,

      OK solved the problem 🙂 By the way how could we save the returning data inside a file. How should we configure our DT?

      Thanks,
      Arman

      (0) 
      1. William Li Post author
        Hi,
        Using .asp, you can try the following code:

        Set lf = server.createObject(“Scripting.FileSystemObject”)
        SavePath = Server.MapPath(“./Data/savedPostData.txt”)
        Set SaveFile = lf.CreateTextFile(SavePath, True)
        SaveFile.Write(PostData)
        SaveFile.Close

        “Data” directory in the file path must be defined as a virtual directory in IIS.

        Regards,
        Bill

        (0) 
      2. Alexandre de Sousa
        Hello Arman,

        I have de same problem that you reported before, when I uncheck the “Fail If Adapter-Specific Message Attributes Missing” flag I get the error “ATTRIBUTE_MISSING_PARAMS”.

        Can you tell me how you sloved the problem?
        Many thanks!

        Regards,
        Alexandre

        (0) 
  4. Matthias Boettger
    Hi Bill,

    first of all thanks for this great Blog, but when we built up this exp. within our PI System
    we alway get an Error raised by the Java function:

    Exception:[java.lang.NullPointerException] in class com.sap.xi.tf._MM_FILE_TO_HTTP_ method Test[[Ljava.lang.String;@4e4bedf7, [Ljava.lang.String;@5af41b49, com.sap.aii.mappingtool.tf7.rt.ResultListImpl@502b8445, com.sap.aii.mappingtool.tf7.rt.Context@58f8f721]

    do you know why this could happen?

    thanks in advance
    Matt

    (0) 
      1. Matthias Boettger
        Hi Bill,

        I’m terrible sorry but I’m not a Java Programmer at all – so may could you be that kind an provide a code snipe for 7.1 similar to that one you used within your blog?

        kind regards
        Matt

        (0) 
    1. Raj Chintam

      I know the reason.  Null pointer exception is raised because when you are testing the message mapping, you need to pass arguments to the UDF where you trying to make use of the container object.  Since this container object is null when you run static tests, the compiler raises null pointer.

      But, it should not be a worry, this container object is populated at the runtime by adapter engine when you really run the end-to-end test.  You check you logs in the Call Adapter / SOAP Header to check your input paramters in UDF.

      Thanks,

      Raj Chintam

      (0) 
  5. Arkesh Sharma

    Hi William,

    I am unable to view any images in this blog post so it is getting difficult for me to understand and implement this blog. I have a similar scenario in which I have to implement a synchronous HTTP to HTTP messaging.

    I request you to please help me and guide me in this regard.

    Thanks,

    Arkesh

    (0) 

Leave a Reply