Page tree
Skip to end of metadata
Go to start of metadata
/* This adapter module can be used in sender mail adapter.
   It reads the attachment name from the content type of the MIME header and writes it
   to an adapter specific message attribute (ASMA).
   Put this module after the standard mail adapter module
   If the incoming mail has several parts, then the PayloadSwapBean should be used before this module.
*/ 
package sample;
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 GetAttachmentName 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) inputModuleData.getPrincipalData();
         TextPayload payload = msg.getDocument();
         String contentType = payload.getContentType();
         // Content Type could be something like
         // text/plain;charset="UTF-8";name="file.txt"
         contentType = contentType.replaceAll("\"","");
         int i = contentType.lastIndexOf("=") + 1;
         String fileName = contentType.substring(i);
         msg.setMessageProperty("http://sap.com/xi/XI/System/File",
                               "FileName", fileName);
         inputModuleData.setPrincipalData(msg);
    } catch (Exception e) {
         throw new ModuleException(e);
   }

    return inputModuleData;
 }
}
  • No labels

2 Comments

  1. Unknown User (tgpakxy)

    Stephan,

    Can you supply the PI 7.1 version if there are differences. So what you are saying is that the standard mail adapter module goes first in the config, then PayloadSwapBean then the GetAttachment module. I have been using it as SWAP, GETATTACHMENT then the standard Mail adapter.

    Regards

    Mike Greer

  2. Former Member

    Cool....

     

     

    --Divyesh