on 12-16-2010 5:57 PM
Dear sirs,
I need to process several attachments at the same mail message as individual payloads.
In default configuration of sender mail adapter only the body of message is used as payload.
So I added PayloadSwapBean Module at Processing Sequence and it processed the attachment I set in Module Configuration. I'm not able to process all attachments available, just one attachment is sent to PI pipeline.
How can I process all attachments of a single mail message?
Thank you in advance.
Fabio Purcino
Fabio,
to be able to process multiple attachment in the same Mail Message you need to develop a custom adapter module that iterate over the attachments and output a xml message containing all the attachments as one XML message (as shown below).
<Mail>
<Attachments>
<Attachment>
<Attachment_Name>textfile.txt</Attachment_Name>
<Attachment_Content>Lorem ipsum dolor....</Attachment_Content>
....
</Attachments>
</Attachments>
</Mail>
The java code will be something like this:
import com.sap.aii.af.ra.ms.api.Message;
...
public ModuleData process(ModuleContext moduleContext, ModuleData inputModuleData)
throws ModuleException {
...
Message msg = (Message)inputModuleData.getPrincipalData();
Iterator itr = msg.getAttachmentIterator();
while(itr.hasNext()) {
//Handle Attachment
Payload payload = (Payload) itr.next();
}
...
}
Then, you do a Multi-mapping to split all the Attachments into single messages.
References:
Adapter Module PI 7.0: http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/02706f11-0d01-0010-e5ae-ac25e74c4...
Adapter Module PI 7.1: http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/c0b39e65-981e-2b10-1c9c-fc3f8e674...
Multi-mapping: http://help.sap.com/saphelp_nw04/helpdata/en/21/6faf35c2d74295a3cb97f6f3ccf43c/content.htm
Best regards,
JN
Edited by: Jose Nunes on Dec 16, 2010 4:33 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear sirs,
I developed a custom adapter module to merge all attachments and it works fine.
But I'm having troubles while doing multimapping. Usually I develop multimapping to many diferent message types, but I need several messages from the same message type to be sent to a comm. channel individually.
So each tag <Attachment_Content> should be sent as a new payload to the back-end.
Is it possible to do it without BPM in NW PI 7.0?
Following is a printscreen from my mapping test. I couldn't multiply the messages based on context change of tag <Attachment>
[http://img35.imageshack.us/img35/5674/pimultimapping.jpg]
Thank you in advance.
Fabio Purcino
Hi Jose,
We are trying to implement reading multiple attachment in sender mail adapter.
Our Requirement is : Reading a mail having multiple .xls files. This should be read and converted to payload .
package multiswap;
//import com.sap.aii.adapter.xi.ms.XIMessage;
import com.sap.aii.af.lib.mp.module.*;
import com.sap.aii.af.lib.trace.Trace;
import com.sap.aii.af.sdk.xi.mo.Message;
import com.sap.aii.af.sdk.xi.mo.MessageContext;
import com.sap.aii.af.sdk.xi.mo.xmb.XMBMessageOperator;
import com.sap.aii.af.sdk.xi.mo.xmb.XMBPayload;
import com.sap.aii.af.sdk.xi.util.PayloadType;
import com.sap.aii.af.service.auditlog.Audit;
import com.sap.aii.af.service.cpa.*;
import com.sap.engine.interfaces.messaging.api.MessageDirection;
import com.sap.engine.interfaces.messaging.api.MessageKey;
import com.sap.engine.interfaces.messaging.api.Payload;
import com.sap.engine.interfaces.messaging.api.auditlog.AuditLogStatus;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Locale;
import javax.ejb.*;
public class MultiSwapRead
implements SessionBean, Module
{
private static final String VERSION_ID = "$Id: //tc/xpi.af/NW731EXT_07_REL/src/_af_application_ejb_module/ejbm/api/com/sap" +
"/aii/af/app/modules/PayloadSwapBean.java#1 $"
;
private static final Trace TRACE = new Trace("$Id: //tc/xpi.af/NW731EXT_07_REL/src/_af_application_ejb_module/ejbm/api/com/sap" +
"/aii/af/app/modules/PayloadSwapBean.java#1 $"
);
private static final String SIGNATURE_PROCESS = "process(ModuleContext , ModuleData)";
protected Hashtable cachedChannels;
protected SessionContext myContext;
public MultiSwapRead()
{
cachedChannels = new Hashtable();
}
public void ejbRemove()
{
}
public void ejbActivate()
{
}
public void ejbPassivate()
{
}
public void setSessionContext(SessionContext context)
{
myContext = context;
}
public void ejbCreate()
throws CreateException
{
}
public ModuleData process(ModuleContext moduleContext, ModuleData inputModuleData)
throws ModuleException
{
if(TRACE.beLogged(200))
{
TRACE.entering("process(ModuleContext , ModuleData)", new Object[] {
moduleContext, inputModuleData
});
}
ModuleData outputModuleData;
Iterator itr;
outputModuleData = inputModuleData;
String chid = moduleContext.getChannelID();
TRACE.infoT("process(ModuleContext , ModuleData)", ModuleCategories.SAP_MODULE_ROOT, (new StringBuilder()).append("performing payload swap for channel ").append(chid).toString());
LookupManager lman = LookupManager.getInstance();
Channel chan = null;
try {
chan = (Channel)LookupManager.getInstance().getCPAObject(CPAObjectType.CHANNEL, chid);
} catch (CPAObjectNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (CPAException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Direction direction = chan.getDirection();
String swapkey = moduleContext.getContextData("swap.keyName");
String keyvalue = moduleContext.getContextData("swap.keyValue");
Object obj = inputModuleData.getPrincipalData();
Object pivotedObj = inputModuleData.getSupplementalData("mp.pivoted");
boolean pivoted = pivotedObj == null || !(pivotedObj instanceof Boolean) ? false : ((Boolean)pivotedObj).booleanValue();
Message mo = null;
if(obj instanceof com.sap.engine.interfaces.messaging.api.Message)
{
mo = (Message)((com.sap.engine.interfaces.messaging.api.Message)obj);
} else
if(obj instanceof MessageContext)
{
mo = ((MessageContext)obj).getMessage();
} else
{
TRACE.warningT("process(ModuleContext , ModuleData)", ModuleCategories.SAP_MODULE_ROOT, "no message found");
}
if(mo != null && XMBMessageOperator.numberOfPayloads(mo) > 0)
{
// String midstr = XMBMessageOperator.getMessageId(mo).toString();
MessageKey auditkey = new MessageKey(((com.sap.engine.interfaces.messaging.api.Message) mo).getMessageId(), com.sap.engine.interfaces.messaging.api.MessageDirection.INBOUND);
itr = (Iterator) mo.getAttachments();
if(swapkey != null && keyvalue != null)
{
StringBuffer textSwappingbyBuf = new StringBuffer();
textSwappingbyBuf.append("Swap: swapping by '").append(swapkey).append("' ? '").append(keyvalue).append("'");
String textSwappingby = textSwappingbyBuf.toString();
TRACE.infoT("process(ModuleContext , ModuleData)", ModuleCategories.SAP_MODULE_ROOT, textSwappingby);
Audit.addAuditLogEntry(auditkey, AuditLogStatus.SUCCESS, textSwappingby);
while (itr.hasNext()){
boolean swappedp = swapPayloads(mo, swapkey, keyvalue);
String swappedStatus = swappedp ? "Swap: successfully swapped" : "Swap: no matching payload found";
Audit.addAuditLogEntry(auditkey, AuditLogStatus.SUCCESS, swappedStatus);
}
} else
{
StringBuffer textInvalidBuf = new StringBuffer();
textInvalidBuf.append("Swap: parameter missing ");
if(swapkey == null)
{
textInvalidBuf.append("swap.keyName");
}
if(swapkey == null && keyvalue == null)
{
textInvalidBuf.append(" and ");
}
if(keyvalue == null)
{
textInvalidBuf.append("swap.keyValue");
}
String textInvalid = textInvalidBuf.toString();
TRACE.warningT("process(ModuleContext , ModuleData)", ModuleCategories.SAP_MODULE_ROOT, textInvalid);
Audit.addAuditLogEntry(auditkey, AuditLogStatus.WARNING, textInvalid);
}
} else
{
String messageEmpty = "Swap: message is empty or has no payload";
TRACE.infoT("process(ModuleContext , ModuleData)", ModuleCategories.SAP_MODULE_ROOT, messageEmpty);
}
return outputModuleData;
}
private static boolean swapPayloads(Message mo, String swapkey, String keyvalue)
{
swapkey = swapkey.toUpperCase(Locale.ENGLISH);
keyvalue = keyvalue.toUpperCase(Locale.ENGLISH);
int ifound = -1;
for(int i = 0; i < XMBMessageOperator.numberOfPayloads(mo); i++)
{
XMBPayload pldi = XMBMessageOperator.getPayload(mo, i);
String pldivalue = null;
if(swapkey.equals("PAYLOAD-DESCRIPTION"))
{
pldivalue = pldi.getPayloadDescription();
} else
if(swapkey.equals("PAYLOAD-NAME"))
{
pldivalue = pldi.getPayloadName();
} else
{
pldivalue = pldi.getContentAttribute(swapkey);
}
if(pldivalue == null)
{
continue;
}
pldivalue = pldivalue.toUpperCase(Locale.ENGLISH);
if(pldivalue.indexOf(keyvalue) < 0)
{
continue;
}
ifound = i;
break;
}
if(ifound >= 0)
{
XMBPayload pldfound = XMBMessageOperator.getPayload(mo, ifound);
if(pldfound.getPayloadType() != PayloadType.APPLICATION)
{
XMBPayload pldapp = XMBMessageOperator.getApplicationPayload(mo);
if(pldapp == null)
{
pldfound.setPayloadType(PayloadType.APPLICATION);
} else
{
pldapp.setPayloadType(PayloadType.APPLICATION_ATTACHMENT);
pldfound.setPayloadType(PayloadType.APPLICATION);
}
TRACE.infoT("process(ModuleContext , ModuleData)", ModuleCategories.SAP_MODULE_ROOT, "successfully swapped");
}
return true;
} else
{
TRACE.warningT("process(ModuleContext , ModuleData)", ModuleCategories.SAP_MODULE_ROOT, "no matching found");
return false;
}
}
}
We couldn't go further. Please have a look in highlighted code.
Regards,
Kesava.
Dear sirs,
I developed a custom adapter module to merge all attachments and it works fine.
But I'm having troubles while doing multimapping. Usually I develop multimapping to many diferent message types, but I need several messages from the same message type to be sent to a comm. channel individually.
So each tag
http://img35.imageshack.us/img35/5674/pimultimapping.jpg
Thank you in advance.
Fabio Purcino
Edited by: Fabio Purcino Aragão on Dec 20, 2010 4:44 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Fabio,
In the mapping of the source tag Attachment to MT_Arquivo, use the node function splitByValue.
The mapping:
http://img227.imageshack.us/img227/2357/screenshot20101221at855.png
The result:
http://yfrog.com/f/eqscreenshot20101221at859p/
Best regards,
JN
Or if you're in PI 7.1+, you can use the new Java Mapping API and handle the additional attachments directly within the mapping program.
Best regards,
Henrique.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
74 | |
10 | |
8 | |
7 | |
6 | |
5 | |
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.