on 09-19-2016 1:23 PM
Erica,
Firstly you need to add PaylaodSwapBean before then PaylodZip bean , so that the attachment and the mainpayload will be swapped.
Your current configuration is trying to unzip the mail body but not an attachment.
br,
Manoj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As per your screenshot from SXMB_MONI we see only one payload i.e Attachment so as already praveen Suggested you can remove the payloadswap bean . Give it a try and also provide the screenshot of the channel monitoring log which will be helpful to analyze if module execution is happening or not.
Praveen Gandepalli : How can a mail have just an attachment atleast it should have an empty body right ?i mean to say how is it possible to have just one payload
Erica,
Regarding the Custom module you have to download the EAR file mentioned in the blog and then deploy it in your PI system after that only you can use this module.
Search in SCN you will get numerous blogs on how to deploy EAR file.
But wait lets see if any suggestions by any experts beacuse after you add custom module you have next query to unzip only the necessary files not all i.e XML this is but tricky
Br,
Manoj
Hi Erica,
Regards,
Praveen.
What is your PI version, is the note is applicable to your PI version??
I am in SAP PI 7.4, yes the note is applicable
If yes then each attachment the new PI message will be created
As the image this doesn't happened.
So you can use PayloadZipBean in the receiver channel to unzip
Or if you want unzip and need to do the mapping then you can do it in java mapping
What is your full requirement??
I need to receive a mail with multilple attachments between XMLs and XMLs in a zip file, if we receive the files in a ZIP , I need to extract and identify the XML files.
I already have a java mapping. This java is responsible to identiify some strings in the XMLs, so depend on the string (for example, "nfeProc"), then it is sent to ECC to record this XMLs files in the respectives folders. I tested the interface withou zip files and it is working. But, unfortunately, I don't know JAVA, I got this from an other project, but I believe I should change this java mapping code to do the unzip and continue the java code as is working. What do you think? Can you give some help how I can start the java code do unzip the file? I found some code in scn but I don't know it should be applicable to this function. I requested a JAVA resource in the company to help me, but he doesn't know PI, so he is trying to deal with it, but we don't have any news yet.
My actual java function:
package com.b2b.inbound.att;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
//import javax.xml.soap.Node;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
//import org.omg.CORBA.DynamicImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
//import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import org.xml.sax.SAXException;
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.InputAttachments;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
//import com.sap.aii.mapping.api.OutputAttachments;
//import com.sap.aii.mapping.api.DynamicConfiguration;
import com.sap.aii.mapping.api.StreamTransformationConstants;
public class GetAttachments extends AbstractTransformation{
InputStream in = null;
OutputStream out = null;
String NFe = "";
//Object nfe = "";
public void transform(TransformationInput input, TransformationOutput output)
throws StreamTransformationException {
// TODO Auto-generated method stub
try{
in = input.getInputPayload().getInputStream();
out = output.getOutputPayload().getOutputStream();
InputAttachments ipAtt = input.getInputAttachments();
if (ipAtt.areAttachmentsAvailable()){
Collection<String> colAtt = ipAtt.getAllContentIds(true);
Iterator<String> itAtt = colAtt.iterator();
String attachId = "";
Attachment attach = null;
//monta XML de saida
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transform = tf.newTransformer();
//Cria escopo do XML
Document docout = db.newDocument();
Element root = docout.createElement("ns0:msgType_MultiAttachments");
root.setAttribute("xmlns:ns0", "http://genmills.com/xi/Mail/Inbound");
docout.appendChild(root);
while(itAtt.hasNext()){
attachId = itAtt.next();
attach= ipAtt.getAttachment(attachId);
String attType = "";
attType = attach.getContentType();
if (attType.contains("xml")){
NFe = this.getUTF8(attach.getContent());
String accessKey = "";
accessKey = NFe.substring(NFe.indexOf("<chNFe>")+7,NFe.indexOf("<chNFe>")+51);
//OutputAttachments outAtt = output.getOutputAttachments();
//Cria elemento Atachments
Element attachments = docout.createElement("Attachments");
root.appendChild(attachments);
if (NFe.contains("nfeProc")){
//Cria elemento Attachment Name
Element attachmentName = docout.createElement("Attachments_Name");
attachments.appendChild(attachmentName);
Text attachmentNameText = docout.createTextNode("NFe_" +accessKey+ ".xml"); //Cria valor campo
attachmentName.appendChild(attachmentNameText);
}
if (NFe.contains("procEventoNFe")){
//Cria elemento Attachment Name
Element attachmentName = docout.createElement("Attachments_Name");
attachments.appendChild(attachmentName);
Text attachmentNameText = docout.createTextNode("Event_" +accessKey+ ".xml"); //Cria valor campo
attachmentName.appendChild(attachmentNameText);
}
if (NFe.contains("cteProc")){
accessKey = NFe.substring(NFe.indexOf("<chCTe>")+7,NFe.indexOf("<chCTe>")+51);
//Cria elemento Attachment Name
Element attachmentName = docout.createElement("Attachments_Name");
attachments.appendChild(attachmentName);
Text attachmentNameText = docout.createTextNode("CTe_" +accessKey+ ".xml"); //Cria valor campo
attachmentName.appendChild(attachmentNameText);
}
if (NFe.contains("eventoCTe")){
accessKey = NFe.substring(NFe.indexOf("<chCTe>")+7,NFe.indexOf("<chCTe>")+51);
//Cria elemento Attachment Name
Element attachmentName = docout.createElement("Attachments_Name");
attachments.appendChild(attachmentName);
Text attachmentNameText = docout.createTextNode("EventCTe_" +accessKey+ ".xml"); //Cria valor campo
attachmentName.appendChild(attachmentNameText);
}
//Cria elemento Attachment Content
Element attachmentContent = docout.createElement("Attachments_Content");
attachments.appendChild(attachmentContent);
//Text attachmentContentText = docout.createTextNode(attType); //Cria valor campo
Text attachmentContentText = docout.createTextNode(NFe); //Cria valor campo
attachmentContent.appendChild(attachmentContentText);
}
}
DOMSource domS = new DOMSource(docout);
transform.transform((domS), new StreamResult(out));
itAtt = null;
colAtt = null;
}
//Tranforma mensagem de entrada em String
String inptxml = this.stream2string(in);
String fileName = "";
Document docIn = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(inptxml.getBytes("utf-8")));
org.w3c.dom.Node from = docIn.getElementsByTagName("From").item(0).getFirstChild();
fileName = from.toString();
//Dynamic Configuration para setar o nome do arquivo
Map mapParameters = (Map) input.getInputHeader().getAll();
mapParameters.put(DynamicConfigurationKey.create("http://sap.com/xi/XI/Dynamic", StreamTransformationConstants.DYNAMIC_CONFIGURATION), "");
DynamicConfiguration conf = (DynamicConfiguration) mapParameters.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
conf.put(key, (fileName + ".xml"));
} catch (ParserConfigurationException e) {
// TODo Auto-generated catch block
e.printStackTrace();
} catch (TransformerConfigurationException e) {
// TODo Auto-generated catch block
e.printStackTrace();
} catch (TransformerException e) {
// TODo Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODo Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODo Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODo Auto-generated catch block
e.printStackTrace();
}
}
private String stream2string (InputStream _in){
BufferedReader inpxml = new BufferedReader(new InputStreamReader(in));
StringBuffer buffer = new StringBuffer();
String line = "";
try {
while ((line = inpxml.readLine()) != null) {
buffer.append(line);
}
} catch (IOException e) {
e.printStackTrace();
}
String inptxml = buffer.toString();
return inptxml;
}
public String byte2String(byte[] _bytes)
{
String file_string = "";
for(int i = 0; i < _bytes.length; i++)
{
file_string += (char)_bytes[i];
}
return file_string;
}
private String getUTF8(byte[] Content){
String ret;
try {
ret = new String(Content, "UTF-8");
} catch (UnsupportedEncodingException e) {
ret = "";
}
return ret;
}
}
Regards
Erica
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.