on 12-23-2008 12:10 AM
I am doing a Mail to File scenario. I need to get the attachment from the mail and store it on the file server. I am using the PayloadSwap bean in the sender mail adapter. My requirement is to carry forward the attachement name as it is to the receiver file adapter side and store the file with the same name.
Did any one try doing this? I was looking at developing an adapter module but got struck as I could not find whether the attachement name is stored in the XI payload after it has got swapped using the swap bean.
Any help would be appreciated.
VJ
Try this code:
https://www.sdn.sap.com/irj/scn/wiki?path=/display/xi/adapterModulePI7.0GetAttachmentName
There is no way to test this outside the adapter engine.
Regards
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
This is becoming a damn nightmare. When I run the adapter I am getting ModuleExceptions. Can you pass your eyes over these Java config settings to see what I am doing wrong. U
APPLICATION.XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application PUBLIC "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"
"http://java.sun.com/dtd/application_1_3.dtd">
<application>
<display-name>MailPOP_EAR</display-name>
<description>EAR description</description>
<module>
<ejb>MailPOP_EJB.jar</ejb>
</module>
</application>
APPLICATION-J2EE-ENGINE.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application-j2ee-engine SYSTEM "application-j2ee-engine.dtd">
<application-j2ee-engine>
<reference reference-type="hard">
<reference-target provider-name="sap.com" target-type="service">engine.security.facade</reference-target>
</reference>
<reference reference-type="hard">
<reference-target provider-name="sap.com" target-type="library">engine.j2ee14.facade</reference-target>
</reference>
<reference reference-type="hard">
<reference-target provider-name="sap.com" target-type="service">com.sap.aii.af.svc.facade</reference-target>
</reference>
<reference reference-type="hard">
<reference-target provider-name="sap.com" target-type="interface">com.sap.aii.af.ifc.facade</reference-target>
</reference>
<reference reference-type="hard">
<reference-target provider-name="sap.com" target-type="library">com.sap.aii.af.lib.facade</reference-target>
</reference>
<reference reference-type="hard">
<reference-target provider-name="sap.com" target-type="library">com.sap.base.technology.facade</reference-target>
</reference>
<fail-over-enable mode="disable" />
</application-j2ee-engine>
EJB-J2EE-ENGINE.XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-j2ee-engine SYSTEM "ejb-j2ee-engine.dtd">
<ejb-j2ee-engine>
<enterprise-beans>
<enterprise-bean>
<ejb-name>GetMailAttachment</ejb-name>
<jndi-name>GetMailAttachment</jndi-name>
<session-props/>
</enterprise-bean>
</enterprise-beans>
</ejb-j2ee-engine>
EJB-JAR.XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans
2.0//EN"
"http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<description>EJB JAR description</description>
<display-name>EJB JAR</display-name>
<enterprise-beans>
<session>
<ejb-name>GetMailAttachment</ejb-name>
<home>com.sap.aii.af.lib.mp.module.ModuleHome</home>
<remote>com.sap.aii.af.lib.mp.module.ModuleRemote</remote>
<local-home>com.sap.aii.af.lib.mp.module.ModuleLocalHome</local-home>
<local>com.sap.aii.af.lib.mp.module.ModuleLocal</local>
<ejb-class>sample.GetMailAttachment</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
SENDER MAIL ADAPTER modules
1 AF_Modules/PayloadSwapBean Local EB 1
2 GetMailAttachment Local EB 2
3 sap.com/com.sap.aii.adapter.mail.app/XIMailAdapterBean Local EB 3
Oops pressed the send key. Take two.
This is becoming a damn nightmare. When I run the adapter I am getting ModuleExceptions. Can you pass your eyes over these Java config settings to see what I am doing wrong. Using NWDS CE 7.1 with PI 7.1 both at SP07. All the imports were taken from PI 7.1 after SP07 was applied. The build id of NWDS is
SAP NetWeaver Developer Studio
SAP NetWeaver 7.1 Composition Environment SP07 PAT0001
Build id: 200901152336
APPLICATION.XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application PUBLIC "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"
"http://java.sun.com/dtd/application_1_3.dtd">
<application>
<display-name>MailPOP_EAR</display-name>
<description>EAR description</description>
<module>
<ejb>MailPOP_EJB.jar</ejb>
</module>
</application>
APPLICATION-J2EE-ENGINE.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application-j2ee-engine SYSTEM "application-j2ee-engine.dtd">
<application-j2ee-engine>
<reference reference-type="hard">
<reference-target provider-name="sap.com" target-type="service">engine.security.facade</reference-target>
</reference>
<reference reference-type="hard">
<reference-target provider-name="sap.com" target-type="library">engine.j2ee14.facade</reference-target>
</reference>
<reference reference-type="hard">
<reference-target provider-name="sap.com" target-type="service">com.sap.aii.af.svc.facade</reference-target>
</reference>
<reference reference-type="hard">
<reference-target provider-name="sap.com" target-type="interface">com.sap.aii.af.ifc.facade</reference-target>
</reference>
<reference reference-type="hard">
<reference-target provider-name="sap.com" target-type="library">com.sap.aii.af.lib.facade</reference-target>
</reference>
<reference reference-type="hard">
<reference-target provider-name="sap.com" target-type="library">com.sap.base.technology.facade</reference-target>
</reference>
<fail-over-enable mode="disable" />
</application-j2ee-engine>
EJB-J2EE-ENGINE.XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-j2ee-engine SYSTEM "ejb-j2ee-engine.dtd">
<ejb-j2ee-engine>
<enterprise-beans>
<enterprise-bean>
<ejb-name>GetMailAttachment</ejb-name>
<jndi-name>GetMailAttachment</jndi-name>
<session-props/>
</enterprise-bean>
</enterprise-beans>
</ejb-j2ee-engine>
EJB-JAR.XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans
2.0//EN"
"http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<description>EJB JAR description</description>
<display-name>EJB JAR</display-name>
<enterprise-beans>
<session>
<ejb-name>GetMailAttachment</ejb-name>
<home>com.sap.aii.af.lib.mp.module.ModuleHome</home>
<remote>com.sap.aii.af.lib.mp.module.ModuleRemote</remote>
<local-home>com.sap.aii.af.lib.mp.module.ModuleLocalHome</local-home>
<local>com.sap.aii.af.lib.mp.module.ModuleLocal</local>
<ejb-class>sample.GetMailAttachment</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
SENDER MAIL ADAPTER modules
1 AF_Modules/PayloadSwapBean Local EB 1
2 GetMailAttachment Local EB 2
3 sap.com/com.sap.aii.adapter.mail.app/XIMailAdapterBean Local EB 3
1 swap.keyName payload-name
1 swap.keyValue MailAttachment-1
RECEIVER FILE MODULES
1 localejbs/AF_Modules/DynamicConfigurationBean Local Enterprise Bean 1
2 localejbs/CallSapAdapter Local Enterprise Bean 2
1 key.0 write http://sap.com/xi/XI/System/File FileName
1 value.0 message.interface
VARIABLE FILENAME SUBST WITH ASMA TURNED ON
fName message:interface_name
JAVA SOURCE
package sample;
import javax.ejb.CreateException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import com.sap.aii.af.lib.mp.module.Module;
import com.sap.aii.af.lib.mp.module.ModuleContext;
import com.sap.aii.af.lib.mp.module.ModuleData;
import com.sap.aii.af.lib.mp.module.ModuleException;
import com.sap.engine.interfaces.messaging.api.Message;
import com.sap.engine.interfaces.messaging.api.MessagePropertyKey;
import com.sap.engine.interfaces.messaging.api.TextPayload;
import com.sap.engine.interfaces.messaging.api.XMLPayload;
import com.sap.aii.af.service.cpa.Channel;
/**
@ejbHome <{com.sap.aii.af.lib.mp.module.ModuleHome}>
@ejbLocal <{com.sap.aii.af.lib.mp.module.ModuleLocal}>
@ejbLocalHome <{com.sap.aii.af.lib.mp.module.ModuleLocalHome}>
@ejbRemote <{com.sap.aii.af.lib.mp.module.ModuleRemote}>
@stateless
*/
/**
<code>GetMailAttachment</code>
*/
@SuppressWarnings("unused")
public class GetMailAttachment implements SessionBean, Module {
private static final long serialVersionUID = 7612238514043673502L;
private SessionContext myContext;
private MessagePropertyKey myFileName;
public void ejbRemove() {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void setSessionContext(SessionContext context) {
myContext = context;
}
/**
@throws CreateException
*/
public void ejbCreate() throws CreateException {
}
public void getMessageProperty(MessagePropertyKey FileName) {
myFileName = FileName;
}
/**
@param moduleContext
Contains data of the module processor that might be important
for the module implementation such as current channel ID
@param inputModuleData
Contains the input XI message as principal data plus eventual
set supplemental data
@return ModuleData Contains the (changed) output XI message. Might be the
response message if the module is the last in the chain.
@exception ModuleException
Describes the cause of the exception and indicates whether
an retry is sensible or not.
*/
@SuppressWarnings("deprecation")
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(myFileName, fileName);
inputModuleData.setPrincipalData(msg);
} catch (Exception e) {
}
return inputModuleData;
}
}
JAVA ERRORS
2009-02-04 11:41:14 Information Mail: calling the module processor for channel LMK_Common_Mail_Sender
2009-02-04 11:41:14 Information Swap: swapping by payload-name ? MailAttachment-1
2009-02-04 11:41:14 Information Swap: successfully swapped
2009-02-04 11:41:14 Information Mail: message leaving the adapter (call)
2009-02-04 11:41:14 Information The application tries to send an XI message asynchronously using connection AFW.
2009-02-04 11:41:14 Information Backward validation is enabled
2009-02-04 11:41:14 Error Unable to validate the message with message ID 8702df71-f254-11dd-9b9b-001a64a73518
2009-02-04 11:41:14 Error Returning to application. Exception: com.sap.engine.interfaces.messaging.api.exception.MessagingException: Content is not allowed in prolog.
2009-02-04 11:41:14 Error Mail: error occured: com.sap.engine.interfaces.messaging.api.exception.MessagingException: Content is not allowed in prolog.
2009-02-04 11:41:14 Error Mail: error occured: com.sap.aii.af.lib.mp.module.ModuleException
Hi,
Tell me what u r trying to do.. so that some one can help. I you are looking ar swapping ur first attachment into payload and it is an xml then you do not need any adapter modules. If you need the name of the attachment, you do need to use. But pay load swap bean must be called before you call this module.
VJ
VJ,
Scenario is as follows. Sending email with CSV attachment and need to capture this file into the file system. Problem being that different files will be emailed with different names so I want to use payloadswapbean to swap to the payload-1 ( this seems to work ) then capture the filename and pass this to the receiver file adapter using dynamicconfigurationbean..
Mike
Stephan,
Ran it again with the extra line in the catch block as you advised and it still failed. Java errors are below.
Error error 2009-02-04 12:32:14:762 exception caught during processing mail message[1]; com.sap.aii.af.lib.mp.module.ModuleException com.sap.aii.af.sdk.xi.srt.xmb.XMBPOPInitiatorServiceImpl.invoke()
Error error 2009-02-04 12:32:14:760 failed to call the adapter engine; caused by com.sap.engine.interfaces.messaging.api.exception.InvalidParamException: One of the parameters is null.
Regards
Mike
java is a four letter word.
Stephan,
You are a god among men. My adapter now appears to have worked after I reverted back to the 7.0 code and ignored the Deprecation warnings, but only when I exported the EAR and JAR files manually ( context right click export options from within NWDS ) and not letting the deploy step create them for me. So I exported the JAR file first then the EAR file, deleted the libs from withing the EAR file then added the EAR to the deploy list.
Again, thanks for the assistance. You should join the OSS gang as I got a quicker and more beneficial response from you.
Regards
Mike Greer
Hi VJ
Looking at your requirement. Is there a possibility that you can get filename for the attachment in content of attachment.
If not then as you are swapping it this will change attachment name.
Did you tried with Dynamic Configuration bean in sender mail adapter. Set the filename properly to attachment name. Give it a try.
In module you should be able to fetch the name and add to payload. As while mapping to target dont pass this. Where did you got stuck ?
Thanks
Gaurav
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The attachemnt is plain text file. I am not even using any repository objects as of now. DynamicConfigurationBean needs to be used as the first module in the module chain. If I do that, after I swap the payload.. it will not be of any use.
By the time the message reaches IE, the name of the attachement is already been changed..
VJ
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.