cancel
Showing results for 
Search instead for 
Did you mean: 

Need to get the Mail attachment name as it is to the receiver file adapter

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (2)

Answers (2)

stefan_grube
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

VijayKonam
Active Contributor
0 Kudos

If you are working with sender mail adapter.. YES.

VJ

stefan_grube
Active Contributor
0 Kudos

Besides the import statements, there is no change inside the code.

Check this blog:

/people/stefan.grube/blog/2008/12/11/adjust-your-pi-70-adapter-modules-for-pi-71-in-15-minutes

Former Member
0 Kudos

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

Former Member
0 Kudos

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

VijayKonam
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

stefan_grube
Active Contributor
0 Kudos

The myFileName in your code is not initialized.

add this line of code in your catch block

} catch (Exception e) {

throw new ModuleException(e);

}

or something like this.

Former Member
0 Kudos

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.

stefan_grube
Active Contributor
0 Kudos

Again: You have not initialized "myFileName".

You can use the 7.0 code, there is no need to change.

Former Member
0 Kudos

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

Former Member
0 Kudos

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

VijayKonam
Active Contributor
0 Kudos

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

VijayKonam
Active Contributor
0 Kudos

Does any one have a work around for Module testing even before deploying it on to the XI server?

Where can one get the message data for static testing on the XI server? Did anyone try writing the message data to disk from with in a module?

VJ