on 02-18-2016 11:06 AM
Hi,
Can any one throw some light on this..
thanks in advance,
Irfan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nitin,
*****************************************************************************************************************************************
Regards
Hi Shaik,
Based on the error message you used the wrong Document interface in the java mapping, it should be org.w3c.dom.Document not javax.swing.text.Document.
Java mapping com//addAttachment has thrown a StreamTransformationException. Thrown: com.sap.aii.mapping.api.StreamTransformationException: Cannot cast class com.sun.org.apache.xerces.internal.dom.DocumentImpl to interface javax.swing.text.Document at com.addAttachment.transform(addAttachment.java:63)
import java.io.InputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.Attachment;
import com.sap.aii.mapping.api.DynamicConfiguration;
import com.sap.aii.mapping.api.DynamicConfigurationKey;
import com.sap.aii.mapping.api.OutputAttachments;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
Make sure above import statements in your java mapping.
Regards,
Praveen.
Hi Shaik,
Use below java mapping, instead of hard coding the target xml in the code, you can use DOM parser to generate the xml.
public class AddAttachmentJavaMap extends AbstractTransformation {
@Override
public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput)
throws StreamTransformationException {
try {
DynamicConfiguration conf = transformationInput.getDynamicConfiguration();
DynamicConfigurationKey FILE_NAME_KEY = DynamicConfigurationKey
.create("http://sap.com/xi/XI/System/File", "FileName");
String fileName = conf.get(FILE_NAME_KEY);
OutputAttachments outputAttachments = transformationOutput.getOutputAttachments();
InputStream inputStream = transformationInput.getInputPayload().getInputStream();
byte[] b = new byte[inputStream.available()];
inputStream.read(b);
Attachment newAttachment = outputAttachments.create(fileName, "application/excel", b);
outputAttachments.setAttachment(newAttachment);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
factory.setIgnoringElementContentWhitespace(true);
Document outputDoc = builder.newDocument();
Element outMsgType = outputDoc.createElement("ns0:MT_Payload");
outMsgType.setAttribute("xmlns:ns0", "http://test.com/test");
outputDoc.appendChild(outMsgType);
Element fileNameElement = outputDoc.createElement("FileName");
fileNameElement.setTextContent(fileName);
outMsgType.appendChild(fileNameElement);
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
transformer.setOutputProperty("indent", "yes");
DOMSource source = new DOMSource(outputDoc);
StreamResult result = new StreamResult(transformationOutput.getOutputPayload().getOutputStream());
transformer.transform(source, result);
} catch (Exception e) {
getTrace().addDebugMessage(e.getMessage());
throw new StreamTransformationException(e.getMessage());
}
}
Regards,
Praveen.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
fresult = fresult.concat("<ns0:MT_Payload xmlns:ns0=\"http://test.com/test");
Missing ">" at the end of the line
it should be
fresult = fresult.concat("<ns0:MT_Payload xmlns:ns0=\"http://test.com/test\">");
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ganesh,
Thanks for the reply.
Stuck up with another work,so delay in response.
I had changed to fresult = fresult.concat("<ns0:MT_Payload xmlns:ns0=\"http://test.com/test\">");.
But now i am facing the following error
Kindly help.
Regards,
Irfan
User | Count |
---|---|
84 | |
25 | |
12 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.