cancel
Showing results for 
Search instead for 
Did you mean: 

Java Mapping suggestion

Former Member
0 Kudos

I have 2 mappings for interface transformation. The first is visual mapping and second - java mapping. There are 2 entry of interface mapping.

my java code is:


public void execute(InputStream in, OutputStream out) {
    AbstractTrace trace =      (AbstractTrace)param.get(StreamTransformationConstants.MAPPING_TRACE );
trace.addInfo("[EscapeMapping] Mapping is starting");
try {
    int inputByte = 0;
    while((inputByte = in.read()) != -1) {
        out.write(inputByte);
    }
   } catch (Exception e) {
trace.addDebugMessage("[JAVA_MAPPING EXCEPTION] " + e.getMessage() + e.toString());
}

My my receiver gets an empty message.

message monitor:

<Trace level="1" type="T">Interface Mapping http://server.com/Mapping PersonToPersonJDBCInterfaceMapping</Trace>

<Trace level="1" type="T">*** APPLICATION TRACE TRUNCATED (for more details see LogViewer)***</Trace>

But I don't see my trace message in defaultTrace.trc

Coult you help me?

Why my mapping doesn't work? Do I need to restart J2EE Engine after new version of Java class mapping has been deployed?

Accepted Solutions (1)

Accepted Solutions (1)

stefan_grube
Active Contributor
0 Kudos

I assume, that you need a line

out.flush();

in your code.

For testing your Java mapping standalone, you can add a main method in your class:

    public static void main (String[] args) {
        try {
            InputStream in = new FileInputStream(new File("in.xml"));
            OutputStream out = new FileOutputStream(new File("out.xml"));
            MyClass change = new MyClass();
            change.execute(in, out);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

The trace is written to the XML message trace, not to the defaultTrace.trc.

If you do not see it there, set the trace level to 3.

Regards

Stefan

Former Member
0 Kudos

Thanks. Could you explain where do I have to set trace level?

stefan_grube
Active Contributor
0 Kudos

Here a code sample for Java Mapping. It should deescape the XML.

package sample;

import  com.sap.aii.mapping.api.*;
import  java.io.*;
import  java.util.Map;

public class Deescaping implements StreamTransformation{



		public static void main (String[] args) {
			try {
				InputStream in = new FileInputStream(new File("in.xml"));
				OutputStream out = new FileOutputStream(new File("out.xml"));
				Deescaping change = new Deescaping();
				change.execute(in, out);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}


		public void setParameter (Map map) {
		}


		public void execute (InputStream in, OutputStream out)
			throws StreamTransformationException {
			try {
				int c;
				while ((c = in.read()) != -1) {
					if (c != '&') {
						out.write(c);
					} else {
						// ampersand
						String help = "&";
						boolean exit = false;
						// check the next 5 chars, if there is a ';'
						for (int i = 0; i < 5 && !exit; i++) {
							c = in.read();
							if (c == -1) {
								exit = true;
							} else {
								// another ampersand?
								if (c == '&') {
									out.write(help.getBytes());
									help = "&";
									i = 0; // check the next 5 chars
								} else {
									help = help + (char) c;
									if (c == ';') {
										exit = true;
									}
									if (help.equals("&")) {
										help = "&";
									}
									if (help.equals("<")) {
										help = "<";
									}
									if (help.equals(">")) {
										help = ">";
									}
									if (help.equals(""")) {
										help = """;
									}
									if (help.equals("&apos;")) {
										help = "'";
									}
								}
							}
						} // for
						out.write(help.getBytes());
					}
				} // while
				out.flush();
			} catch (Exception e) {
				throw new StreamTransformationException(e.getMessage(),e);
			}
		}

}

Regards

Stefan

stefan_grube
Active Contributor
0 Kudos

Set the trace level like follows:

Log on to XI ABAP

Call: SXMB_ADM

Choose: Integration Engine Configuration

Press Button: Specific Configuration

Check for an entry: RUNTIME TRACE_LEVEL

If the entry is missing, add it. Assign value: 3

Regards

Stefan

Answers (0)