com.sap.aii.mapping.api

Interface StreamTransformation


public interface StreamTransformation

Each XI Java mapping program must implement this interface. The implementing class needs a default constructor. For each message a new instance is created with the default constructor. Afterwards setParameter(java.util.Map) is called before execute(InputStream, OutputStream) is called.

Example The following example shows how the MAPPING_TRACE and RECEIVER_NAME parameters are set and evaluated in a Java mapping program:

 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.Map;
 import java.util.HashMap;
 import com.sap.aii.mapping.api.AbstractTrace;
 import com.sap.aii.mapping.api.StreamTransformation;
 import com.sap.aii.mapping.api.StreamTransformationConstants;
 
 public class JavaMapping implements StreamTransformation {
 
   private Map param = null;
 
   private AbstractTrace trace = null;
 
   public void setParameter(Map param) {
     this.param = param;
   }
 
   public void execute(InputStream in, OutputStream out) throws StreamTransformationException {
     // ...
     trace = (AbstractTrace) param.get(StreamTransformationConstants.MAPPING_TRACE);
     trace.addInfo("...");
 
     // ...
     String receiverName = (String) param.get(StreamTransformationConstants.RECEIVER_NAME);
 
     // ...  
   }
 }
 

It is possible that different instances of the implementing class are executed in parallel in different Threads. Take care about this when using static fields or static methods. Java mapping programs are not permitted to be stateful. It is not permitted to perform actions such as writing data to a database table during a Java mapping. The Integration Server cannot track such side effects. Therefore, if an attempt is made to resend a message that has not been received by the receiver, the data may inadvertently be written to the database twice in a Java mapping. Note also that you cannot call java.lang.System.exit() or java.lang.System.setProperties() within a Java mapping and that you cannot use a ClassLoader in the classes of an imported archive. For reading files from an imported Archive getClass().getResourceAsStream(String name) can be used.


Method Summary
 void execute(InputStream in, OutputStream out)
          Is called from the rumtime after executing setParameter(java.util.Map).
 void setParameter(Map param)
          Is called from the rumtime after executing the default constructor and before calling execute(InputStream, OutputStream).
 

Method Detail

setParameter

public void setParameter(Map param)
Is called from the rumtime after executing the default constructor and before calling execute(InputStream, OutputStream). A java.util.Map is passed that contains an AbstractTrace, values of the message header and since SAP NetWeaver '04 SPS 14 a DynamicConfiguration. As a key for reading values fromthe java.util.Map param the constants in StreamTransformationConstants can be used.

Example:
(AbstractTrace)param.get(StreamTransformationConstants.MAPPING_TRACE);

Parameters:
param - java.util.Map, containing an AbstractTrace, values of the MessageHeader and since SAP NetWeaver '04 SPS 14 a DynamicConfiguration.

execute

public void execute(InputStream in,
                    OutputStream out)
             throws StreamTransformationException
Is called from the rumtime after executing setParameter(java.util.Map). This method contains an java.io.InputStream for the source document and an java.io.OutputStream for the target document as parameters. These streams are usually XML documents. The target document must be written in the passed java.io.OutputStream out. For parsing XML document javax.xml.parsers.SAXParser or javax.xml.parsers.DocumentBuilder can be used. During converting bytes to java.lang.String or java.lang.String to bytes take care about the encoding.
A StreamTransformationException indicates a problem . The message than gets an error state in the pipeline.

Parameters:
in - source document
out - target document to fill
Throws:
StreamTransformationException - indicates a problem during execution of the mapping program
See Also:
SAXParser, DocumentBuilder


Copyright 2006 SAP AG. 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 AG. The information contained herein may be changed without prior notice. Microsoft, Windows, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. Oracle is a registered trademark of Oracle Corporation. UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group. Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc. HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C, World Wide Web Consortium, Massachusetts Institute of Technology. Java is a registered trademark of Sun Microsystems, Inc. JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape. MaxDB is a trademark of MySQL AB, Sweden. SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary. These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group 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.