Skip to Content

Cloud platform integration with OData - How to handle incoming $filter query parameter

We have defined an iFlow that exposes an OData service and consumes a receiver OData service. We want to allow end user to query this iFlow OData service with a $filter query parameter. We want the iFlow to able to extract the $filter from the incoming url and pass that to the receiver OData service.

How do we do this?

We think that the solution involves something like this:

${header.filter} in “Custom Query Options” field of “Processing” tab in “OData Receiver” connection

But we don’t know what ${header} property to use and we can’t find any documentation that clearly identifies the available ${header} properties.

Any guidance in the matter is appreciated.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

8 Answers

  • Apr 11 at 07:54 AM

    Hi Virendra,

    When an iflow is fired there is a Camel message object created and this is what is passed through the iflow.

    There are Headers values, Exchange Property values and a Body of the message object.

    You can pull the Header data and Exchange Property data from a Header value into the Body using a content modifier.

    In the Body tab of the Content Modifier, you can put in for example;

    Header "orderNo" is ${header.orderNo}
    
    Property "msgOut" is ${property.msgOut}

    And you pull them into the Body that way.

    .

    1. "We think that the solution involves something like this: ${header.filter}"

    So yes as long as there actually is a Header called "filter" in the message object then ${header.filter} can be used to access that.

    .

    2. "But we don’t know what ${header} property to use and we can’t find any documentation that clearly identifies the available ${header} properties."

    You can use a Groovy Script step to transfer all the Headers and Properties to the Body, where you can then see them, if you wish. Use the following script I've created for you to amomplish this:

    import com.sap.gateway.ip.core.customdev.util.Message;
    import java.util.HashMap;
    import java.util.List;
    
    def Message processData(Message message) 
    {
    
    // get the body as a string (no type casting needed as groovy is dynamic language)
    def body_as_string = message.getBody();
    
    // get the headers from the Message object
    def message_headers = message.getHeaders();
    
    // get the properties from the Message object
    def message_properties = message.getProperties();
    
    // create a new string to display in the Body
    def new_body_string =
    """
    This message was created using the Apache Groovy Language.
    
    All Headers: ${message_headers}
    
    All Properties: ${message_properties}
    """
    
    // set the Body of the Message object with the new string we created now
    message.setBody(new_body_string);
    
    return message;
    }
    
    

    .

    You can also log the body to the MPL as an attachment, which you can then look at.

    How to do that is explained here: https://blogs.sap.com/2017/01/09/hci-payload-logging-sorted-using-groovy-script/

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 12 at 03:26 AM

    Thanks Kevin for the response. In order to understand the content of header, properties and payload during the execution of iFlow, we are trying to get logs as attachment as mentioned as the above link and able to generate the attachment. However, when we try to open it, it fails with the below message. Any idea what could be wrong here?

    "Request for log attachments failed with error: Invalid server response: Couldn't parse message. Status Code: 500 Message: Internal" target="_blank">http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">Internal Server Error while trying to invoke the method java.io.InputStream.read(byte[]) of a null object loaded from local variable 'is'</message></error>"

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Virendra,

      You are having trouble logging the payload?

      Try the following code in a groovy script step (make sure it's not a javascript step):

      import com.sap.gateway.ip.core.customdev.util.Message;
      import java.util.HashMap;
      
      def Message processData(Message message) 
      {
          def body = message.getBody(java.lang.String) as String;
          def messageLog = messageLogFactory.getMessageLog(message);
          if(messageLog != null)
      {
              messageLog.addAttachmentAsString("ResponsePayload:", body, "text/plain");
           }
          return message;
      }
  • Apr 12 at 11:35 AM

    *Actually that may be caused by the following missing from the imports in the original answer:

    import java.util.List;

    I've updated the original answer now, adding this.

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 16 at 09:25 AM

    Hi Virendra,

    It's best to open an incident with us now to get further assistance with this.

    Best Regards

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Kevin,

      We are now able to dump the content of header and properties into logs, however, from the logs, not able to find any key/variable which is responsible for capturing filter value passed through url. For example, the below is Header List details from the current OData Service iFlow.

      null accept-language en-US,en;q=0.9,gu;q=0.8

      ODataContext org.apache.olingo.odata2.core.ODataContextImpl@501b8ee3 odataEntity Customers ODataMethod GET_FEED odataURI null SAP_MessageProcessingLogID AFy_xY3nU4CZP0GUMwfhjwAyYXip scriptFile script2.gsh scriptFileType groovy UriInfo com.sap.gateway.core.ip.odata.OGWUriInfo@da8f72b x-forwarded-for 50.101.108.120

      The same attempt to pass filter to a regular HTTP Integration Flow retrieves the below Header content which seems to pass the filter value correctly in the header as we can see the ID eq 'RAVAL' being captured in the CamelHttpQuery as seen below.

      null CamelHttpMethod GET CamelHttpPath CamelHttpQuery $filter=ID%20eq%20%27RAVAL%27 CamelHttpUrl https://c0908-iflmap.hcisb.int.sap.eu2.hana.ondemand.com/http/pogo CamelServletContextPath /pogo SAP_MessageProcessingLogID AFy_bxZ9Qd5hRZKz6n53-3VDJF6c scriptFile POGO_script.gsh scriptFileType groovy

      ..wondering how do we get such element like CamelHttpQuery in case of OData Integration flow.

  • Apr 24 at 12:37 PM

    Hi Virendra,

    Glad to hear you have got the pulling of data and logging it working.

    I'm not sure how to do the same with an Odata call (v4?), I assume it would add an extra layer of processing if it is possible, but it would take some time and testing to give a proper answer or suggestion.

    I would recommend to open a incident.

    Kind Regards

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 24 at 01:08 PM

    I have facing the same issue now. I have placed the iFlow in Trace mode and verified. There is no standard header available for accessing the query part in the incoming url.

    So for an alternative I am using HTTP sender channel for fetching the query part. Now I can able to access the CamelHttpQuery header into another header variable in content modifier. I used groovy script to isolate only values I require and saved in a property and using in further steps.

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 24 at 05:21 PM

    Hello Anil,

    Can you explain how you are using an HTTP *sender* channel to obtain the incoming OData query URL? In our use case, we have an HTTP *receiver* channel that is receiving an incoming OData request with the OData query parameters. It doesn't make sense to us that a *sender* is part of the solution.

    --- Andrew

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 29 at 09:57 AM

    Hello Andrew,

    Earlier, I tried OData as sender and couldn't able to fetch the URL parameters. So I have changed the design to HTTP as sender for capturing the query Parameters as there is no design restriction for us.

    If the OData adapter to be used for sure, then please use the header UriInfo header and then you can see the value of header as com.sap.gateway.core.ip.odata.OGWUriInfo@xyza123. Using groovy script we have to apply few methods on this class and fetch the filter paramter.

    Add comment
    10|10000 characters needed characters exceeded