Skip to Content

This blog is part of a collection of blog entries that shows architectural concepts and configuration of the SAP PI REST Adapter. We also added some sample scenarios to make it easier for you to understand how your scenario can be implemented using the PI REST Adapter.

If you haven’t done so far, best is to start with the very first blog PI Rest Adapter – Don’t be afraid within the blog series covering the concepts of the REST adapter. A complete list of all blog entries can be accessed from here PI REST Adapter – Blog Overview.

The current blog shows you along a sample scenario which kind of dynamic attributes are supported and how you can use them.

Scenario

Referring to the flight scenario that we have introduced in the previous blogs PI REST Adapter – JSON to XML conversion and PI REST Adapter – Defining a dynamic endpoint, we will do further enhancements by using the dynamic adapter specific message attributes of the REST adapter. If you haven’t done so far, you should first read the previous blogs to make yourself familiar with the scenario. In short, we provide a RESTful service in order to read different kind of flight information. Within PI, the calls are routed to either function modules BAPI_FLIGHT_GETDETAIL or BAPI_FLIGHT_CHECKAVAILABILITY.

In this blog, we would like to introduce a GET variable mode to distinguish between an expert and a default usage of the service. In the expert mode, in addition to the flight details we add the information of the return table of the function modules to the response of the service call.

To recall, this is how the respective Integration Flow looks like:

03_01 Integration Flow - same.png

Configuring the REST sender channel

In the SAP Process Integration Designer perspective of the NetWeaver Developer Studio (NWDS), we open the existing Integration Flow, and double-click on the sender channel of type REST to open the channel editor. Switch to the REST Resources tab below the Adapter-Specific tab. The rest of the settings remain unchanged.

We can use dynamic attributes to store information of the service call which we then can be used to control the message flow. The REST adapter comes with a set of predefined adapter specific message attributes such as resource, service, and id which are commonly used among RESTful services. In addition to the predefined attributes you can also define custom attributes which are then added to the header of the PI message.

First, we would like to define the resource as constant value flights. Add a new dynamic attribute REST Resource (resource) from the Dynamic Attribute drop down menu, select Manual Value as Value Source, and enter flights into the Static Value field.

03_05 Manual value attribute.png

Next, we would like to define two IDs based on the JSON payload, one for the airline identity, and one for the connection number. Add a new dynamic attribute REST ID (id) from the Dynamic Attribute drop down menu, select JSON Content Element from the Value Source drop down menu, and enter the respective JSON Element from the JSON payload, here FlightDetails.AirlineID. Proceed accordingly for the JSON element FlightDetails.ConnID.

03_06 JSON Element attribute.png

Finally, we define a custom attribute called mode. Select — Custom Attribute — from the Dynamic Attribute drop down menu, enter the Custom Attribute Name mode, select GET Variable from the Value Source drop down menu, and enter the GET Variable Name mode. Though I have chosen here the same name, the custom attribute name and the GET variable name do not have to be identical. Note, that you must not add the GET variable to the url pattern, in our example it remains /{service_part}.

03_07 Custom attribute.png

Enhancing the mapping of the response

Based on the mode attribute, we either like to add the return table to the response or not. So, we need to change the message mapping of the response message. Within the mapping, we need to access the dynamic attribute. I have created a user defined function getASMA to read the value of the dynamic attribute which we will use in the mapping:

@LibraryMethod(title=“getASMA”, description=“get adapter specific message attribute”, category=“UDFPool”, type=ExecutionType.SINGLE_VALUE

     public String getASMA (

       @Argument(title=“”) String namespace,

              @Argument(title=“”) String attribute,

               Container container)  throws StreamTransformationException{

            Map<String, Object> all = container.getInputHeader().getAll();

            DynamicConfiguration dynConf = (DynamicConfiguration)all.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

            DynamicConfigurationKey key = DynamicConfigurationKey.create( namespace, attribute);

            String value = dynConf.get(key);

                          return value;

     }

From the Integration Flow, you can double click on the operation mapping to navigate to the respective message mapping in the ESR. Expand the source and target structure, and define a new field mapping for the node return. The target node return should be created if the attribute mode equals expert. As you can see from the figure below, we first call the user defined function getASMA. As input parameter of the function I pass the key of the attribute, in our case name mode with namespace http://sap.com/xi/XI/System/REST. The output value of the getASMA function is compared with the constant value expert using standard function equalsS. In case of boolean true, the node is created. Below the return node, the child nodes need to be mapped from the respective nodes of the source structure.

03_08 Mapping of mode.png

Running the scenario

For testing the scenario we use the Advanced REST Client Application in the Google Chrome browser. The endpoint URL of your RESTful service starts with http://<host>:<port>/RESTAdapter with host and port of the SAP PI system, followed by what you have defined in the sender channel, here /demo/flight/<service>. Since we have defined a GET variable, we need to add the GET variable to the URL. Let’s stick here to the checkavail service.

First, I call the service with the default mode info. The URL is as follows: http://<host>:<port>/RESTAdapter/demo/flight/checkavail?mode=info

03_09 Chrome browser 2 Request.png

The response is as follows:

03_10 Chrome browser 2 Response.png

Let’s change the date of the flight details intentionally to a flight that does not exist, and call the service with the expert mode. The URL is as follows: http://<host>:<port>/RESTAdapter/demo/flight/checkavail?mode=expert

03_11 Chrome browser 3 Request.png

In the response you can see that the return items have been added.

03_12 Chrome browser 3 Response.png

You can access the dynamic attributes values from the DynamicConfiguration message header. In the message monitor, select the corresponding message, switch to tab Message Content, and open the DynamicConfiguration message header.

03_14 Dynamic Attributes link.png

Here you can see additional attribute values that we have added.

03_15 Dynamic Attributes.png

I hope this blog was helpful to understand the various options that you have to define dynamic attributes within the SAP PI REST adapter. If you like to learn more, check out the other blogs in the series, accessible from the main blog PI REST Adapter – Blog Overview.

To report this post you need to login first.

28 Comments

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

  1. Pragya dubey

    Hi Alexander,

    I have a similar scenario, but I want to add two parameters in my HTTP Header of Rest Sender.

    I am using Synchronous Sender Rest Adapter where I want to add few standard HTTP header values in the response.

    Do I have a standard Adapter module to do so ? Or I would have to write a custom module?

    I need to add these two fields in Response Header sent by Rest Adapter.

    “Access-Control-Allow-Origin” = “*”

    “Access-Control-Allow-Headers” = “Authorization”


    Will an adapter module help me in this case. I have raised it on SCN too , link : http://scn.sap.com/thread/3729029


    It would be great if you can provide some insight.


    Thanks,

    Pragya

    (0) 
    1. Alexander Bundschuh Post author

      Hi Pragya,

      we have lately added custom http header for the receiver channel, unfortunately custom http header for the response is not supported yet. It’s in our backlog but we don’t have any concrete shipment date yet.

      Alex

      (0) 
      1. Pragya dubey

        Hi Alex,

        Thanks a lot for responding. So you mean that I won’t be able to set HTTP headers.

        Also, the value that I want to set is not custom but standard http parameters which are currently not coming.

        The HTTP parameters that I want to add are :

        “Access-Control-Allow-Origin” = “*”

        “Access-Control-Allow-Headers” = “Authorization”


        Thanks Again !!

        (0) 
        1. Alexander Bundschuh Post author

          Hi Pragya,

          what I meant with custom is that you have to add them to the http header.

          I also checked the standard modules that we provide, unfortunately we don’t have any module that would fit here.

          So, the only option right now would be to create your own adapter module as long as we haven’t enhanced the REST adapter with supporting this.

          Alex

          (0) 
          1. Pragya dubey

            Thanks Alex for your valuable inputs.

            I would look out for creating my own adapter module. Just one question if you can help me here. I have been looking to PI JAVA docs but didn’t find any suitable class/method to write or set header. I do see get header methods but nothing to set except for set content type.

            Please let me know which class/ interface can I use for to achieve this.

            Thanks in advance.

            (0) 
            1. Monica Gonzalez

              Hi Pragya,

              I’m developing a integration AAE IDOC–>PI –> REST , and I need send in http header 3 custom parameters.

               

              My PI version is 7.4 SP 9 and the the HTTP Header only is from SP10 , i want to create a custom adapter module, but i have the same problem in dont know the class/method to set a header .

              Please could you tell me how was resolve your issue?

              Thanks and regards

              (0) 
              1. Mauricio Antonio Garcia Hurtado

                Hola Monica,

                Tengo un caso parecido al tuyo (AAE SOAP->PI->REST), y el servicio REST tiene HTTP Header para autenticar. No he conseguido documentación clara al respecto. Lo pudiste solucionar?.

                Agradezco tus comentarios.

                Saludos,

                (0) 
  2. Stéphan BLOCH

    Hello,

    I have a synchronous scenario with a REST receiver adapter with a response which comes back with a csv as payoad.

    I don’t found how to exploit it and how to convert it into a xml message.

    Do you have some advises to do that ?

    Thank you for all readers.

    (0) 
  3. Venu Chippa

    Hi,

    How can i use this dynamic attributs in ESR mapping without using NWDS. I’m not able to use GET operation using REST adapter because of mapping error.

    Please advise.

    Regards,

    Venu

    (0) 
    1. Stéphan BLOCH

      Hello,

      I finally found how to do what I want to do :

      /wp-content/uploads/2016/03/screenshot_03_910863.png

      However, I have a question, when I set the date like in my example, the first time it works but if I test another time with a different value for the date, the new value is not taken and the first date set is always in memory.


      Someone knows why ?


      My scenario is REST to PROXY in synchronous way.


      Regards

      (0) 
      1. PANAGIOTIS PAPADOPOULOS

         

        Hello,

        I am having the exact same problem:

        Scenario is REST to PROXY. Both REST Resources and GET Variables are working, but keep the same value until I stop/start the channel.

        Also did a search on Google / OSS Notes / Messages but didn’t find anything.

        Have you found a solution ?

        EDIT:

        Seems that’s the one:

        2258139 – REST sender channel is caching values from HTTP requests

        (0) 
  4. Aprajita Pandey

    Hi Alexander,

    Is there any way to declare the Additional attributes in REST sender as optional? I have configured one channel for 5 operations, all GET. I can define only 10 custom attributes and mark them as optional. I have 11th Get parameter as well that needs to be marked as optional. In below scenario I need to mark filterBy as optional.

    Additonal_Parameter.pngGet_Parameters.png

    (0) 
      1. ANIL KUMAR

        Hi  Alexander,

        I am working on REST synchronous scenario with GET  operation & the interface is working fine with Rest url – http://host:port/RESTAdapter/xxxxx/xxxxx/12345678.

        For this i define the endpoint as XXXXX/XXXXX & used suitable XI Dynamic  Attribute  in rest sender channel which is working as expected.

        Now what could be the endpoint & required XI Dynamic Attribute for below url in REST sender channel with GET operation.

        Rest url: http://host:port/RESTAdapter/XXXX/XXXXXX/12345678/docs

        Pls help me on this.

        BR,
        Kumar

        (0) 
          1. Marco Passariello

            Oh! Thanks Alex.

            Currently, I’m passing from “outside” parameters via rest interface by setting some default values, in this way the current (mandatory) parameters are always filled. But this is a workaround.

            Do You have any suggestions on how to handle so many (18+) optional parameters?

            Thanks a lot,

            Marco

            (0) 
  5. Kalpana Ramadoss

    Hi Alex,

    We have implemented PI scenario exactly the same way how you explained here, this was working fine when we are on PI 7.4 SP09 (Single Stack) but recently upgraded our system to PI 7.50.4.9 then the dynamic attributes configured in Sender Rest Adapter missing during response message mapping. The scenario is Rest to Rest synchronous. The strange part is this is working fine with REst to RFC synch scenarios where for Rest to Rest synch scenario the dynamic attributes missing after upgrade. Any idea?

    Thanks
    VJ

    (0) 
  6. Markus Erschig

    I am working on REST (sender) synchronous scenario with GET operation (SAP PI 7.4SP13).
    Question is how can I map HTTP method GET to two different message types on the same Endpoint? But I do not want to do this with neither with a HTTP variable nor an URL pattern element…

    Is this possible with current REST sender adapter?

    Examples for a user management requests retrieving user information of all users respectively a single user.

    GET http://host:port/RESTAdapter/api/users
    -> Get all users, I want to get a list of users

    GET http://host:port/RESTAdapter/api/users/{id}
    -> Get a user by ID, I want to get a single user

    How is it possible than to match operation to message types on operation determination tab (REST sender adapter)

    Best Regards,
    Markus

    (0) 
  7. Andrea Ferrari

    Hello,

    i’m working with a REST receiver channel. In Pattern Variable Replacement i set an Adapter-Specific attribute:

    I use the Pattern Element Name “token” to dynamic set HTTP Header “Authorization”:

    The Header Attribute Name “Token” has been setup using a java mapping UDF.

    I can see it in Dynamic Configuration:

    When i run the scenario i receive

    com.sap.engine.interfaces.messaging.api.exception.MessagingException: com.sap.aii.adapter.rest.ejb.receiver.PlaceholderMissingException: URL placeholder token is not configured, or has an empty value

    Where i’m wrong?
    Best regards
    (0) 
  8. swetha sap

    Hi Alexander,

    I have a REST to Proxy Sync scenario where I wanted to add a parameter in my HTTP response header header of REST sender adapter. I would need to add ( Access-control-allow-origin=”*” )

    I saw the earlier comment on someone requesting the same, but looks like this feature is in your backlog. My requirement is driving me to have the same feature provided in HTTP response header. Here I’m using REST sender adapter. Please let  me know if you have a fixed solution on this feature.

    I look forward to hearing from you.

    Thank you!!

    (0) 
  9. Akshay Ruia

    Hi Alexander,

    I have a proxy to Rest Synchronous Scenario. I need to read the dynamic configuration parameters. System is giving me general mapping error.

     

    Can you please help me how to read or remove this error.

     

    Thanks & Regards,

    Akshay Ruia

     

    (0) 
  10. Peter Asigbetse

    Hi Alexander,

    Can I ask is it possible to define arrays in the GET URL?

    My scenario is REST > SOAP where the SOAP service has a header structure (which could be mapped to URL parameters easily) and then an items array where there could be 1 to n records. 

    Thanks, Peter

    (0) 
  11. Nikhil Mahajan

    Hi Alexander,

    Need some guidance from you. In my scenario we have a sync REST <->PI(7.5)<->Proxy where we are posting orders in SAP.

    we need to authenticate the token we receive in the HTTP header ‘Authentication ‘ against a service and if its valid then only we can proceed else we need to send a HTTP 401 message back.

    I was wondering if this is achievable using the dynamic configurations.

    Thanks

    Nikhil

     

     

    (0) 

Leave a Reply