Hello,
We are working on sending a zip file containing image and a xml from source to R3 system. Sender adapter is MQ, Receiver is through Proxy.
Java zip class is used at mappings, But we are facing an error at inbound side. This is the below error we are facing : It says runtime application mapping error.
" Runtime exception occurred during application mapping dk/post/xi/dmsreadsoft/DmsReadsoft; Caused by: java.lang.NullPointerException: while trying to get the length of an array loaded from local variable 'buf' at java.io.ByteArrayInputStream.<init>(ByteArrayInputStream.java:89) at dk.post.xi.dmsreadsoft.DmsReadsoft.createInputFile(DmsReadsoft.java:48) at dk.post.xi.dmsreadsoft.DmsReadsoft.execute(DmsReadsoft.java:78) at com.sap.aii.ib.server.mapping.execution.TransformationWrapper.transform(TransformationWrapper.java:39) at com.sap.aii.ib.server.mapping.execution.JavaMapping.executeStep(JavaMapping.java:92) ... "
But more interesting is, we are not able to know why when we placed just ONE zip file in MQ and sent to PI, There are four messages seen at our monitor transaction and RWB communication channel, Don't know how 4 messages are seen. Is it something due to four cluster nodes at JMS communication channel ? Probably that's why the mapping is failing ?
This is the Java code implemented.
package dk.post.xi.dmsreadsoft;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import java.util.Properties;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
import com.sap.aii.mapping.api.MappingTrace;
import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationConstants;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.engine.lib.xml.util.SAXToDocHandler;
import com.sap.engine.lib.xsl.xslt.output.DocHandlerSerializer;
/**
* @author Kenneth Reinhardt
*
* Created on Sep 28, 2004
*
* This class converts an HTMl formattet email to a structured XML document.
* The format of the email is descripted in the technical documentatian
*
*/
public class DmsReadsoft implements StreamTransformation {
private static final String empty = "";
private Map parms;
MappingTrace mappingTrace;
/* (non-Javadoc)
* @see com.sap.aii.mapping.api.StreamTransformation#setParameter(java.util.Map)
*/
public void setParameter(Map parms) {
this.parms = parms;
mappingTrace = (MappingTrace) parms.get(StreamTransformationConstants.MAPPING_TRACE);
}
private InputStream createInputFile(byte[] text) throws IOException {
return new ByteArrayInputStream(text);
}
/* (non-Javadoc)
* @see com.sap.aii.mapping.api.StreamTransformation#execute(java.io.InputStream, java.io.OutputStream)
* Main method
*/
public final void execute(InputStream in, OutputStream out) throws StreamTransformationException {
ReadsoftZipFile rzf = new ReadsoftZipFile(in, this.mappingTrace);
Properties properties = new Properties();
properties.setProperty("encoding", "ISO-8859-1");
Attributes attr = new AttributesImpl();
// if (false) { // Do it the old way or the new way?
try {
DocHandlerSerializer dhs = new DocHandlerSerializer(out, properties);
dhs.setOutputStream(out);
ContentHandler writer = new SAXToDocHandler(dhs);
// Write start of file
writer.startDocument();
writer.startElement("", "", "zipfile", attr);
// Create a temp file and write to it to get an input file for the XML parser.
// This is done to the fact that the parser only can parse from an InputStream (not cool).
// InputStream is = createInputFile(rzf.getXML(), tmpfile);
InputStream is = createInputFile(rzf.getXML());
ReadsoftIOHandler rioh = new ReadsoftIOHandler(is, writer, false);
writer.startElement("", "", "imagebase64", attr);
char[] base64data = rzf.getTiffBase64Char();
writer.characters(base64data, 0, base64data.length);
writer.endElement("", "", "imagebase64");
writer.endElement("", "", "zipfile");
writer.endDocument();
out.close();
} catch (javax.xml.parsers.ParserConfigurationException e) {
debug(e.toString());
e.printStackTrace();
throw new StreamTransformationException("ParserConfigurationException thrown", e);
} catch (IOException e) {
debug(e.toString());
e.printStackTrace();
throw new StreamTransformationException("IOException thrown", e);
} catch (SAXException e) {
debug(e.toString());
e.printStackTrace();
throw new StreamTransformationException("SAXException thrown", e);
}
debug("DmsReadsoft terminating with Success!");
}
/**
* Write debug to correct debug destination
*/
public void debug(String s) {
if (mappingTrace != null) {
mappingTrace.addInfo("Debug: " + s);
} else {
System.out.println("Debug: " + s);
}
}
/**
* Method only used for developing purposes
*/
public static void main(String[] args) {
DmsReadsoft x = new DmsReadsoft();
try {
if (args != null && args.length >= 2) {
x.execute(new FileInputStream(new File(args[0])), new FileOutputStream(new File(args[1])));
} else {
System.out.println("Warning: Missing args\n\nUsage:\nDmsReadsoft inputfile.txt outputfile.xml\n\n using defaults: 20041203-2.zip and output.xml");
x.execute(new FileInputStream(new File("XR843000.zip")), new FileOutputStream(new File("output.xml")));
}
} catch (Exception e) {
System.out.println("Error using files: " + e);
}
}
}
Can you please let us know on this ? And why we are able to see 4 messages instead of one ?