Using configure XSL with the build in parameters in the SAP PI mappings

I needed to figure out how it was possible to configure XSL in the configuration directory. I also need to get up to speed on how Java mappings could be configured.

This blog will give some information on how to configure both Java and XSL mappings.  It was quite simple to make it work.

The first thing was that I should move to the AbstractTransformation. Since StreamTransformation is deprecated and does not support the parameters.

The method to extend is

[java]
public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException.
[/java]

The input parts contains access to

[java]
InputParameters parameters = in.getInputParameters();
getTrace().addInfo(“Username ” + parameters.getString(“USERNAME”));
[/java]
It is not a possible to read all the parameters, so each parameter has to be hard coded. The parameters can have different types, so it is possible to assign a channel or an integer.

Then the information is saved into the dynamic configuration.

It is easy to access the information from the XSL mapping. The code has the public static String getValue(Map map, String key). This method makes it easy to reach the content. The XSL looks like the following.

[xml]











[/xml]

The method getValue looks like the following.
[java]
/**
* Method called from the XSL to return the value of the attribute
* Remeber to have in the XSL and call with
* xslsave:getValue($inputparam, ‘USERNAME’)
* @param map the inputparams
* @param key the key to lookup
* @return
*/
public static String getValue(Map map, String key){
try{
DynamicConfiguration dc = (DynamicConfiguration)map.get(“DynamicConfiguration”);
DynamicConfigurationKey keyConfig = DynamicConfigurationKey.create(namespace, key);
return dc.get(keyConfig);
}catch(Exception e){
return “Error fetching key “+ key + ” because: ” +e.getMessage();
}
[/java]

To set the mapping to use the parameters click the binding tab and add the information there. Then fill in the values that you are going to save in the java mapping.

 

The result of the mapping is then that the username and password fields are filled with value from the parameters.


 

It is possible to download the source from http://www.piarchitecture.com/download/XSLSaver.jar

Related Posts:

  • No Related Posts