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.

/wp-content/uploads/2016/09/fun_lib_1033514.png

Create the required functions in the function library.

/wp-content/uploads/2016/09/methods_1033515.png

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-receiver-httpaae-idoc-to-httpaae

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

/wp-content/uploads/2016/09/lib_dep_1033516.png

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

/wp-content/uploads/2016/09/fun_map_1033520.png

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

/wp-content/uploads/2016/09/var1_1033521.png

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.

/wp-content/uploads/2016/09/var_map_1033522.png

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

/wp-content/uploads/2016/09/htt_aae_url_param_1033523.png

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 header fields

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

/wp-content/uploads/2016/09/set_idoc_1033524.png

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

/wp-content/uploads/2016/09/get_idoc_1033525.png

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.

/wp-content/uploads/2016/09/get_filename_1033529.png

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

/wp-content/uploads/2016/09/set_filename_1033531.png

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.

To report this post you need to login first.

3 Comments

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

Leave a Reply