这是我的样本撒克逊变换代码,我有一个错误。
public static boolean transformXML(Source xmlSrc, Source xsltSrc,
OutputStream output, HashMap<String, String> parameters) {
boolean retVal = false;
try {
Processor proc = new Processor(false);
XsltCompiler comp = proc.newXsltCompiler();
XsltExecutable exp = comp.compile(xsltSrc);
XdmNode source = proc.newDocumentBuilder().build(xmlSrc);
Serializer outputSerializer = new Serializer();
outputSerializer.setOutputStream(output);
XsltTransformer trans = exp.load();
trans.setInitialContextNode(source);
trans.setDestination(outputSerializer);
trans.transform();
retVal = true;
} catch (Exception ex) {
LOGGER.error("Unexpected Exception", ex);
} finally {
IOUtils.closeQuietly(output);
}
return retVal;
}
如果我有&gt; 15mb xmlsource这是我在执行trans.transform()后得到的错误:
java.util.concurrent.TimeoutException
at org.eclipse.jetty.client.util.InputStreamResponseListener.get(InputStreamResponseListener.java:226)
at org.restlet.ext.jetty.internal.JettyClientCall.sendRequest(JettyClientCall.java:275)
at org.restlet.engine.adapter.ClientAdapter.commit(ClientAdapter.java:105)
at org.restlet.engine.adapter.HttpClientHelper.handle(HttpClientHelper.java:119)
at org.restlet.Client.handle(Client.java:153)
at org.restlet.Restlet.handle(Restlet.java:275)
at com.ti.itg.peit.core.ftds.http.util.HTTPRequest.genericRequest(HTTPRequest.java:115)
at com.ti.itg.peit.core.ftds.http.util.HTTPRequest.getRequest(HTTPRequest.java:72)
private StringBuffer processXSLT(
final StringBuffer xmlSrc) {
StringBuffer retVal = new StringBuffer();
try {
// to reduce file or content size.
String compressTextXMLSrc = xmlSrc.toString()
.replaceAll("\\s+", " ");
// Dump file into a temp dir named input.xml;
String inputDmp = System.getProperty("java.io.tmpdir")
+ "input.xml";
FileUtils.writeStringToFile(new File(inputDmp), compressTextXMLSrc );
// END dump: sample file size > 19mb
// get file .xslt
String xsltFile = getResourceProperties()
.getXsltFile();
String outputDmp= System.getProperty("java.io.tmpdir") + "output.xml";
// XSLT File Set systemID
Source xsltFile = new SAXSource(
new InputSource(xsltFile));
xsltFile.setSystemId(xsltFile);
try {
InputStream test = IOUtils.toInputStream(compressTextXMLSrc);
Processor proc = new Processor(false);
XsltCompiler comp = proc.newXsltCompiler();
XsltExecutable exp = comp.compile(xsltFile);
DocumentBuilder builder = proc.newDocumentBuilder();
builder.setLineNumbering(true);
// Get input File from temp dir
XdmNode source = builder
.build(new StreamSource(new File(inputDmp)));
Serializer outputSerializer = new Serializer();
FileOutputStream output = new FileOutputStream(
new File(outputDmp));
outputSerializer.setOutputStream(output);
XsltTransformer trans = exp.load();
trans.setInitialContextNode(source);
trans.setDestination(outputSerializer);
trans.transform();
} catch (Exception ex) {
ex.printStackTrace();
}
} catch (Exception ex) {
LOGGER.error("Caught an exception: ", ex);
retVal = null;
}
return retVal;
}
// END
XdmNode source = builder .build(new StreamSource(new File(inputDmp)));这是我得到这个错误的地方。但是,如果我有较低的mb文件大小,我没有遇到这个
java.util.concurrent.TimeoutException
at org.eclipse.jetty.client.util.InputStreamResponseListener.get(InputStreamResponseListener.java:226)
at org.restlet.ext.jetty.internal.JettyClientCall.sendRequest(JettyClientCall.java:275)
at org.restlet.engine.adapter.ClientAdapter.commit(ClientAdapter.java:105)
at org.restlet.engine.adapter.HttpClientHelper.handle(HttpClientHelper.java:119)
at org.restlet.Client.handle(Client.java:153)
at org.restlet.Restlet.handle(Restlet.java:275)
at com.ti.itg.peit.core.ftds.http.util.HTTPRequest.genericRequest(HTTPRequest.java:115)
at com.ti.itg.peit.core.ftds.http.util.HTTPRequest.getRequest(HTTPRequest.java:72)