Skip to Content

We all know about adapter user-module for java adapters, e.g. File, JMS, JDBC, etc.  But, what about for the HTTP adapter, which is an adapter in the ABAP stack?

In this blog, we will take a look at how we can write an user-module for the HTTP adapter.

Obviously, since HTTP adapter is an ABAP adapter, the user-module will have to be in ABAP code.

The concept is as follow.  The HTTP adapter is a service in ABAP, which is named “adapter_plain”.  We can examine this service with tx:SICF:

image

When we examine the details of this service, we see that this service executes the class, CL_HTTP_PLAIN_INBOUND.

image

Consequently, we can create another service, which also invokes this class.  And, in addition, this service can invoke another class right before it.  This additional class would be our user-module.

So, the steps would be the following:

  1. Create a “Z” class.
  2. Create a new service in SICF.
  3. Add two handlers to the service in the following order:  the “Z” class and CL_HTTP_PLAIN_INBOUND.

Sample HTTP User-Module

For demonstration purpose, in this blog we will create an XML wrapper for the HTTP payload.  The HTTP payload, which is non-XML, can contain any data.  The user-module will wrap the non-XML payload with an XML element.  This way, once in PI, we can use message mapping to decode the content of the payload.

1. Create the “Z” class in ABAP

  1. Enter tx:SE24 to create a class.  I will give it the name: zcl_xml_wrapper

    /wp-content/uploads/2009/03/httpusrmod_02_403731.jpg

    /wp-content/uploads/2009/03/httpusrmod_03_403732.jpg

  2. For the interface, enter:  IF_HTTP_EXTENSION

    /wp-content/uploads/2009/03/httpusrmod_04_403733.jpg

  3. With this interface, a method will automatically be available.

    /wp-content/uploads/2009/03/httpusrmod_05_403734.jpg

  4. Double-click on the method to enter the code, which will be the user-module.  Below is a sample code to wrap the payload with XML:

    method IF_HTTP_EXTENSION~HANDLE_REQUEST. DATA: wrap TYPE string,       xmlWrap1 TYPE string,       xmlWrap2 TYPE string,       payload TYPE xstring,       xml1 TYPE xstring,       xml2 TYPE xstring,       new_payload TYPE xstring,       util TYPE REF TO cl_xms_part_util.       if_http_extension~flow_rc = if_http_extension=>co_flow_ok_others_mand.       payload = server->request->get_data( ).         util = cl_xms_part_util=>getinstance( ).         xmlWrap1 = '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><root><mydata>'.         xmlWrap2 = '</mydata></root>'.         CALL METHOD util->convert_string_to_xstring             EXPORTING *            CHARSET = 'UTF-8'               in      = xmlWrap1             RECEIVING               out     = xml1.         CALL METHOD util->convert_string_to_xstring             EXPORTING *            CHARSET = 'UTF-8'               in      = xmlWrap2             RECEIVING               out     = xml2.         CONCATENATE xml1 payload xml2 INTO new_payload IN BYTE MODE.         server->request->set_data( new_payload ). endmethod.

  5. Save and activate the class.

2. Create a new service in SICF

  1. In tx:SICF, navigate to the “xi” node and right-click to create a new sub-element:

    image

  2. Create a unique name for the service.  In our test case, I use the name:  wrap

    image

  3. Provide a description for the new service and go to the “Handler List” tab.  For the handlers, enter two classes.  The first one is the one we created previously, ZCL_XML_WRAPPER.  The second one is the standard class used by the service “adapter_plain”, CL_HTTP_PLAIN_INBOUND.

    image

3. Test the user-module

The user-module can be tested using any HTTP test tool.  The URL must be:
     http://server:port/sap/xi/wrap?…

We used a standard test tool that has been featured on SDN in the past.  It does not matter what service, interface or namespace are used.  Even though in XI Monitor errors will occur due to no configuration in the Integration Directory, we are only interested the content of the payload to verify if the user-module was executed.

image

Using SXMB_MONI, we can examine the payload:

image

To report this post you need to login first.

10 Comments

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

    1. William Li Post author
      Java user-module is executed from the Adapter Framework (AFW) in the Java stack.  The ABAP stack is not (and cannot be) involved in the processing of msgs in the AFW.  In additional, with PI 7.1’s AAE local processing, the ABAP stack is bypassed or not used at all during end-to-end msg processing. 

      Regards,
      Bill

      (0) 
      1. Sudharshan Aravamudan
        Hi Bill,

        Nice blog. Lot of times we require manipulating the paylod before mapping in HTTP Adapter and you have provided the solution.

        I have two questions
        1) Can the approach be extended to XI Proxy Adapter (inbound/outbound).
        2) Do we have anything equivalent to Adapter Modules in ABAP. Becoz the main advantage of Adapter modules is change of character encoding, Dealing with attachments, etc.

        Kindly provide your valuable thoughts.

        Regards,
        Sudharshan N A

        (0) 
  1. Prateek Raj Srivastava
    Every now and then we see people saying adapter modules for http is not possible and no one even tries to give a thought about any workaround. This seems to be very much feasible and easy to implement. Thanks for sharing.

    Best Regards,
    Prateek

    (0) 
  2. abhishek salvi
    Hi Wlliam,

    The approach looks promising. I have some doubts:
    1) Can this approach be used in SAP PI7.11 to generate any of the message structures available in the operations section of Service Interface? Suppose I have Operation1 and Operation2 in the SI and I have to trigger Operation2 whenever string is passed by the HTTP sender.
    2) Is there any known negative impact (which can be avoided) that may occur on the server due to inclusion of the ABAP code in the HTTP service?

    Thanks,
    Abhishek.

    (0) 
  3. Michelle Fish

    Hello.  thanks for this information.

    I have a question – I used this approach to URL decode and resave the payload.

    My issue:  This works on my smaller HTTP shopping cart requests however on larger HTTP requests – the set_data for the new payload is failing.  I am getting a 31 as the m_last_error return code.  So – when the CL_HTTP_PLAIN_INBOUND is called and does a get_data it retrieves the original payload – not the new payload.

    Question: Is there a size limitation on the set_data?  Any recommendations – in order to handle errors on the set_data call and how to get the new payload to be accepted in the set_Data call ?

    Thanks, Michelle

    (0) 

Leave a Reply