cancel
Showing results for 
Search instead for 
Did you mean: 

Java Module for changing the file's name

Former Member
0 Kudos

Hi all

I m developing a java module for altering a file's name. I m trying to append system date and time to the file name and send it back. I was successful in retrieving the file's name, appending date n time in it but now I want to send it back. How can I achieve this ? any pointers will be very helpful

awaiting your reply

Regards

Kapil

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Kapil,

Try this

Object obj = md.getPrincipalData();

com.sap.aii.af.ra.ms.api.Message msg = (Message) obj;

msg.setMessageProperty("http://sap.com/xi/XI/System/File", "FileName","FileNameModule");

// FileNameModule represents the resultantFile name.

Set Adapter Specific Attributes(FileName) in receiver commn channel.

Rest of ur logic is same.

Get back if u have any issues.

Regards,

Sudharshan

Answers (3)

Answers (3)

Shabarish_Nair
Active Contributor
0 Kudos
MichalKrawczyk
Active Contributor
0 Kudos

hi,

>>>> but now I want to send it back

what do you mean?

to the XI again ? if you put the file in a folder in which XI pulls

the files the file will be in XI again

Regards,

michal

-


<a href="/people/michal.krawczyk2/blog/2005/06/28/xipi-faq-frequently-asked-questions"><b>XI / PI FAQ - Frequently Asked Questions</b></a>

Former Member
0 Kudos

Michal

I want to send it bak to the moduleData wid new name

Regards

Kapil

bhavesh_kantilal
Active Contributor
0 Kudos

Kapil,

Can you give the entire flow?

File adapters are asynch always and so, what do you imply when you say you want to sent it back?

Regards,

Bhavesh

Former Member
0 Kudos
String SIGNATURE = "process(ModuleContext moduleContext, ModuleData inputModuleData)";
		TRACE.entering(SIGNATURE, new Object[] { moduleContext, inputModuleData });
//		Access the XI message. I.e. this module must be placed in the module chain
		 // behind a module that sets an XI message as principal data.
		 Object obj = null;
		 Message msg = null;
		 try {
		 		obj = inputModuleData.getPrincipalData();
			 	msg = (Message) obj;
			 
				Message msgg = (Message)inputModuleData.getPrincipalData();	
				AuditMessageKey amk = new AuditMessageKey(msgg.getMessageId(), AuditDirection.INBOUND);			
				Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, "RenameFile: Module Called");
			
//			Read the channel ID, channel and the module configuration
				 String cid  = null;
				 String mode = null;
				 String fileName = null;

				 try {
					 // CS_GETMODDAT START
					 mode = (String) moduleContext.getContextData("mode");
					 // CS_GETMODDAT END
					 // CS_GETCHADAT START
					 cid  = moduleContext.getChannelID();
					 
					 Channel channel = new Channel(cid);
//					 channel = (Channel) LookupManager.getInstance().getCPAObject(CPAObjectType.CHANNEL, cid);
					 // Example to access a channel configuration parameter in a module: String someParameter = channel.getValueAsString("YourAttributeName");
					 // CS_GETCHADAT END
				  
//					Hashtable mp = (Hashtable) inputModuleData.getSupplementalData("module.parameters");
//					  if(null != mp)
//					  {
//						   fileName = (String)mp.get("FileName");
//						   fileName = fileName + todaysDate;
//						   mp.put("FileName",fileName);	
//					   }
					fileName = channel.getValueAsString("file.targetFileName");
					Date todaysDate = new Date(System.currentTimeMillis());
					fileName = fileName + todaysDate;
					
					Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, "RenameFile: fileed" + fileName);
					
					 if (mode == null) {
						 TRACE.debugT(SIGNATURE, "Mode parameter is not set. Switch to 'none' as default.");
						 mode = "none";
					 }
					 TRACE.debugT(SIGNATURE, "Mode is set to {0}", new Object[] {mode});
				 } catch (Exception e) {
					 TRACE.catching(SIGNATURE, e);
					 TRACE.errorT(SIGNATURE, "Cannot read the module context and configuration data");
					 ModuleException me = new ModuleException(e);
					 TRACE.throwing(SIGNATURE, me);
					Audit.addAuditLogEntry(amk, AuditLogStatus.ERROR, "Rerrrd" + me);
					 throw me;
				 }
//			try{
//			   Hashtable mp = (Hashtable) inputModuleData.getSupplementalData("module.parameters");
//			   String fileName = null;
//			   Date todaysDate = new Date(System.currentTimeMillis());
//			   if(null != mp)
//			   {
//				   fileName = (String)mp.get("FileName");
//				   fileName = fileName + todaysDate;
//				   mp.put("FileName",fileName);	
//			   }
//			   inputModuleData.setSupplementalData("module.parameters", mp);
//			}catch(Exception e){
//				
//			}

		 } catch (Exception e) {
			 TRACE.catching(SIGNATURE, e);
			 if (obj != null)
				 TRACE.errorT(SIGNATURE, "Input ModuleData does not contain an object that implements the XI message interface. The object class is: {0}", new Object[] {obj.getClass().getName()});
			 else
				 TRACE.errorT(SIGNATURE, "Input ModuleData contains only null as XI message");
			 ModuleException me = new ModuleException(e);
			 TRACE.throwing(SIGNATURE, me);
			 throw me;
		 }



		return inputModuleData;

Please refer the above code, it might help you to understand what i m trying to do. I have also included some code that is in comments which I tried by referring the links given by other users but its nt working. Please tell me how to improve my code to set the filename into the <b>reciever file adapter</b>.

Regards

Kapil

bhavesh_kantilal
Active Contributor
0 Kudos

Kapil,

To access and set the Adapter Specific identifiers from the Receiver File adapter 's Module, just check this blog,

/people/daniel.graversen/blog/2006/10/05/dynamic-configuration-in-adapter-modules

Meanwhile will take a look at your code as well.

Regards,

Bhavesh

Shabarish_Nair
Active Contributor
0 Kudos

Kapil,

if you ref. the earlier link i sent you then u wud understand the aproach is to fill your XML that comes into XI with a node/field with the filename generated.your module will be deployed in the sender channel.

And then maybe later in your receiver adapter, you cud use variable substitution (http://help.sap.com/saphelp_nw04/helpdata/en/bc/bb79d6061007419a081e58cbeaaf28/content.htm) to get the value to generate the file name for ur output file.

Former Member
0 Kudos

Hi KApil,

Use the ASMA field for changing target filename : Adapter-specific-message-attribute,

You can find some blogs on how to use it for altering your filename

( you could even have done this is message mapping : no module necessary )

rgds

Dirk

Former Member
0 Kudos

HI Kapil

To clarify : ASMA are specified in the communication channel : Activate the flag and you see the possible asma fields.

How to use in your flow : see

/people/michal.krawczyk2/blog/2005/11/10/xi-the-same-filename-from-a-sender-to-a-receiver-file-adapter--sp14

rgds

Dirk