SOAP/SAAJ/XML Issues When Migrating to Java 6 (with Axis 1.2)

When you migrate an application using Apache Axis 1.2 from Java 4 or 5 to Java 6 (JRE 1.6) you will most likely encounter a handful of strange SOAP/SAAJ/XML errors and ClassCastExceptions. This is due to the fact that Sun's implementation of SAAJ 1.3 has been integrated directly into the 1.6 JRE. Due to this integration it's loaded by the bootstrap class loader and thus cannot see various classes that you might be referencing in your old code.

As mentioned on Spring pages:
Java 1.6 ships with SAAJ 1.3, JAXB 2.0, and JAXP 1.4 (a custom version of Xerces and Xalan). Overriding these libraries by putting different version on the classpath will result in various classloading issues, or exceptions in org.apache.xml.serializer.ToXMLSAXHandler. The only option for using more recent versions is to put the newer version in the endorsed directory (see above).
Fortunately, there is a simple solution, at least for Axis 1.2.

Some of the exceptions that we've encountered

Sample Axis code

import javax.xml.messaging.URLEndpoint;

import javax.xml.soap.MessageFactory; import javax.xml.soap.SOAPConnection; import javax.xml.soap.SOAPConnectionFactory; import javax.xml.soap.SOAPMessage;


public static callAxisWebservice() { SOAPConnectionFactory soapconnectionfactory = SOAPConnectionFactory.newInstance(); SOAPConnection soapconnection = soapconnectionfactory.createConnection(); MessageFactory messagefactory = MessageFactory.newInstance(); SOAPMessage soapmessage = messagefactory.createMessage(); ... URLEndpoint urlendpoint = new URLEndpoint(string); SOAPMessage soapmessage_18_ =, urlendpoint); ... }

SOAPExceptionImpl: Bad endPoint type

com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Bad endPoint type
This extremely confusing error is caused by the following, seemingly innocent code above, namely by the '... new URLEndpoint(string)' and the call itself. The problem here is that Sun's HttpSOAPConnection can't see the javax.xml.messaging.URLEndpoint because it is not part of the JRE and is contained in another JAR, not visible to the classes loaded by the bootstrap loader.

If you check the HttpSOAPConnection's code (this is not exactly the version I have but close enough) you will see that it calls "Class.forName("javax.xml.messaging.URLEndpoint");" on line 101. For the reason mentioned it fails with a ClassNotFoundException (as indicated by the log "URLEndpoint is available only when JAXM is there" when you enable the JDK logging for the finest level)  and thus the method isn't able to recognize the type of the argument and fails with the confusing Bad endPoint message.

A soluti0n in this case would be to pass a or a String instead of a URLEndpoint (though it might lead to other errors, like the one below).

Related: Oracle saaj:soap1.2 bug SOAPExceptionImpl: Bad endPoint type.


org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
 at org.apache.xerces.dom.AttrNSImpl.setName(Unknown Source)
 at org.apache.xerces.dom.AttrNSImpl.<init>(Unknown Source)
 at org.apache.xerces.dom.CoreDocumentImpl.createAttributeNS(Unknown Source)
We got this when calling an Axis web service via a proxy object, I've no idea why it is thrown. The solution is as below, to set the SOAP implementation properties either upon start or at the runtime.

Bonus: Conflict between Axis and IBM WebSphere JAX-RPC "thin client"

Additionally, if you happen to have somewhere on the classpath, you may get this funny exception:
java.lang.ClassCastException: org.apache.axis.Message incompatible with
You may wonder why Java tries to use Axis Message with WebSphere SOAP connection. Well, it's because the SAAJ lookup mechanism prefers the websphere implementation, for it declares itself via META-INF/services/javax.xml.soap.SOAPFactory pointing to, but instantiates the org.apache.axis.soap.MessageFactoryImpl for message creation for the websphere thin client doesn't provide an implementation of this factory.

The solution here is the same as for all the other exception, to use exclusively Axis. But if you are interested, check the description how to correctly create a Message with the websphere runtime on page 119 of the IBM WebSphere Application Server V7.0 Web Services Guide (md =, SOAPMessage.class, Service.Mode.MESSAGE);  ((SOAPBinding) ((BindingProvider) md).getBinding()).getMessageFactory();).


The solution that my collegue Jan Nad has found is to force JRE to use the SOAP/SAAJ implementation provided by Axis, something like:

java -Djavax.xml.soap.SOAPFactory=org.apache.axis.soap.SOAPFactoryImpl -Djavax.xml.soap.MessageFactory=org.apache.axis.soap.MessageFactoryImpl -Djavax.xml.soap.SOAPConnectionFactory=org.apache.axis.soap.SOAPConnectionFactoryImpl example.MainClass

Alternatively, at the runtime:
System.setProperty("javax.xml.soap.SOAPFactory", "org.apache.axis.soap.SOAPFactoryImpl");

It's also described in issue AXIS-2777.

Check details of the lookup process in the SOAPFactory.newInstance() JavaDoc.

Tags: java

Copyright © 2024 Jakub Holý
Powered by Cryogen
Theme by KingMob