Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member182412
Active Contributor

Introduction

We have always common requirement is to get the dynamic configuration attributes like FileName, Directory etc or set the dynamic configuration attributes. For this we need to write the UDF by using DynamicConfiguration standard classes which shown in this SAP XI Dynamic Configuration - Code Gallery - SCN Wiki.

But we need to create the same logic in each and every mapping, instead of creating this logic every time we can create common UDF in function library in common software component then we can reuse this function in all of the mappings without writing the common logic, we only need to write the logic for building attribute value no need to worry about dynamic configuration logic.

Create Function Library

Create function library called MsgAttributeLib in common software component(PRO_UTILS 1.0) like below.


Note: We need to create this software component as dependency to all our software components then these functions will be available in all the software components.

Create the required functions in the function library.

UDF: getMessageID


@LibraryMethod(
  title = "getMessageID",
  description = "Get message id from message header",
  category = "MsgAttributeLib",
  type = ExecutionType.SINGLE_VALUE)
  public String getXIMessageID(Container container) throws StreamTransformationException {
  Map<String, Object> map = container.getInputHeader().getAll();
  String messageId = (String) map.get(StreamTransformationConstants.MESSAGE_ID);
  return messageId;
  }

UDF: getDynamicConfigurationKey


@LibraryMethod(
  title = "getDynamicConfigurationKey",
  description = "Get the dynamic configuration attribute from XI message header",
  category = "MsgAttributeLib",
  type = ExecutionType.SINGLE_VALUE)
  public String getDynamicConfigurationKey(@Parameter(title = "") String name, @Parameter(title = "") String namespace,
  Container container) throws StreamTransformationException {
  try {
  DynamicConfiguration dynamicConfiguration = (DynamicConfiguration) container.getInputHeader().getAll().get(
  StreamTransformationConstants.DYNAMIC_CONFIGURATION);
  DynamicConfigurationKey dynamicConfigurationKey = DynamicConfigurationKey.create(namespace, name);
  return dynamicConfiguration.get(dynamicConfigurationKey);
  } catch (Exception e) {
  return e.toString();
  }
  }

UDF: setDynamicConfigurationKey


@LibraryMethod(
  title = "setDynamicConfigurationKey",
  description = "Set the dynamic configuration attribute to XI message header",
  category = "MsgAttributeLib",
  type = ExecutionType.SINGLE_VALUE)
  public String setDynamicConfigurationKey(@Parameter(title = "") String name, @Parameter(title = "") String namespace,
  @Argument(title = "") String dynamicConfigurationKeyValue, Container container) throws StreamTransformationException {
  try {
  DynamicConfiguration dynamicConfiguration = (DynamicConfiguration) container.getInputHeader().getAll().get(
  StreamTransformationConstants.DYNAMIC_CONFIGURATION);
  DynamicConfigurationKey dynamicConfigurationKey = DynamicConfigurationKey.create(namespace, name);
  dynamicConfiguration.put(dynamicConfigurationKey, dynamicConfigurationKeyValue);
  return "Successfully set dynamic configuration key. key: " + name + "/" + namespace + " with value: "
  + dynamicConfigurationKeyValue;
  } catch (Exception e) {
  return e.toString();
  }
  }

Example#1

One of the requirement is to pass message id as a query parameter in the target url using HTTP_AAE adapter, for this we need to set the URLParamOne attribute as shown in this blog http://scn.sap.com/community/pi-and-soa-middleware/blog/2014/09/18/using-dynamicconfiguration-to-rec...

Add function library which we created before in the message mapping.

After adding the function library we can see them under functions.

Create a variable in the target structure to set the message id in URLParamOne attribute.

Create the mapping for variable, first get the message id using getMessageId function and after that set the URLParamOne attribute using other function setDynamicConfigurationKey, pass just parameters name and namespace like below.

In the directory receiver HTTP_AAE adapter give the query parameter name in first parameter.

The above example we did not write any code in the message mapping, we just reused the function which we created in function library. Similarly we can set any dynamic configuration key using above UDF's, we just need to pass the right parameters.

Example#2

One of the requirement is to copy the value from request to response as shown in this blog Copy value from Request message to Response message using DynamicConfigurationBean and dynamic heade...

To set the IDoc number in request mapping in custom attribute in message header like below.

To read the IDoc number from the message header in the response mapping like below.

Example#3

One of the common requirement to read the file name in the mapping and pass it one of the field in the target message.

To set the file name in the message mapping without writing any code.

Conclusion

By creating dynamic configuration functions in function library in common software component we no need to worry about the dynamic configuration logic in all our message mapping, we just need to write the logic to build the attribute value.

3 Comments
Labels in this area