cancel
Showing results for 
Search instead for 
Did you mean: 

Error in testing SAX java mapping

Former Member
0 Kudos

Hi

I have created a java mapping program using SAX parser. i have compiled it on my local PC and zipped the java file and class file into a folser and imported it to the import archive in XI. inlcuded the class file in the mapping program of the interface mapping. when i do testing i am getting the following error

saxmapfinal is the class name

Linkage error occurred when loading class saxmapfinal

LinkageError at JavaMapping.load(): Could not load class: saxmapfinal

java.lang.UnsupportedClassVersionError: saxmapfinal (Unsupported major.minor version 50.0) at java.lang.ClassLoader.defineClass0(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:539) at java.lang.ClassLoader.defineClass(ClassLoader.java:448) at com.sap.aii.ibrep.server.mapping.ibrun.RepMappingLoader.findClass(RepMappingLoader.java:175) at java.lang.ClassLoader.loadClass(ClassLoader.java:289) at java.lang.ClassLoader.loadClass(ClassLoader.java:235) at com.sap.aii.ibrep.server.mapping.ibrun.RepJavaMapping.load(RepJavaMapping.java:136) at com.sap.aii.ibrep.server.mapping.ibrun.RepJavaMapping.execute(RepJavaMapping.java:50) at com.sap.aii.ibrep.server.mapping.ibrun.RepMappingHandler.run(RepMappingHandler.java:80)

mapping java file code is :


<b>import</b> java.io.FileInputStream;
<b>import</b> java.io.FileOutputStream;
 
<b>import</b> com.sap.aii.mapping.api.StreamTransformation;
<b>import</b> java.io.*;
<b>import</b> java.util.Map; <b>import</b> javax.xml.parsers.*;
<b>import</b> org.xml.sax.*; <b>import</b> org.xml.sax.helpers.*;
 
<b>public</b> <b>class</b> saxmapfinal <b>extends</b> DefaultHandler <b>implements</b> StreamTransformation{
	<b>private</b> Map map;
	<b>private</b> OutputStream out;
 <b>private</b> <b>boolean</b> input1 = <b>false</b>;
  <b>private</b> <b>boolean</b> input2 = <b>false</b>;
<b>private</b> <b>int</b> number1;
<b>private</b> <b>int</b> number2;
<b>private</b> <b>int</b> addvalue;
<b>private</b> <b>int</b> mulvalue;
<b>private</b> <b>int</b> subvalue;
 
	<b>public</b> <b>void</b> setParameter (Map param)
       {
		map = param;
	}
	<b>public</b> <b>void</b> execute (InputStream in, OutputStream out)
	<b>throws</b> com.sap.aii.mapping.api.StreamTransformationException 
               {
		DefaultHandler handler = <b>this</b>;
		SAXParserFactory factory = SAXParserFactory.newInstance();
		<b>try</b> {
			SAXParser saxParser = factory.newSAXParser();
			this.out = out; saxParser.parse(in, handler);
		}
		<b>catch</b> (Throwable t){
			t.printStackTrace();
		}
	}
	<b>private</b> <b>void</b> write (String s) <b>throws</b> SAXException{
		<b>try</b>{
			out.write(s.getBytes()); out.flush();
		}
		<b>catch</b> (IOException e){
			<b>throw</b> <b>new</b> SAXException(&quot;I/O error&quot;, e);
		}
	}
	<b>public</b> <b>void</b> startDocument () <b>throws</b> SAXException{
		write(&quot;<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>&quot;);
		write(&quot;<ns0:MT_IB_SAX_MAP xmlns:ns0=http://learningxi.com>&quot;);
	}
	<b>public</b> <b>void</b> endDocument () <b>throws</b> SAXException {
		write(&quot;</ns0:MT_IB_SAX_MAP>&quot;);
		<b>try</b> { out.flush();
		}
		<b>catch</b> (IOException e) {
			<b>throw</b> <b>new</b> SAXException(&quot;I/O error&quot;, e);
		}
	}
	<b>public</b> <b>void</b> startElement (String namespaceURI, String sName, String qName, Attributes attrs)
	<b>throws</b> SAXException {
		String eName = sName;
		<b>if</b> (&quot;&quot;.equals(eName))
			eName = qName;
		<b>if</b>(eName.equals(&quot;NUMBER1&quot;))
 
                           input1 = <b>true</b>;
	           <b>if</b>(eName.equals(&quot;NUMBER2&quot;))
 
                           input2 = <b>true</b>;
 
			
	}
	<b>public</b> <b>void</b> endElement (String namespaceURI, String sName, String qName) <b>throws</b> SAXException {
		String eName = sName;
		<b>if</b> (&quot;&quot;.equals(eName))
			eName = qName;
		<b>if</b>(eName.equals(&quot;NUMBER1&quot;))
			input1 = <b>false</b>;
	
		<b>if</b>(eName.equals(&quot;NUMBER2&quot;))
			input2 = <b>false</b>;
    }
<b>public</b> <b>void</b> characters(<b>char</b>[] chars,<b>int</b> startIndex, <b>int</b> endIndex) <b>throws</b> SAXException 
{
    
      String dataString =
        <b>new</b> String(chars, startIndex, endIndex).trim();
      <b>if</b> (input1) {
        <b>try</b> 
        {
          number1 = Integer.parseInt(dataString);
        } <b>catch</b>(NumberFormatException nfe)
             {
        
        }
      }
  <b>if</b> (input2) {
        
          
          number2 = Integer.parseInt(dataString);
        
      }
 
<b>if</b> ((number1 != 0) &#38;&#38; (number2 != 0))
{
addvalue = number1 + number2;
mulvalue =  number1 * number2;
subvalue = number1 - number2;
	write(&quot;<ADD>&quot; + addvalue +&quot;</ADD>&quot;);
	write(&quot;<MUL>&quot; + mulvalue +&quot;</MUL>&quot;);
	write(&quot;<SUB>&quot; + subvalue +&quot;</SUB>&quot;);
}
 
    
}
 
 
}

I have test the same program in my PC by adding the main method and adding the below code. the program is gnerating the target xml as desired.


//	public static void main(String[] args) throws Exception{
//		try{
//			FileInputStream fin =
//				new FileInputStream(&quot;C:\Documents and Settings\sbhatta\saxexp.xml&quot;);
//			FileOutputStream fout =
//				new FileOutputStream(&quot;C:\Documents and Settings\sbhatta\tarsax.xml&quot;);
//			saxmap mapping = new saxmap();
//			mapping.execute(fin,fout);
//		}
//		catch (Exception e){
//			e.printStackTrace();
//		}
//	}

the logic is the input message contians number1 and number2 and the output message contains ADD, MUL and SUB elements where ADD contains addition value of two numbers ,, MUL is multiplication SUB is subtraction.

when you import the zip file what it should contain and is thery anything i missed in the coding part???

thanks

sankar

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi sankara,

I am sure that there is somthing wrong with the path in your imported archive (where your java-programm is hostet).

The path shown in the imported archive has to be the same as in your java-development-enviroment.

Sample:

java-development-enviroment: If your xxx.java is in the package

folder1/folder2

than your path in your imported archive has also to be

folder1/folder2

So you did zip your class or jar-file in a wrong way! Zip it on the fitting path-level!

Regards Mario

Edited by: Mario Müller on Jul 23, 2008 8:44 AM

Former Member
0 Kudos

Hi

thanks for the reply.

I did not use any package statemetn in my java program. is it mandatory??

my jdk path is

C:\Program Files\Java\jdk1.6.0_06\bin I have stored my java file and class file in the same folder . then i have slected both java and class file and zipped them. zip file is also exists in the same path. I went to the XI system and crated new imported archive and imported the zip file. the "path" field is blank but the class and java files are loaded into the imported archive.

thanks

sankar

Former Member
0 Kudos

Hi,

I am not sure under which circumstances the "path" field could be blank!

Every java belongs to a package. Check the path with your windows explore.

Regards Mario

Former Member
0 Kudos

hi

can you let me know if there is anyhting wrong with the java program.

thanks

sankar

Answers (1)

Answers (1)

Former Member
0 Kudos

Did you ever get a solution for this? I am getting the same issue, and found a note saying that the java version must match (JDK versus what is on PI). I have both on 1.5 but it is not solving the issue. Wonder if release matters too.