cancel
Showing results for 
Search instead for 
Did you mean: 

Message Transformation Bean - Usage of external classes

Former Member
0 Kudos

Hi SDNers,

I am planning to write an external Java class to be loaded from AF_Modules/MessageTransformBean . The idea is simple, I want my class to handle an extra level of hierarchy in FCC process. I know writing the Java class which is as generic as the one provided by SAP is too complex. But I just want it for some specific requirements, so I dont intend to make it as a generic class.

Should the external class that I write implement the interface Transform? If so, what is the jar file that contains this interface and where can I find this jar file in my XI installation?

Also, what is the jar file that contains the standard class com.sap.aii.messaging.adapter.Conversion that gets loaded by default while using the MessageTransformBean?

If you have already tried with similar requirements, please share your experience on the same.

Thanks

Jaishankar

Accepted Solutions (1)

Accepted Solutions (1)

stefan_grube
Active Contributor
0 Kudos

Go to service marketplace, download J2SE adapter. You find the Transform.class in aii_msg_runtime.jar

You can test your class locally with the J2SE adapter engine. Check online help:

http://help.sap.com/saphelp_nw04/helpdata/en/78/759f3cad1e3251e10000000a114084/frameset.htm

Use the aii_af_jmsproviderlib.sda for deploying your class.

The code of the module is similar to a Java mapping.

Regards

Stefan

Former Member
0 Kudos

Stefan,

Thanks a lot. I added the jar file as an external library. I was able to see a Transform.class in the jar file(opened using winzip). However in NWDS I am unable to implement the Transform interface.

I copied the aii_msg_runtime jar file from the PI 7.0 installation. Is that the reason for this behaviour?

Also, is it mandatory that I implement this interface for my class? I plan to use only the central J2EE adapter and no J2SE adapters.

Thanks

Jaishankar

stefan_grube
Active Contributor
0 Kudos

You can use the same module in J2SE and J2EE adapter without change.

I recommend to install a J2SE adapter engine on a local PC for testing.

I have found a sample code from previous tests:


package sample;

import com.sap.aii.messaging.adapter.Parameter;
import com.sap.aii.messaging.adapter.trans.Transform;
import com.sap.aii.messaging.adapter.trans.*;
import java.io.*;

public class MyModule extends Transform {

Parameter parameter;

String filename;


	public void init(TransformConfig config) throws TransformException{
			
			super.init(config);
			parameter = (Parameter) config.getParameters("Parameter");

			filename = (String) parameter.get("filename");
	}
				
	// obligatory method service
	public void service(TransformRequest request, TransformResponse response) throws TransformException {
		
		// Get the input stream for request message
		InputStream in = (InputStream) request.getMessage();
		
		// Get output stream for response message
		OutputStream out = (OutputStream) response.getMessage(Transform.MT_OutputStream);
		
		try{
			execute(in,out);
		} catch (Exception e) {
			throw new TransformException("TransformException: Error converting Message " + e.getMessage(), e);
		}
	}
	
	public void execute(InputStream in, OutputStream out) throws Exception{
		
		String filename = (String) transformConfig.getParameters("FileName");
		if (filename == null){
			filename = "notfound.txt";
		}
			
		// open file stream
		OutputStream fileOut = new FileOutputStream(new File(filename));
		// copy input stream to output stream and to file
		int c;
		while ((c = in.read()) != -1) {
				fileOut.write(c);
				out.write(c);
			}

	}

//	main Methode, for local testing. A local XML file is expected.
	 public static void main (String[] args) {

		 try {
			 // Define Input stream and output stream from file
			 InputStream in = new FileInputStream(new File("source.xml"));
			 OutputStream out = new FileOutputStream(new File("target.xml"));
			 // call Mapping
			 MyModule map = new MyModule();
			 map.execute(in,out);
		 } catch (Throwable t) {
			 t.printStackTrace();
		 }
		 System.exit(0);
	 }

	
}

Answers (1)

Answers (1)

VijayKonam
Active Contributor
0 Kudos

Hi Jai,

Instead of planning to write a generic class, why dont you look at writing a module that can be called before or after the messagetransform module? That way, it would be easier for you to plug in and you can use the sample module code provided by SAP...

Just a thought..

VJ

Former Member
0 Kudos

Hello VJ,

Hmmm.. if I use Message Transformation Bean I already have lost the hierarchy. It could get really cumbersome to rebuild the hierarchy with the XML formed using the XML formed by the bean.

Any other ideas..

Thanks

Jaishankar