java.io.IOException:服务器返回HTTP响应代码:503为URL:http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
在以下代码中:
private Document transformDoc(Source source) throws TransformerException, IOException { TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(new StreamSource(xsltResource.getInputStream())); JDOMResult result = new JDOMResult(); transformer.transform(source, result); return result.getDocument(); }
我得到这个例外:
java.io.IOException: Server returned HTTP response code: 503 for URL: http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
我通过xsl翻译的XHTML是:
Terms and Conditions Test Content
如何阻止xalan变压器打电话回家?
来自Xalan-J邮件列表的这篇文章表明,“正确的方法”是您自己配置底层的Source
/ Reader
以禁用validation。
在解析器中禁用DTD解析(特定于解析器)或设置空实体解析器。
复制自http://www.jdom.org/docs/faq.html#a0350 :
public class NoOpEntityResolver implements EntityResolver { public InputSource resolveEntity(String publicId, String systemId) { return new InputSource(new StringBufferInputStream("")); } } // Then in the builder... builder.setEntityResolver(new NoOpEntityResolver());