views:

1013

answers:

2

Hi There,

I have an application which has been running happily under Java 1.5 for around a year. We've just had the boxes updated and had Java 1.6 installed.

After deploying the app to the new server we've found the application is throwing an exception when it tries to transform some XML. We couldn't understand why this was happening until we deployed it locally and the same happened. After changing the SDK to v1.5 the problem stopped and the application runs fine.

Here's the method's source:

import java.io.StringWriter;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Element;
import org.w3c.dom.Node;


   public static String xmlToString(Node node) {
    try {
        Source source = new DOMSource(node);
        StringWriter stringWriter = new StringWriter();
        Result result = new StreamResult(stringWriter);
        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer = factory.newTransformer();
        transformer.transform(source, result);
        return stringWriter.getBuffer().toString();
    } catch (TransformerConfigurationException e) {
        e.printStackTrace();
    } catch (TransformerException e) {
        e.printStackTrace();
    }
    return null;
   }

It's crashing on the "transformer.transform(source, result);" line with exception:

Exception in thread "main" java.lang.AbstractMethodError: org.apache.xerces.dom.DocumentImpl.getXmlStandalone()Z
    at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.setDocumentInfo(DOM2TO.java:373)
    at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:127)
    at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:94)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:662)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:708)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:313)

Does anyone know of any changes made to Java between the two versions which would cause this? What would be the easiest fix?

Thanks for your help.

+4  A: 

I don't remember if it was between 1.4 and 1.5 or 1.5 and 1.6, but the Xalan libraries that shipped with the JVM from Sun changed their package name. I ran into something similar about 2 years ago. I think what I had to do was explicitly ship my own xalan implementation to fix the problem.

UPDATE: This might have been what I was thinking of, though it still could be related to your problem link text

Chris Boran
You're supposed to use only the JAXP API or depend on the xerces libraries themselves, never on the sun-supplied implementation (which will vary between releases).
wds
A: 

It is the problem because of jar(Xalan) version conflict. Remove the jars and give a try

Niger