The object passed to the script function includes message body, header and properties.

For JDBC and SOAP data sources each script file will have four functions, 2 functions for handling request and 2 functions for handling response.

For JPA data source each script file will have 2 functions, 1 for handling request and 1 for handling response.

In SOAP:

Function processRequestData can be used to modify the request message body which is a hashmap and return a body which is also a hashMap which is an input to Web service pre processsor.

Function processRequestXML can be used to modify the request message body which is an xml and return a body which is also xml

Function processResponseXML can be used to modify the response message which is an XML obtained from Web service response and return a body which is also XML

Function processResponseData can be used to modify the response message which is a hashMap obtained from Web service PostProcessor and return a body which is also a hashMap.

All the above functions can also modify headers and properties (properties which do not contain string ‘SAP’ or ‘sap’) which are hashMaps

message.getHeader(<HeaderName>,<HeaderType>) and message.getBody(<BodyType>) methods can be used in the above functions to get header and body respectively in a specific format.

In JDBC:

Function processRequestData can be used to create a hashMap which is currently used for mapping and this is input to oDataToSQLProcessor

Function processRequestSQL can be used to modify the sql statement which is a string and return the modified sql statement in message body

Function processResponseResult can be used to modify the hashMap result set obtained from a JDBC database call and return the hashMap in message body

Function processResponseData can be used to modify the final result set which is a hashMap obtained from ODataToJDBCProcessor and return a body which is a hashMap.

All the above functions can also modify headers and properties (properties which do not contain string ‘SAP’ or ‘sap’) which are hashMaps

message.getHeader(<HeaderName>,<HeaderType>) and message.getBody(<BodyType>) methods can be used in the above functions to get header and body respectively in a specific format.


In JPA:

Function processRequestData can be used to create a hashMap and this is input to JPAProviderProcessor

Function processResponseData can be used to modify the final result which is a hashMap obtained from JPAProviderProcessor and return a message body which is a hashMap

All the above functions can also modify headers and properties (properties which do not contain string ‘SAP’ or ‘sap’) which are hashMaps

message.getHeader(<HeaderName>,<HeaderType>) and message.getBody(<BodyType>) methods can be used in the above functions to get header and body respectively in a specific format.

You can fetch the body using function message.getBody() and you can set the body as message.setBody(body)

Properties is any key value pair (again a hashMap). Property can be set using the function message.setProperty(“InlineCount”, count);

Different headers have to be set based on the scenarios to be tested. Headers can be set using function message.setHeader(key,value)

The message class is included in the package com.sap.gateway.ip.core.customdev.util

In order to fetch uriInfo use the function

message.getHeaders().get(ODataExchangeHeaderProperty.UriInfo.toString());

UriInfo class is included in the package org.apache.olingo.odata2.api.uri

UriInfo gives details about

Start entity set – uriInfo. getStartEntitySet()

Target entity set — uriInfo. getTargetEntitySet()

Filter expression — uriInfo.getFilter().getExpressionString()

Custom query options — uriInfo. getCustomQueryOptions().get(“!deltatoken”)

Navigationsegments — uriInfo. getNavigationSegments()

To check if request has count — uriInfo.isCount()

To get the odataMethod use the function

message.getHeaders().get(ODataExchangeHeaderProperty.ODataMethod.toString());

ODataExchangeHeaderProperty enum is included in the package com.sap.gateway.core.ip.component.commons

The different ODataMethods available are GET_FEED, GET_ENTRY, DELETE_ENTRY, CREATE_ENTRY and UPDATE_ENTRY

Further, messages can be logged using the statement

log.logErrors(LogMessage.TechnicalError, <message>);

This is available in package com.sap.gateway.ip.core.customdev.logging

1.       Delta token and tombstone scenario in JDBC, SOAP and JPA: For this to be tested few headers have to be set in the Custom Processor

The deleted items must be set

message.setHeader(ODataCamelExchangeHeaders.DELETED_ENTITIES.toString(),deletedItems);

ODataCamelExchangeHeaders enum is included in the package com.sap.gateway.ip.core.customdev.api

The response type must be set

message.setHeader(ODataExchangeHeaderProperty.ODataResponseType.toString(),ODataResponseType.DeltaResponseMap);

The flag for delta token must be set

message.setHeader(ODataCamelExchangeHeaders.IS_DELTA_IMPLEMENTED.toString(), true);

The next delta token value must be set

message.setHeader(ODataExchangeHeaderProperty.DeltaToken.toString(), token);

The message body must have a hashmap including deleted entities and actual result entities as below

deltaResponse = new HashMap();

                deltaResponse.put(ODataExchangeBodyDeltaResponseMapProperty.Properties.toString(), resultEntities);                         deltaResponse.put(ODataExchangeBodyDeltaResponseMapProperty.DeletedEntities.toString(), deletedItems);

                message.setBody(deltaResponse);

                HashMap is included in the package java.util

                ODataExchangeBodyDeltaResponseMapProperty enum is included in the package com.sap.gateway.core.ip.component.commons

2.       Mapping in JDBC: The headers that have to be set for this are

message.setHeader(ODataCamelExchangeHeaders.JDBC_TABLE_MAPPING.toString(), tableMap);

tableMap is a hashMap with key being entity set name and value being the corresponding database table name.

message.setHeader(ODataCamelExchangeHeaders.JDBC_PROP_MAPPING.toString(), entitiesMap);

entitiesMap is a hashMap with key being entityset name and value being another hashMap having properties i.e. key being edmx property name and value being corresponding database column name.

3.       Inline count in SOAP:

If inline count has to be checked in soap data source “InlineCount” property has to be set in the custom processor.

message.setProperty(“InlineCount”, count);

To fetch the inline count value the CP is placed before the post mapping and the body obtained here is an XML and the same XML format has to be returned. (Exception case)

4.       Top, skip functions in JDBC:

Here only message body will be changed. The sql statement received in the message body has to be changed and set back. The header that has to be set to indicate $top is handled by custom processor is

message.setHeader(ODataCamelExchangeHeaders.IS_TOP_HANDLED.toString(), true);

5.       Mapping using custom processor in SOAP:

Request mapping has to be done on the XML document returned from a pre processor. The edmx properties have to be mapped with soap request properties and an XML structure has be returned.

function processRequestXML(message) {
  importPackage(java.util);
      importPackage(java.lang);
      var payload = message.getBody().toString();
      var body = message.getBody();
      var buffer = new StringBuffer();

      buffer.append("<tes:GetStockQuote xmlns:tes=\"http://www.restfulwebservices.net/ServiceContracts/2008/01\">");

      var tokens = payload.split("(?=<)|(?<=>)");

      for(var i=0;i<tokens.length;i++) {
                  if(tokens[i].contains("CustomerID")) {
                              buffer.append("<tes:request>");
                              buffer.append(tokens[i+1]);
                              buffer.append("</tes:request>");
                              i=i+2;
                  }
      }
      buffer.append("</tes:GetStockQuote>");
      message.setBody(buffer.toString());
      return message;
}

Response mapping has to be done on the payload retrieved from cxf call. Message.getBody().toString() returns a string of cxf payload. To retrieve the actual content of the body whose properties have to be mapped to edmx types use the function Message.getBody().toString(). This returns the String of CxfPayload which has to be parsed as shown below.

The code snippet to parse the payload is

function processResponseXML(message) {

  importPackage(org.apache.camel.component.cxf);

  importPackage(java.util);

  importPackage(java.lang);

  var payload = message.getBody().toString();

  importPackage(com.sap.gateway.ip.core.customdev.logging);

  log.logErrors(LogMessage.TechnicalError, "Response Payload is: " + payload);

  var tokens = payload.split("(?=<)|(?<=>)");

  var buffer = new StringBuffer();

  buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");

  buffer.append("<LoginRequestSet><LoginRequest>");

  var breakLoop = false;

  for(var i=0;i<tokens.length;i++)

  {

  if(tokens[i].contains("id") && !breakLoop)

  {

  buffer.append("<id>");

  buffer.append(tokens[i+1]);

  buffer.append("</id>");

  i=i+2;

  breakLoop = true;

  }

  if(tokens[i].contains("module_name"))

  {

  buffer.append("<module_name>");

  buffer.append(tokens[i+1]);

  buffer.append("</module_name>");

  i=i+2;

  }

  }

  buffer.append("</LoginRequest></LoginRequestSet>");

  message.setBody(buffer.toString());

  return message;

}

To report this post you need to login first.

1 Comment

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

Leave a Reply