Search code examples
javajsptomcatservletsflying-saucer

Java URL Read Issue


I am using Flying Saucer to read contents of a JSP file from a servlet and generate a PDF. The domain is the same. It works on localhost but fails on server even thought the webapp has all privileges granted. I've tested by reading from different domain (works), reading in a generic url file without PDF (fails on server).

So I am not sure if it's a servlet or Tomcat configuration to enable the servlet to retrieve contents of a URL on the same domain?

Here is the timeout error:

org.xhtmlrenderer.util.XRRuntimeException: Can't load the XML resource (using TRaX transformer). java.io.IOException: Stream closed
    org.xhtmlrenderer.resource.XMLResource$XMLResourceBuilder.createXMLResource(XMLResource.java:191)
    org.xhtmlrenderer.resource.XMLResource.load(XMLResource.java:71)
    org.xhtmlrenderer.swing.NaiveUserAgent.getXMLResource(NaiveUserAgent.java:211)
    org.xhtmlrenderer.pdf.ITextRenderer.loadDocument(ITextRenderer.java:134)
    org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:138)
    com.cusa.sms.reportprinter.ReportPrinter.doGet(Unknown Source)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:585)
    org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
    java.security.AccessController.doPrivileged(Native Method)
    javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
    org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276)
    org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)

Solution

  • Feeling like a massive idiot at the moment, but it's fixed. Server names are resolved internally as well and it's not guarantee that all hosts do that automatically for you. Just because I could see the page from my connection doesn't mean that the app could see the page from internal connection. So adding necessary host entries to /etc/hosts fixed all the problems.