cancel
Showing results for 
Search instead for 
Did you mean: 

PayloadZipBean - variable filename inside the archive

Former Member
0 Kudos

Hi,

I'm using the Adapter-Specific Message Properties in a sender fileadapter to determine the incoming filename, which has variable components (i.e. date and time). After changing the prefix and suffix in a Message-Mapping the new name is applied in a receiver fileadapter. The new name is now part of the payload in the tag <Filename>. The receiver fileadapter contains the PayloadZipBean to compress the output file, everything works fine.

Now I want the file inside my compressed archive always to have the same name as my archive has. In Stefan Grube's blog about the PayloadZipBean I only found the possibility to choose a fix name by using the MessageTransformBean (name="file.txt").

Example:

1. variable input filename: IN_RNK_20080227_1006.txt

2. filename after Message-Mapping: OUT_RNK_20080227_1006.gz

3. archive filename after receiver adapter: OUT_RNK_20080227_1006.gz

filename inside the archive: MainDocument (this is the default (payload-name))

I would like to name the file inside the archive OUT_RNK_20080227_1006, too.

Question 1: Is there any possibility to read out the mapped <Filename>-tag from the payload to use it for the element inside my archive (File Name Scheme and Variable Substitution don't work when using Adapter-Specific Message Properties).

Question 2: Is there a way to modify the name of the payload so that I can change "MainDocument" to "OUT_RNK_20080227_1006"?

I'm on XI 3.0 - SP19.

Many thanks,

Ralph

Accepted Solutions (1)

Accepted Solutions (1)

stefan_grube
Active Contributor
0 Kudos

This is not possible with standard functionality.

You have to write an adapter module that stores the file name for example in the content type.

Regards

Stefan

Former Member
0 Kudos

Thanks.

Regards,

Ralph

Former Member
0 Kudos

Hi Stefan,

One more guy to say thanks for your blog [Zip or Unzip your Payload with the new PayloadZipBean |https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/5899] [original link is broken] [original link is broken] [original link is broken];

I am following this thread now as we have similar issue. Is there some example code that we can refer to to write such adapter module. We have to get the filename that is available in the dynamic configuration and put it in the content type as we are having difficulty in setting the filename in the ZIP archive as per the sender filename. The PayloadZipBean only allows certain fields to be used for filenames.

However we are successful in naming the ZIP file name correctly as per sender file name at the receiver.

For this we are using the AF_Modules/DynamicConfigurationBean to write the File Name from the dynamic configuration to message.interface and then using Variable Substitution to use this key to format the receiver filename.

This works fine for the ZIP archive name and want to make sure the name of the in the archive also is correct and not something hardcoded.

Regards

Charu

stefan_grube
Active Contributor
0 Kudos

In this thread there is a module for reading the content type and setting the dynamic configuration:

It should be not be so difficult to derive the reverse way.

Regards

Stefan

Edited by: Stefan Grube on Apr 17, 2008 11:02 AM

Former Member
0 Kudos

>

> In this thread there is a module for reading the content type and setting the dynamic configuration:

>

> It should be not be so difficult to derive the reverse way

Thanks for this info Stefan.

[Stefan Grube's webinar on custom adapter module development|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/64a6bdab-0c01-0010-079a-b3707717cecd?prtmode=navigate]

The code of the EJB module we had to write to get the filename from the Dynamic Configuration (ASMA) and then set the content type of the message is given below.

/*
 * Created on Apr 23, 2008
 */
package zfilezipper;
/**
 * @author Krishneel Goundar
 */
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 SetContentTypeEJB 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();	//Used to read dynamic configuration data
			TextPayload payload = msg.getDocument();	//Used to set 'contentType' value
			//The name of the file to be zipped is read from the dynamic configuration.
			String fileName = msg.getMessageProperty("http://sap.com/xi/XI/System/File", "FileName");
			
			if(fileName == null)	//If no file name can be determined we set 'contentType' to "defaultbeanile.txt"
				payload.setContentType("text/plain;charset = \"UTF-8\";filename=\"defaultbeanfile.txt\"");	
			else	//If a file name can be found we set 'contentType' to the name of the file.
				payload.setContentType("text/plain;charset = \"UTF-8\";filename=\"" + fileName + "\"");	
			//After setting the value of 'contentType' we need to update the ModuleData object (inputModuleData).
			inputModuleData.setPrincipalData(msg);
		} catch (Exception e) {
			ModuleException me = new ModuleException(e);
			throw me;
		}
		return inputModuleData;		//Return the updated ModuleData object.
	}
}

Edited by: Charu Kulkarni on Apr 28, 2008 1:41 AM

Answers (0)