Monday, January 30, 2006

Java Apache Axis upgrade from version 1.1 to 1.2 - IncompatibleClassChangeError

Background:
The Java Web Application (WAR) that I developed makes a Web Service Call. I originally developed the application using Apache Axis version 1.1, however due to server deployment requirements, I have been forced to upgrade to Axis version 1.2.

Problem Description
After changing to the axis.jar in my WEB-INF/lib to Axis 1.2 (from Axis 1.1), the application started throwing the following error:
java.lang.IncompatibleClassChangeError
at org.apache.axis.message.MessageElement.addTextNode(MessageElement.java:1387)
at org.apache.axis.message.SOAPHandler.addTextNode(SOAPHandler.java:148)
at org.apache.axis.message.SOAPHandler.endElement(SOAPHandler.java:112)
at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(Unknown Source)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:424)
at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
at org.apache.axis.client.Call.invokeEngine(Call.java:2765)
at org.apache.axis.client.Call.invoke(Call.java:2748)
at org.apache.axis.client.Call.invoke(Call.java:2424)
at org.apache.axis.client.Call.invoke(Call.java:2347)
at org.apache.axis.client.Call.invoke(Call.java:1804)
at au.com.sensis.intranet.webservices.OutlookCalendarSoap_BindingStub.getAllMeetingRequestResponses(OutlookCalendarSoap_BindingStub.java:360)

after finding this forum post, and this post, I tried upgrading the Saaj.jar & jaxrpc.jar.


Problem Solution:
After downloading the Axis release 1.2.1, I upgraded:
saaj.jar from version 1.1 to version 1.1
jaxrpc.jar from version 1.1 to version 1.2

and added:
wsdl4j-1.5.1.jar to WEB-INF/lib

This resolved the IncompatibleClassChangeError. It's a pity Apache didn't implement Axis 1.2 to be backwards compatible with Axis version 1.1.

As a side comment, the Axis upgrade to version 1.2 was good because version 1.1 uses the 'enum' java reserved keyword in it's variable naming which causes warnings when running Java Source code level 1.5.

Note: I was using the mySpotter WSDL2Java Eclipse pluginto generate my Java stub to the web service using the WSDL, however upon examining the manifest.mf of the Axis jar in the com.myspotter.wsdl2java_1.1.0 plugin directory, discovered it was using Axis 1.1. Updating this jar alone didn't work, so I decided (based upon: ) to create an ANT script to generate the Web Service stubs (using wsdl4j-1.4.1.jar from the axis release):

build.properties:

# project information
project.owner =
My Company
project.owner.url = http://mywebservice.asmx
project.fullname =
My Company Web Service Java Client library Jar
project.vendor = My Company
project.name = myproject
project.version = 2
project.year = 2006
build.version = 1

# directory paths
build.dir = c:/temp/jarsbuild
lib.dir = ../../WebApp/WEB-INF/lib
build.dest.dir = ../../Builds
source.dir = ../../src
whos.who.web.service.wsdl.dev = http://x.asmx?WSDL
whos.who.web.service.wsdl.stg = http://x.asmx?WSDL
whos.who.web.service.wsdl.prd = http://x.asmx?WSDL


build.xml
<project name="OutlookUtilsJar" default="init" basedir=".">
<description>Sensis OutlookUtils Jar build file</description>

<property file="build.properties" />

<property name="fetched.dir" location="${build.dir}/fetched"/>
<property name="generated.dir" location="${build.dir}/generated"/>
<property name="pkg.jar.name" value="${project.name}-${project.version}.0.${build.version}"/>
<property name="compiled.src.dir" location="${build.dir}/compiled-src"/>

<target name="init">
<delete dir="${fetched.dir}"/>
<delete dir="${generated.dir}"/>
<mkdir dir="${fetched.dir}"/>
<mkdir dir="${generated.dir}"/>

<antcall target="buildStubJar">
<param name="build.type" value="dev"/>
<param name="wsdl" value="${whos.who.web.service.wsdl.dev}"/>
</antcall>
<antcall target="buildStubJar">
<param name="build.type" value="stg"/>
<param name="wsdl" value="${whos.who.web.service.wsdl.stg}"/>
</antcall>
<antcall target="buildStubJar">
<param name="build.type" value="prd"/>
<param name="wsdl" value="${whos.who.web.service.wsdl.prd}"/>
</antcall>
</target>

<target name="buildStubJar">
<property name="current.jar.name" value="${pkg.jar.name}-${build.type}"/>
<property name="current.src.dir" location="${generated.dir}/${current.jar.name}"/>
<property name="current.classes.dir" location="${current.src.dir}-classes"/>
<antcall target="fetch-wsdl">
<param name="jar.name" value="${current.jar.name}"/>
<param name="wsdl" value="${wsdl}"/>
</antcall>
<antcall target="import-wsdl">
<param name="jar.name" value="${current.jar.name}"/>
<param name="java.src.dir" value="${current.src.dir}"/>
</antcall>
<antcall target="compile-wsdl">
<param name="jar.name" value="${current.jar.name}"/>
<param name="java.src.dir" value="${current.src.dir}"/>
<param name="java.output.dir" location="${current.classes.dir}"/>
</antcall>

<tstamp/>
<jar destfile="${current.src.dir}.jar">
<fileset dir="${current.classes.dir}" />
<manifest>
<attribute name="Manifest-Version" value="${current.jar.name}"/>
<attribute name="Built-By" value="${user.name}"/>
<section name="${project.name}">
<attribute name="Specification-Vendor" value="${project.vendor}"/>
<attribute name="Implementation-Version" value="${TODAY}"/>
</section>
</manifest>
</jar>
<copy file="${current.src.dir}.jar" tofile="${build.dest.dir}/${pkg.jar.name}/${current.jar.name}.jar"/>
</target>

<target name="compile-wsdl">
<mkdir dir="${java.output.dir}"/>
<javac srcdir="${java.src.dir}"
destdir="${java.output.dir}"
classpathref="axis.classpath"
debug="on"
source="1.4"
/>
</target>

<path id="axis.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
</path>

<target name="fetch-wsdl">
<get src="${wsdl}" dest="${fetched.dir}/${jar.name}.wsdl"/>
</target>

<target name="import-wsdl">
<java classname="org.apache.axis.wsdl.WSDL2Java" fork="true" failonerror="true" classpathref="axis.classpath">
<arg file="${fetched.dir}/${jar.name}.wsdl"/>
<arg value="--output"/>
<arg file="${java.src.dir}"/>
<arg value="--verbose"/>
<arg value="--package"/>
<arg value="au.com.sensis.intranet.webservices"/>
</java>
</target>


</project>

0 Comments:

Post a Comment

<< Home