Sie sind auf Seite 1von 30

SAP HANA Cloud Platform, integration service

Orchestration/Pipeline Steps: Message transformations and scripting

July, 2016 (Release 2.16) Public


Target

After completing this presentation of SAP HANA Cloud


Platform (HCP), integration service, you will be able to
understand:

• Message Transformation steps available in SAP HANA


Cloud Platform, integration service

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 2
Agenda

• Message Transformers

Note:
1) This document describes components as per release 2.16 ( July
2016)
2) There are some components/features mentioned as “Planned”.
These components are scheduled to get released in the upcoming
releases. However these are subject to change and always refer to
latest HCI documentation for released content.

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 3
Message Transformers
• Mapping
• Message Digest
• Encoder
• Decoder
• Filter
• Content Modifier
• Converter
• Script
Mapping

This Process Step is used to create a message mapping when the receiver system accepts a different message format than that of
the sender system. The message mapping defines the logic that maps input message structures with the required format of output
message structures.
Two types of mapping are supported

1) Message Mapping: Also called as graphical mapping. Editors are available in both eclipse as well as HANA Cloud
Platform, integration service WebUI
2) XSLT: XSLT mapping is created in xml editors like altova, xml spy and then imported in project.

All the mappings are available under the location src.main.resources.mapping under the project explorer node in
eclipse.

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 5
Message Mapping
This Process Step is used to create a message mapping when the receiver system accepts a different message format than that of the sender system.
The message mapping defines the logic that maps input message structures with the required format of output message structures. The message
mapping can be created using both WEB UI and eclipse.

1 Select Source Select Target


Message 2
Message
3 Drag &Drop

4 Add function

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 6
Message Mapping (Simulation)
After creating a message mapping , we can test this mapping using the simulation / testing feature of the WEB UI tool. To test the mapping, click on
the Simulate Button provided on bottom right corner of mapping editor. Upload the input file from your file system and then click on test button.

Simulate Upload
1 2 Input

3 Select the input xml file from your file


system
4 Click on Test Button to generate the
output xml

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 7
Message Mapping
This Process Step is used to create a message mapping when the receiver system accepts a different message format than that of the sender
system. The message mapping defines the logic that maps input message structures with the required format of output message structures.

.
1 When we need to map different node structures of the
source message to only one node structure of the target
message, we can use the option of duplicating the sub
trees

.
2 Maintain parameters of functions

.
ReturnAsXML would return the selected field
Note: Mapping can be saved as Excel by selecting Export to Excel in Context Menu
3 in XML format

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 8
XSLT Mapping

When we right click on Mapping step, we Below is a snippet of how XSLT mapping looks like. You can use
get an option 'Assign Mapping' . There we any XSLT editors to create the mapping and import this mapping in
can either assign Message mapping or the project folder
XSLT Mapping‘. If there is no predefined <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/
mapping we can create a new Message or XSL/Transform (http://www.w3.org/1999/XSL/Transform)">
XSLT mapping. <xsl:output method="xml" indent="yes" omit-xml-
Note: All the mappings are available in the declaration="yes"/>
folder src.main.resources.mapping <xsl:param name="id"/>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="store_id">
<store_id><xsl:value-of select="$id"/></store_id>

</xsl:template>
</xsl:stylesheet>

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 9
Message Digest
This integration flow step is used to calculate a digest(hash value) of the Payload or parts of it and store the result in a message header.

The Message Digest integration flow step transforms a message into a canonical XML document. Canonicalization transforms an XML document
into a form (the canonic form) that makes it possible to compare it with other XML documents From this document, a digest(hash value) is
calculated and written to the message header. With the Message Digest integration flow step, you can apply canonicalization to a message (or to
parts of a message), calculate a digest out of the transformed message, and add the digest to the message header.

In simple terms, canonicalization skips non-significant elements from an XML document. The original message remains unchanged. We also
have the option to define a filter to apply canonicalization only to a sub-set of the message. Following attributes can be specified:

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 10
Message Digest
1 Filter: If you only want to transform part of the message, enter an Xpath expression to specify
the part (optional attribute).

2 Canonicalization Method: You can choose between the following methods.


• Inclusive XML Canonicalization
• Inclusive XML Canonicalization with Comments
• Exclusive XML Canonicalization
• Exclusive XML Canonicalization with Comments
• None

Note: This is an optional attribute.

3 Digest Algorithm: Select the hash algorithm to be used to calculate the digest.

You can choose between the these hash algorithms: SHA-1, SHA256, SHA384, SHA512, MD5

This is a mandatory attribute.

Header Name: Enter the name of the header element which is to contain the hash value 1
4
(digest). This is a mandatory attribute 2
3
4

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 11
Encoder
This Process step is used to encode messages by using an encoding scheme to secure any sensitive
message content during transfer over the network.
1 3
In the Properties view, following encoding schemes can be selected from the dropdown list:
1• Base64 Encode: Allows you to encode the message content using base64.

2• GZIP Compress : Allows you to compress the message content using GNU zip (GZIP).
2
3• ZIP Compress: Allows you to compress the message content using zip.

4• MIME multipart encode: Allows you to transform the message content into a MIME multipart message

4
Example

Consider the input XML payload structure to the encoder:


<message> Input for encoder</message>

If you select Base64 Encode, the output message would look like

PG1lc3NhZ2U+DQoJSW5wdXQgZm9yIGVuY29kZXINCjwvbWVzc2FnZT4NCg==

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 12
Decoder
This Process step is used to decode the message received over the network to retrieve original data

In the Properties view, following decoding schemes can be selected from the dropdown list. 1
1• Base64 Decode: Allows you to decode base64-encoded message content.

2
• GZIP Decompress : Allows you to decompress the message content using GNU zip (GZIP).
2
• ZIP Decompress: Allows you to decompress the message content using zip.
3
4• MIME multipart decoder: Allows you to transform a MIME multipart message into a message with attachments

Example
4
Let us suppose that an input message to the decoder is a message encoded in Base64 that looks like
this:
PG1lc3NhZ2U+DQoJSW5wdXQgZm9yIGVuY29kZXINCjwvbWVzc2FnZT4NCg==

The output message of the decoder would be as follows:


<message> Input for encoder</message>

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 13
Filter
This process step is used to filter information by extracting a specific node from the incoming
message.

1 In the Properties view, enter an Xpath to extract a specific message part from the
body. For example, in the Xpath field, enter
/ns0:MessageBulk/Message/MessageContent/text() .
. .
2 Returns the value of Node
specified
3 Returns parent Node and
child Nodes
Example:

Consider an XML payload structure-


<Message><orders> <order> <clientId>I0001</clientId> <count>100</count> </order> <order>
<clientId>I0002</clientId> <count>10</count> </order></orders></Message>

If you enter an Xpath- /Message/orders/order/count/text().

The output of the Content Filter would be- 10010

2
1
3

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 14
Content Modifier
This Process step is used to modify the content of the incoming message by providing
additional information in the header or body of a message before sending it to the
receiver.

You can also use Content Modifier to define local properties for storing additional data,
during message processing. These properties can be further used in connectors and
conditions.

1• Header Tab: Define additional headers or set values for existing headers of messages
by using constants, another header, an XPath, a property , an external parameter, by 1
forming an expression, a local variable or a global variable.

To enter an XPath, select xpath in the Type column and browse for an XPath from the
lookup in the Value column.(Note: The Data Type column is mainly used for the XPath
type. The data type can belong to any Java class. An example of a data type for an XPath
is java.lang.String.)

If the XPath contains a namespace prefix, specify the association between the
namespace and the prefix in the Runtime Configuration tab page of the integration flow
Properties view.

Local variables and Global variables are declared using the Write variable step.

To access Header, we can use ${header.<Header Name>}

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 15
Content Modifier
To enter a header, select header in the Type column, and browse for a header from the
lookup in the Value column. (Note:This lookup dialog shows you a list of headers that
you have specified) 2
• In the Header tab page of Content Modifier flow steps

• In the Allowed Headers field of the Runtime Configuration tab page

To enter an external parameter, select external parameter in the Type column and define
parameter key.

2• Property Tab: Similar to headers, user can also define properties with different
value types as explained above, by selecting Property tab in Properties view.

Note: Header values can be lost post external system call, whereas properties will be
available for complete message execution.

During outbound communication headers will be handed over to all message receivers
and integration flow steps whereas properties will remain within integration flow and will 3
not be handed over to receivers.

3• Body Tab: In the Body tab of the Content Modifier, you specify the content expected
in the outgoing message.

• To access Body, we can use ${in.body}

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 16
Content Modifier
Example of Content Modifier usage:

Suppose the incoming message has the following information:


<order> <book> <BookID>A1000</BookID><Count>5<Count></book></order>

• Body Tab: Keep a placeholder for the header information to modify the content as
shown below:
<invoice><vendor>${header.vendor}</vendor>${in.body}<deliverydate>${header.date}</delivery></invoice>

• Header Tab:

• Output would look like this:

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 17
Converter
If you have an input message in CSV/XML/JSON format, you need to convert it into XML or JSON or CSV format to use it in the subsequent steps
of the integration flow. You can use the converter to achieve this message transformation.

Converter step can be used for the below conversions.

• CSV to XML conversion

• XML to CSV conversion

• XML to JSON conversion

• JSON to XML conversion

By Default when we add a converter step in the integration flow, it is CSV to XML convertor. In order to switch to other supported conversions,
select the step and right click to switch to a different conversion.

Note: As of the latest release, the convertor step


JSON to XML is only supported in eclipse

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 18
Converter: CSV to XML
If you have an input message in CSV format, you need to convert it into
XML format to use it in the subsequent steps of the integration flow. You
can use the CSV to XML converter to achieve this message
transformation.

In the Properties view, enter the details based on the descriptions for
the fields given in the table below.

1• Choose Browse and select the file path to the XML schema file that
is used as the basis for message transformation. The XML file
schema format is used as the basis for creation of the payload. This
file has to be in the package source.main.resources.xsd

2• XPath in the XML Schema File where the content from CSV has to
be placed.

3• The corresponding record in the CSV file that has to be considered


for conversion. This entry is the first text in every new record of the
CSV. Note: If this value is not specified then all the records would be
considered for conversion. 1
4• The field separator used in the CSV file 2
3
4

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 19
Converter: CSV to XML example
Example

Consider a CSV file that is in the following format:


COMPETENCY,Role Specific,Computer Skills,"Skilled in the use of computers, adapts to new technology, keeps abreast of changes, learns new programs quickly, uses
computers to improve productivity."

Consider the Schema XML File in the following format:


<?xml version="1.0" encoding="UTF-8"?><CompetencyList><Competency><id></id><name></name><description></description></Competency></CompetencyList>

Value for the field XPath of Record Identifier in XSD is given as CompetencyList/Competency.

After it is processed by the CSV to XML converter, the XML output appears in the following format:
<?xml version="1.0" encoding="UTF-8"?><CompetencyList><Competency><id>Role Specific</id><name>Computer Skills</name><description>Skilled in the use of
computers, adapts to new technology, keeps abreast of changes, learns new programs quickly, uses computers to improve
productivity.</description></Competency></CompetencyList>

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 20
Converter: XML to CSV

If you have an input message in XML format, you need to convert it into
CSV format to use it in the subsequent steps of the integration flow. You
can use the XML to CSV converter to achieve this message
transformation.

In the Properties view, enter the details based on the descriptions for
the fields given in the table below.
1• Provide the Xpath of the Source element which you want to convert
to the CSV

• XPath in the XML Schema File where the content from CSV has to
be placed.
2
• Field Separator for the CSV file. Each element will be separated
with the Field Separator in the output file
3
• Click on the checkbox if you want the element names of the XML in
the output file
1
2
3

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 21
Converter: XML to CSV example
Example

Consider a XML file that is in the following format:

Value for the field path for the source element.

ns1:MT_SalesOrder_Target/OrderSummary

After it is processed by the XML to CSV converter, the CSV output appears in the following format:

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 22
Converter: XML to JSON
If you have an input message in XML format, you need to convert it into JSON format to use it
in the subsequent steps of the integration flow. You can use the XML to JSON converter to
achieve this message transformation.

In the Properties view, enter the details based on the descriptions for the fields given in the
table below.

1• Enter the name of the Convertor step.

Mapping of XML namespace to the JSON prefix. These parameters are only filled if “Use
2• Namespace mapping” is selected. The JSON namespace/prefix must start with a letter
and can contain 0-9,aA-zZ.

3• JSON prefix separator to separate the JSON prefix from local part. Colon(:), Comma (,),
Dot(.), Pipe(|), Semicolon(;) and space( ) are supported. The value used must never be
used in the JSON prefix or local name

4• Enter the JSON output encoding. The default value is from Header or Property.

5• Streaming: Click on checkbox for large xml messages. The streaming has the option of
converting all or specific elements of incoming XML document.
6
• Each individual tag of an XML document is processed consecutively, one after the other,
independent from where in the overall structure the tag occurs and how often it occurs in
the structure (multiplicity).

6
• Choose this option to create the JSON message without the root element tag.

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 23
Converter: XML to JSON

The conversion from XML to JSON follows the following rules

 Elements with mixed content (for example. <A>mixed1_value<B>valueB</B>mixed2_value</A>) are not supported. You will get incorrect
results for XML to JSON: {"A":{"B":"valueB","$":"mixed1_valuemixed2_value"}}.

 No namespace declaration is written into the JSON document

 Tabs, spaces, and new lines between elements and attributes are ignored

 If you have an element with a namespace but without an XML prefix whose namespace is not contained in the XML-Namespace-to-JSON-
Prefix map, you get an exception: <A xmlns="http://test"/> -> IllegalStateException Invalid JSON namespace: http://test.

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 24
Converter: JSON to XML

If you have an input message in JSON format, you need to convert it


into XML format to use it in the subsequent steps of the integration flow.
You can use the JSON to XML converter to achieve this message
transformation.

In the Properties view, enter the details based on the descriptions for
the fields given in the table below.

1• Enter the Name of the convertor step.

• Mapping of XML namespace to the JSON prefix. These parameters


2 are only filled if “Use Namespace mapping” is selected. The JSON
namespace/prefix must start with a letter and can contain 0-9,aA-zZ
1
3• JSON prefix separator to separate the JSON prefix from local part.
Colon(:), Comma (,), Dot(.), Pipe(|), Semicolon(;) and space( ) are
supported. The value used must never be used in the JSON prefix
2
or local name

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 25
Converter: JSON to XML

The conversion from JSON to XML follows the following rules

• The result XML document is encoded in UTF-8 and gets the XML header "<?xml version='1.0' encoding='UTF-8'?>".

• The content of the XML-Namespace-to-JSON-Prefix map is transformed to namespace prefix declarations on the root element.

• A member with a JSON null value is transformed to an empty element, for example, "C":null -> <C/>.

• Conversion of "@attr":null to XML is not supported (you get a NullPointerException).

• If no XML namespace is defined for a JSON prefix, the full member name with the prefix and JSON delimiter is set as the element name:
"p:A" -> <p:A>.

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 26
Script

This Process Step is used to execute a java or groovy script for message processing or transformation.

Two types of scripts are supported


1) Java Script
2) Groovy Script.

The script can be added in the integration process as a message


transformation step.
Using Select, an existing script can be selected.

Eclipse:
If a script is already available, we can assign the script by selecting Assign
Script from the context menu of the Script step
If the script doesn’t exist, we can create a New Script from the context
menu of the Script step.
All the Scripts should be imported in the folder src.main.resources.script
under the project.

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 27
Script: Groovy
This Process Step is used to execute custom groovy script for message processing

In the script you require Script Function which will be executed at runtime. You can
specify a custom function which will take “message” object as argument. The function
definition is as follows:
import com.sap.gateway.ip.core.customdev.util.Message;

def Message processData(Message message) {

def body = message.getBody();

message.setBody(body + "enhancements"); //modify body

def map = message.getHeaders(); //modify headers

def value = map.get("oldHeader");

message.setHeader("oldHeader", value + "modified");

message.setHeader("newHeader", "headerValue");

map = message.getProperties(); //modify properties

value = map.get("oldProperty");

message.setProperty("oldProperty", value + "modified");

message.setProperty("newProperty", "script");

return message;}

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 28
Script
You can add or modify Header, Body and Property using below interfaces on the "message" object.

• You can use the following interfaces for Header:


• public java.util.Map<java.lang.String,java.lang.Object> getHeaders()

• public void setHeaders(java.util.Map<java.lang.String,java.lang.Object> exchangeHeaders)

• public void setHeader(java.lang.String name, java.lang.Object value)

• You can use the following interfaces for Body:


• public java.lang.Object getBody()

• public void setBody(java.lang.Object exchangeBody)

• You can use the following interfaces for Property:


• public java.util.Map<java.lang.String,java.lang.Object> getProperties()

• public void setProperties(java.util.Map<java.lang.String,java.lang.Object> exchangeProperties)○

• public void setProperty(java.lang.String name, java.lang.Object value)

Note: You should not add or modify Property name starting with sap.

. © 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 29
© 2016 SAP SE or an SAP affiliate company. All rights reserved.

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an
SAP affiliate company.

SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE
(or an SAP affiliate company) in Germany and other countries. Please see http://global12.sap.com/corporate-en/legal/copyright/index.epx for additional trademark
information and notices.

Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors.

National product specifications may vary.

These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP SE or its
affiliated companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP SE or
SAP affiliate company products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing
herein should be construed as constituting an additional warranty.

In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop or
release any functionality mentioned therein. This document, or any related presentation, and SAP SE’s or its affiliated companies’ strategy and possible future
developments, products, and/or platform directions and functionality are all subject to change and may be changed by SAP SE or its affiliated companies at any time for
any reason without notice. The information in this document is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. All forward-
looking statements are subject to various risks and uncertainties that could cause actual results to differ materially from expectations. Readers are cautioned not to place
undue reliance on these forward-looking statements, which speak only as of their dates, and they should not be relied upon in making purchasing decisions.

© 2016 SAP SE or an SAP affiliate company. All rights reserved. Early Knowledge Transfer Customer 30

Das könnte Ihnen auch gefallen