Skip to Content
Author's profile photo Tejesvi DVR

How to Handle Filters in Soap Operations

When an oData URL specifies filter, which has to be passed as a request parameter, then this filter expression must be retrieved from the uri and parsed in order to get the filter key and value.

Steps from Design Time tool

  1. Create an OData Service Implementation Project
  2. Create an OData Model for login operation, which can have properties CustomerId, CustomerName, Address,CategoryId,SupplierId

Img1.jpg

    3. Right click on odatasvc and choose Select data source

    4. Select the entity set and choose the query CRUD operation. Select the data source SOAP Service.

Img2.jpg

    5. Specify the wsdl file and choose the getCustomers operation from the list of soap operations and click on finish

Img3 (1).jpg

6. Right click on Query and select Define Custom Code

Img4.jpg

7. Select the script type as either javascript or groovy script

Img5.jpg

    8. The filter options specified in odata request has to be fetched in the custom script’s processRequestdata function. Initially the uriInfo object specified in the org.apache.olingo.odata2.api.uri package has to be fetched using the below function


function getUriInfo(message) {
  importPackage(org.apache.olingo.odata2.api.uri);
  importPackage(com.sap.gateway.core.ip.component.commons);
  var uriInfo = message.getHeaders().get(ODataExchangeHeaderProperty.UriInfo.toString());
  return uriInfo;
}

    9. From the uriInfo fetch the filter expression as below

   

Img7.jpg


function parseToWhereExpression(whereExpression) {
    importPackage (com.sap.gateway.ip.core.customdev.logging);
    var FILTER = "FILTER";
    var BINARY ="BINARY";
   
    if (whereExpression.getKind() == 'FILTER') {
                    return parseToWhereExpression(whereExpression.getExpression());
    }
    else if (whereExpression.getKind() == 'BINARY') {
                    var binaryExpression = whereExpression;
                   
                    var left = parseToWhereExpression(binaryExpression.getLeftOperand());
                    var right= parseToWhereExpression(binaryExpression.getRightOperand());
                   
                    childMap2.put("P_Lang",right);
                    return left + "EQ" +right;
    }
    else if (whereExpression.getKind() == 'PROPERTY') {
                    var property = whereExpression;
                    importPackage(org.apache.olingo.odata2.api.edm);
                    var prop = property.getEdmProperty();
                    var returnStr = prop.getName();
                    return returnStr;
    }
    else if (whereExpression.getKind() == 'LITERAL') {
                    importPackage(org.apache.olingo.odata2.api.edm);
                    var literal = whereExpression;
                    var literalType = literal.getEdmType();
                    var value = literalType.valueToString(literalType.valueOfString(
                                                                                    literal.getUriLiteral(), EdmLiteralKind.URI, null,
                                                                                    literalType.getDefaultType()),
                                                                                    EdmLiteralKind.DEFAULT, null);
                    return value;
    }
    else {
                    log.logErrors(LogMessage.TechnicalError, "***returning NULL****");
    }
   
}

So, if the odata request is https://localhost:8083/gateway/odata/SAP/SOAP;v=1/CustomersSet?$filter=CategoryId eq 10,

Then the request payload will look like

<soapenv:Body>
      <tes:getCustomers>
         <tes:categoryid>10</tes: categoryid>
      </tes:getCustomers>
</soapenv:Body>

   10. Right click on Query and select Define Response Mapping

Img9.jpg

    11. Do the mapping as below

Img10.jpg

    12. Right Click on Project and select Generate and Deploy Integration Content. This will deploy the bundle.

Now fire an OData Request https://localhost:8083/gateway/odata/SAP/SOAP;v=1/CustomersSet?$filter=CategoryId eq 10 on the browser and response will give the list of customers with categoryId 10.

Assigned Tags

      10 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Jitendra Kansal
      Jitendra Kansal

      Tejesvi DVR

      I am not able to see any attached images. Can you re-upload it?

      Regards,

      JK

      Author's profile photo Tejesvi DVR
      Tejesvi DVR
      Blog Post Author

      hi JK,

      i have re-uploaded the images, can you check and let me know,if they are visible now.

      i have just copy pasted the whole content from our internal wiki, may be that is causing the problem, now i have attached the images by inserting them.

      regards,

      Tejesvi

      Author's profile photo Jitendra Kansal
      Jitendra Kansal

      Pretty clear now. Thanks

      Author's profile photo Tejesvi DVR
      Tejesvi DVR
      Blog Post Author

      thanks a lot, i have will do the changes for the other blogs too..

      Author's profile photo Former Member
      Former Member

      Hi Tejesvi,

      My soap service on IIS required basic authentication so even i  added in header request the authorization i still see the 401 error. do u have any idea? since i'm tenting in our LAN is it smpUser as local user and not domain user send the request?

      Tx,

      Eli 

      Author's profile photo Former Member
      Former Member

      Hi Tejesvi,

      Where we include the source for importPackage(com.sap.core.odata.api.uri.expression)?

      Regards,

      Affaan

      Author's profile photo Tejesvi DVR
      Tejesvi DVR
      Blog Post Author

      hi Affaan,

      you dont need to include the source code for that package your are mentioning, As SMP container already contains the req olingo libraries.

      regards,

      Tejesvi

      Author's profile photo Former Member
      Former Member

      Hi Tejesvi,

      Thanks for reply. But I think its not the case. Can you please visit and respond to this thread?

      http://scn.sap.com/thread/3759387

      Regards,

      Affaan

      Author's profile photo Former Member
      Former Member

      Hi Tejasvi,

      Can you please provide your inputs the below blog:

      https://scn.sap.com/thread/3776246

      Author's profile photo Former Member
      Former Member

      Hi  Tejesvi DVR ,

       

      Hope you are doing good!

       

      Excellent blog! I was working on the filter scenario where we have multiple inputs as filter fo the Set, so how would we handle that as in the filter expression we will get the whole query with (key,value) separated with 'and'.

       

      Any help will be appreciated.

       

      Best Regards

      Fenil