Skip to Content
0
Former Member
Oct 26, 2009 at 10:39 PM

Issue with java mapping in a multi-mapping scenario

28 Views

Hi

We have a 1:n multiple mapping scenario in XI and the source is R3 proxy and target side is files. So, creating multiple file from a single message from R3 .

R3 --> XI --> Multiple files

Structure of the output of the multi-mapping is

- http://sap.com/xi/XI/SplitAndMerge">

- <ns0:Message1>

<Transaction>

</Transaction>

<Transaction>

</Transaction></ns0:Message1>

</ns0:Messages>

wherein each Transaction node represents a file.

Now, we need to introduce a constant /string like

http://dtd.XXXXXXX.com/dtds/ReceiptAuthorization.dtd\">

on each of the files at the very beginning - i.e within each transaction node , in the above structure, we need the above DTD string to be written. To do this, we added a java mapping as the second mapping after the message mapping that creates this string. Is this the right approach and would it produce what we are expecting ?

********************************************************************************************************************************************

import java.io.BufferedReader;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.io.OutputStream;

import java.util.Map;

import com.sap.aii.mapping.api.StreamTransformation;

import com.sap.aii.mapping.api.StreamTransformationException;

import com.sap.aii.mapping.api.StreamTransformationConstants;

import com.sap.aii.mapping.api.DynamicConfiguration;

import com.sap.aii.mapping.api.AbstractTrace;

public class ModifyRootAndDelay implements StreamTransformation {

AbstractTrace myTrace;

public void execute(InputStream input, OutputStream output) throws StreamTransformationException {

try{

BufferedReader reader = new BufferedReader(new InputStreamReader(input));

String NameSpacePrefix = "http://dtd.innotrac.com/dtds/ReceiptAuthorization.dtd\">";

String sLine = null;

StringBuffer XmlMsg= new StringBuffer();

String Result,PayloadBody;

int indexOfFirst;

while ((sLine = reader.readLine()) != null) {

XmlMsg.append(sLine);

}

String StartingTag = XmlMsg.toString();

indexOfFirst = StartingTag.indexOf("<MerchantID>") ;

PayloadBody=new String(XmlMsg.substring(indexOfFirst));

Result=NameSpacePrefix.concat(PayloadBody);

output.write(Result.getBytes());

/* Thread.sleep(200000); */

}catch(Exception e){

myTrace.addWarning("Exception raised in the JavaMapping:modifyNamespace.java""\n The Exception Message: " e.getMessage());

throw new RuntimeException(e.getMessage()) ;

}

} public void setParameter(Map param) {

myTrace = (AbstractTrace) param

.get(StreamTransformationConstants.MAPPING_TRACE);

}

}