JDK 6

Published: Friday, 5 September 2008

Included Libraries

See Java Endorsed Standards Override Mechanism

Upgrade Issues

org.apache.xml.serializer.ToXMLSAXHandler cannot be cast to org.apache.xml.serializer.SerializationHandler

Caused by: java.io.IOException: org.apache.xml.serializer.ToXMLSAXHandler cannot be cast to org.apache.xml.serializer.SerializationHandler
        at com.sun.xml.messaging.saaj.soap.impl.EnvelopeImpl.output(EnvelopeImpl.java:298)
        at com.sun.xml.messaging.saaj.soap.impl.EnvelopeImpl.output(EnvelopeImpl.java:309)
        at com.sun.xml.messaging.saaj.soap.SOAPPartImpl.getContentAsStream(SOAPPartImpl.java:305)
        at com.sun.xml.messaging.saaj.soap.MessageImpl.getHeaderBytes(MessageImpl.java:942)
        at com.sun.xml.messaging.saaj.soap.MessageImpl.saveChanges(MessageImpl.java:1093)
        ... 28 more

        The full stack trace was not shown. After debugging the remainder can be printed:

org.apache.xml.serializer.utils.WrappedRuntimeException: org.apache.xml.serializer.ToXMLSAXHandler cannot be cast to org.apache.xml.serializer.SerializationHandler
        at org.apache.xml.serializer.SerializerFactory.getSerializer(SerializerFactory.java:177)
        at org.apache.xalan.transformer.TransformerIdentityImpl.createResultContentHandler(TransformerIdentityImpl.java:259)
        at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:329)
        at com.sun.xml.messaging.saaj.util.transform.EfficientStreamingTransformer.transform(EfficientStreamingTransformer.java:390)
        at com.sun.xml.messaging.saaj.soap.impl.EnvelopeImpl.output(EnvelopeImpl.java:296)
        at com.sun.xml.messaging.saaj.soap.impl.EnvelopeImpl.output(EnvelopeImpl.java:309)

The casting is done at

  cls = ObjectFactory.findProviderClass(className, loader, true);
  SerializationHandler sh =
      (SerializationHandler) cls.newInstance();

cls.getClassLoader() seems correct.

org.apache.xml.serializer.SerializationHandler.class.getClassLoader() is from another webapp’s class loader. I’m not sure why.

Thread.currentThread().getContextClassLoader().loadClass("org.apache.xml.serializer.SerializationHandler").getClassLoader() is from the current webapp’s class loader

One fix is to put Xalan into the endorsed lib path of the jre. For tomcat, this in the jakarta-tomcat-5.5.7/common/endorsed directory.

Or you can get away with putting it into the shared/lib directory in $CATALINA_BASE.

JVM Properties

OmitStackTraceInFastThrow

You can use -XX:-OmitStackTraceInFastThrow or -XX:+OmitStackTraceInFastThrow on Sun’s JVM. I’m not sure under what conditions a stack trace does not appear but you could see errors like

java.lang.NullPointerException
                at org.springframework.remoting.support.RemoteInvocationUtils.fillInClientStackTraceIfPossible(RemoteInvocationUtils.java:47)
                at org.springframework.remoting.support.RemoteInvocationResult.recreate(RemoteInvocationResult.java:115)

IPv4 and IPv6

If you have both IPv4 and IPv6 configured on your o/s and want to use only IPv4, add the following system properties:

-Djava.net.preferIPv4Stack=true (default is false)

-Djava.net.preferIPv6Addresses=false (default is already false)

Annotations

javax.annotation.Resource

This allows the dependency injection container to inject an instance at runtime. Apply this to a field or method.