Tomcat classloader

M

Moiristo

I have a web application that performs an XML transformation with an
XSLT style sheet. It uses standard transformation classes from
jax.xml.transform, Transformer and TransformerFactory. The result is
saved in a StreamResult object.

Strange thing is, the first time when I perform a transformation, the
XSL (not the XML) Document is written to the StreamResult. On retry, it
works fine. I think it has something to do with the Tomcat classloader.
Does anyone have other ideas on this (and possibly, a solution)?
 
T

Thomas Fritsch

Moiristo said:
I have a web application that performs an XML transformation with an
XSLT style sheet. It uses standard transformation classes from
jax.xml.transform, Transformer and TransformerFactory. The result is
saved in a StreamResult object.

Strange thing is, the first time when I perform a transformation, the
XSL (not the XML) Document is written to the StreamResult. On retry, it
works fine. I think it has something to do with the Tomcat classloader.
Why do you think this? Is it a wild guess? Or did you run your
web-application in *another* Java-web-server too, and you did *not* get the
described strange behaviour there?
Does anyone have other ideas on this (and possibly, a solution)?
Another reason might be a bug somewhere in your web-application (especially
in using static variables).
 
M

Moiristo

Thomas said:
Another reason might be a bug somewhere in your web-application (especially
in using static variables).

I create a pipeline that first collects the data in a class called
DataManager. The XML and XSL documents are stored in a bean. After that,
I call the transform function in another class (static method, see
below). It seems to me that it's just a standard transformation. No
exception is thrown. If I assume that the Transformer does its job, what
else could it be then my wild guess?



public static void transform(ReportOutput r) throws
XSLTTransformException {

Document XMLDoc = r.getXMLDoc();
Document XSLDoc = r.getXSLTDoc();

if(XSLDoc == null ) {
r.setOutput(xmlToString(XMLDoc));
return;
}

try {
// Create a TransformerFactory
TransformerFactory tFactory =
TransformerFactory.newInstance();

// Use the DOM XML Document to define a DOMSource object.
DOMSource xmlDomSource = new DOMSource(XMLDoc);

// Use the DOM XSL Document to define a DOMSource object.
DOMSource xslDomSource = new DOMSource(XSLDoc);

//Create a StringWriter to collect the output
StringWriter sw = new StringWriter();

// Create a StreamResult from the StringWriter
StreamResult SResult = new StreamResult(sw);

// Process the stylesheet DOMSource and generate a

//Transformer.
Transformer transformer =
tFactory.newTransformer(xslDomSource);

// Perform the transformation, placing the output in the
//StreamResult.
transformer.transform(xmlDomSource, SResult);

r.setOutput(sw.getBuffer().toString());

} catch (TransformerException e) {
ModelUtils.log(e);
throw new XSLTTransformException();
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top