on 01-20-2009 3:17 PM
Hi All,
I want to dynamically set the name of attachment in receiver mail Communication Channel.
Example: IN__9907211000004_4048454000005_20081211_01000000002643
The first two numbers 9907211000004 & 4048454000005 I want to read it from the message
20081211 this is the date and
And againg this number 01000000002643 is read from message.
What is the procedure to create Adapter Module? I am new to Adapter Module.
Any Ideas ideas?
Thank You,
Mukhtar
Have a look at this WiKi too...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,
this is pretty easy with an adapter module
for a start with adapter modules have a look at guides on:
http://mypigenie.com/adapter-modules
Regards,
Michal Krawczyk
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Michal,
why don't you share your knowledge in SDN WIKI?
I have put the source of an adapter module there.
It takes the filename from the ASM,A but can easily be changed for different needs.
https://www.sdn.sap.com/irj/scn/wiki?path=/display/xi/adapterModulePI7.0SetAttachmentName
Regards
Stefan
Hi Michal,
I had a look to your blog and tried to modify according to my requirement.
Here is the code
import javax.ejb.CreateException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import com.sap.aii.af.mp.module.*;
import com.sap.aii.af.ra.ms.api.*;
/**
@ejbHome <{com.sap.aii.af.mp.module.ModuleHome}>
@ejbLocal <{com.sap.aii.af.mp.module.ModuleLocal}>
@ejbLocalHome <{com.sap.aii.af.mp.module.ModuleLocalHome}>
@ejbRemote <{com.sap.aii.af.mp.module.ModuleRemote}>
@stateless
*/
public class SetAttachmentName implements SessionBean, Module{
private SessionContext myContext;
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{
try {
Message msg = (Message) moduleData.getPrincipalData();
//creating parsable XML document
InputStream XIStreamData = null;
XMLPayload xmlpayload = msg.getDocument();
XIStreamData = xmlpayload.getInputStream();
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse(XIStreamData);
//finding the tag's name from the Modules tab in the Directory that will hold the attachment's name
String SenderIDTag = null;
SenderIDTag = moduleContext.getContextData("SenderIDTag");
//finding the content of the tag that will be used as the attachment's name (assuming it's the only tag with this name)
Element element = doc.getDocumentElement();
NodeList list = doc.getElementsByTagName(SenderIDTag);
mailFileName += "_" + list.item(0).getFirstChild().toString();
String anIDTag = null;
ReceiverIDTag = moduleContext.getContextData("ReceiverIDTag");
element = doc.getDocumentElement();
list = doc.getElementsByTagName(ReceiverIDTag);
mailFileName += "_" + list.item(0).getFirstChild().toString();
Date date= new Date(System.currentTimeMillis());
//Add date to the Message
SimpleDateFormat dateFormat= new SimpleDateFormat("yyyyMMdd");
mailFileName += "_" + dateFormat.format(date);
String BillNrTag = null;
BillNrTag = moduleContext.getContextData("BillNrTag");
element = doc.getDocumentElement();
list = doc.getElementsByTagName(BillNrTag);
mailFileName += "_" + list.item(0).getFirstChild().toString();
//creating the attachment
byte by[] = xmlpayload.getText().getBytes();
XMLPayload attachmentXML = msg.createXMLPayload();
attachmentXML.setName(mailFileName);
attachmentXML.setContentType("text/pdf");
attachmentXML.setContent(by);
//adding the message to the attachment
msg.addAttachment(attachmentXML);
inputModuleData.setPrincipalData(msg);
} catch (Exception e) {
throw new ModuleException(e);
}
return inputModuleData;
}
}
I hope this is right Adapter Module coe for my requirement.
Thank you in Advance,
Mukhtar
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
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.