Quantcast
Channel: Process Integration (PI) & SOA Middleware
Viewing all articles
Browse latest Browse all 741

Reuse FunctionLibrary for DynamicConfiguration and Message Header Attributes

$
0
0

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.

fun-lib.png

Create the required functions in the function library.

methods.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.

lib-dep.png

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

fun-map.png

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

var1.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.

var-map.png

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

htt-aae-url-param.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.

set-idoc.png

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

get-idoc.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.

get-filename.png

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

set-filename.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.


Viewing all articles
Browse latest Browse all 741

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>