java.io.IOException: Server returned HTTP response code: 503 for URL: http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
Asked Answered
S

2

5

In the following code:

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();
}

I get this exception:

java.io.IOException: Server returned HTTP response code: 503 for URL: http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd

The XHTML I'm translating over via xsl is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
  <title>Terms and Conditions</title>
</head>
<body>
  <div>Test Content</div>
</body>
</html>

How do I stop the xalan transformer from phoning home?

Smokeproof answered 23/3, 2010 at 18:27 Comment(0)
C
1

This post from the Xalan-J mailing list suggests that "the right way" is for you to configure the underlying Source/Reader yourself to disable validation.

Circumjacent answered 23/3, 2010 at 18:35 Comment(1)
You need the following to get it 100% right, but that mailing list link was most helpful! SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true); spf.setValidating(false); // Turn off validation spf.setFeature("apache.org/xml/features/nonvalidating/load-external-dtd", false); XMLReader rdr = spf.newSAXParser().getXMLReader();Smokeproof
S
2

Either disable DTD resolving in the parser (parser-specific) or set an empty entity resolver.

Copied from 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());
Schweiz answered 23/3, 2010 at 18:38 Comment(0)
C
1

This post from the Xalan-J mailing list suggests that "the right way" is for you to configure the underlying Source/Reader yourself to disable validation.

Circumjacent answered 23/3, 2010 at 18:35 Comment(1)
You need the following to get it 100% right, but that mailing list link was most helpful! SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true); spf.setValidating(false); // Turn off validation spf.setFeature("apache.org/xml/features/nonvalidating/load-external-dtd", false); XMLReader rdr = spf.newSAXParser().getXMLReader();Smokeproof

© 2022 - 2024 — McMap. All rights reserved.