cancel
Showing results for 
Search instead for 
Did you mean: 

Adapter Module for File Adapter

Former Member
0 Kudos

Hi,

I'm developing a module for the file adapter(receiver). My requirement is to parse the XI message(XML) using some XML parsing api and do some formatting, logic etc and to make the file adapter create a flat file with the processed information. File Content Conversion does not suit our requirement and thats the reason we are trying this option.

My understanding is: Access the XML payload in the "process" method of the local ejb, apply XML parsing using JDOM etc, make a string which should be the output of the file adapter. This string will have elements from the XML document, new line characters and spaces. Can i form this string and assign to the inputModuleData? Will the file adapter use this string to create the file? Are there any other parameters to be set or processes to be done?

If anyone has some information or resources please help me..Thanks in advance.

Sandeep

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Sandeep -

Since you will not be using the FileContentConversion option, another option available to you is to perform the target flat-file mapping directly in the main XI mapping. You can't use Message Mapping of course, but with Java or XSLT, you can create the target flat-file mapping.

However, it's good to gain a better understanding of modules and how they work so I'd continue to explore your current path of using a module for your this requirement. But you may want to keep the other option in mind.

Regards,

Jin

Former Member
0 Kudos

Hi Ananth,

thanks a lot for the solution..one question..my output should be a flat file without any XML tags. For example, if the XML is:

<xml>

<firstname>sandeep</firstname>

<lastname>joseph</lastname>

</xml>

the output file should have the following content:

-


firstname: sandeep

lastname : joseph

-


Can i process the xml document in my class and form a string which is my desired output and assign it to the outXML stream? Is it necessary that the outXML also should be an XML document?

Thanks,

Sandeep

Former Member
0 Kudos

Hi Sandeep,

Yes you can process an XML file and generate flat text file.

Actually I thought you were using the File Adapter module at the sender side.

For your question regarding removing XML tags, Java supports Regular Expression in String class methods like String.replaceAll(). Use the regular expression to replace all the <b><</b> and <b>></b> symbols.

<a href="http://www.zytrax.com/tech/web/regex.htm">Regular Expressions</a>

Regards,

Ananth

Former Member
0 Kudos

Hi Sandeep,

The following code fragment using <b>regular expression</b> removes all the XML tags and gives only the plain data

strVar.replaceAll("\<.*?\>","");

Modify this code for your requirement.

Regards,

Ananth

Former Member
0 Kudos

Hi Sandeep,

Modify the following code and add your XML processing logic and deploy it as an EAR Archive.Note Implement your YourClass code in such a way that it modifies your payload and generate new XML payload by using XML processing techniques.

You can access the incoming message using

payloadData.getInputStream()

and after processing your message set your newly created message using

payloadData.setContent(outXML.toByteArray())

Hope this helps,

Regards,

Ananth


import java.io.ByteArrayOutputStream;
 
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
 
import com.sap.aii.af.mp.module.Module;
import com.sap.aii.af.mp.module.ModuleContext;
import com.sap.aii.af.mp.module.ModuleData;
import com.sap.aii.af.mp.module.ModuleException;
import com.sap.aii.af.ra.ms.api.Message;
import com.sap.aii.af.ra.ms.api.XMLPayload;
/**
 * @author AnanthBabu Chinnaraj
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
 
/**
 * @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}>
 */
 
public class YourBean implements SessionBean, Module {
 
	public void ejbCreate() {
	}
 
	public void ejbRemove() {
	}
 
	public void ejbActivate() {
	}
 
	public void ejbPassivate() {
	}
 
	public void setSessionContext(SessionContext context) {
		myContext = context;
	}
 
	private SessionContext myContext;
	/* (non-Javadoc)
	 * @see com.sap.aii.af.mp.module.Module#process(com.sap.aii.af.mp.module.ModuleContext, com.sap.aii.af.mp.module.ModuleData)
	 */
	public ModuleData process(ModuleContext arg0, ModuleData modData)
		throws ModuleException {
		
			
		try {
 
			
			Object dataObject = null;
			Message xiMessage = null;
			
			dataObject = modData.getPrincipalData();
 
			xiMessage = (Message) dataObject;
			XMLPayload payloadData = xiMessage.getDocument();
			ByteArrayOutputStream outXML=null;
			
			if (payloadData != null) {
 
				outXML = new ByteArrayOutputStream();
				
				YourClass obj= new  YourClass();	
				obj.processXML(payloadData.getInputStream(), outXML);
 
				payloadData.setContent(outXML.toByteArray());
				
			}
 
			modData.setPrincipalData(xiMessage);
			  
		} catch (Exception e) {
			
		
		}
		
		
		
		return modData;
	}
 
}