Class PDFProxyServlet

  • All Implemented Interfaces:
    org.xml.sax.ErrorHandler

    public abstract class PDFProxyServlet
    extends HttpProxyServlet
    implements org.xml.sax.ErrorHandler

    The PDFProxyServlet is a basic servlet which accepts a request, reads an XML report from another URL and turns it into a PDF to be returned to the client. Those using the Servlet 2.3 architecture may want to consider using the PDFFilter class instead.

    Most overriders should be able to just override the getProxyURL() method, to alter where the report XML is kept.

    Meta tags that aren't already known to the Report Generator and that begin with "HTTP-" are added to the response header (minus the "HTTP-" prefix). An example would be to place <meta name="HTTP-Expires" value="Mon, 01 Jan 1999 12:00:00 GMT"> in the head of the XML, which would set the "Expires" header in the HTTP response.

    The following custom Meta-Tags may also be used to control the behaviour of the servlet.

    • Servlet-Cache - set the length of time to cache the generated PDF. The cache is actually implemented in the ProxyServlet, and is completely independent of any external caches between the server and the client. Examples of valid values are "1h30m", to cache the document for 1.5 hours, "45s" to cache for 45 seconds or "1d" to cache for 1 day. Any combination of days, hours, minutes and seconds is valid. There is no way to flush this document from the client browser.
    • Servlet-FileName - ask the client browser to save the file as the specified filename instead of displaying it inline. This uses the Content-Disposition header, which in theory is accepted by NS4+ and IE5+. On our test system at least however, this didn't work, and in IE5.5 actually prevented us from viewing the document at all! Use with caution.
    Some initialization parameters can be set in the web.xml file to further control various internal aspects of the servlet:
    • org.xml.sax.driver - may be set to the base class of your SAX parsers XMLReader implementation, if the generator is unable to locate it.
    • org.faceless.util.proxytimeout - may be set to the number of milliseconds to wait for a response from the proxy request. Defaults to 15000, or 15 seconds.

    This class also implements org.xml.sax.ErrorHandler, to deal with any errors found during the XML parsing process. Currently all warnings and errors are fatal, and logged to System.err.

    • Constructor Summary

      Constructors 
      Constructor Description
      PDFProxyServlet()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void error​(org.xml.sax.SAXParseException exception)  
      void fatalError​(org.xml.sax.SAXParseException exception)  
      abstract java.lang.String getProxyURL​(HttpServletRequest request, HttpServletResponse response)
      Returns the absolute URL to send the proxy request to.
      HttpRequestWriter getRequest​(HttpRequestReader request, HttpServletResponse response)
      Implements the getRequest method of the generic HttpProxyServlet.
      HttpResponseWriter getResponse​(HttpResponseReader in)
      Implements the getResponse method of the generic HttpProxyServlet.
      void init()  
      void initParser​(ReportParser parser)
      Set any initialization options for the parser, if necessary.
      void metaTag​(HttpResponseReader reader, HttpResponseWriter writer, java.lang.String name, java.lang.String value)
      Handle any meta tags that aren't recognised by the core Report Generator.
      void modifyPDF​(PDF pdf)
      Adjust the PDF after it's been created but before it's rendered back to the browser.
      void warning​(org.xml.sax.SAXParseException exception)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PDFProxyServlet

        public PDFProxyServlet()
    • Method Detail

      • getRequest

        public HttpRequestWriter getRequest​(HttpRequestReader request,
                                            HttpServletResponse response)
                                     throws ServletException,
                                            java.io.IOException
        Implements the getRequest method of the generic HttpProxyServlet. Subclasses should be able to leave this method untouched.
        Throws:
        ServletException
        java.io.IOException
      • getResponse

        public HttpResponseWriter getResponse​(HttpResponseReader in)
                                       throws ServletException,
                                              java.io.IOException
        Implements the getResponse method of the generic HttpProxyServlet. Subclasses should be able to leave this method untouched.
        Throws:
        ServletException
        java.io.IOException
      • metaTag

        public void metaTag​(HttpResponseReader reader,
                            HttpResponseWriter writer,
                            java.lang.String name,
                            java.lang.String value)
                     throws ServletException,
                            java.io.IOException
        Handle any meta tags that aren't recognised by the core Report Generator. This method recognises tags begining with HTTP-, as well as Servlet-FileName and Servlet-Cache.
        Parameters:
        request - the Servlet request
        response - the Servlet request
        name - the "name" attribute from the meta tag
        value - the "value" attribute from the meta tag
        Throws:
        ServletException
        java.io.IOException
      • warning

        public void warning​(org.xml.sax.SAXParseException exception)
                     throws org.xml.sax.SAXException
        Specified by:
        warning in interface org.xml.sax.ErrorHandler
        Throws:
        org.xml.sax.SAXException
      • error

        public void error​(org.xml.sax.SAXParseException exception)
                   throws org.xml.sax.SAXException
        Specified by:
        error in interface org.xml.sax.ErrorHandler
        Throws:
        org.xml.sax.SAXException
      • fatalError

        public void fatalError​(org.xml.sax.SAXParseException exception)
                        throws org.xml.sax.SAXException
        Specified by:
        fatalError in interface org.xml.sax.ErrorHandler
        Throws:
        org.xml.sax.SAXException
      • initParser

        public void initParser​(ReportParser parser)
        Set any initialization options for the parser, if necessary. Overriders may optionally use this method to set parser flags (by default, this method does nothing).
        Since:
        1.0.4
      • modifyPDF

        public void modifyPDF​(PDF pdf)
        Adjust the PDF after it's been created but before it's rendered back to the browser. Subclassers who need to alter the PDF in some way should override this method and make any changes they need to make to the PDF there.
        Since:
        1.1.27
      • getProxyURL

        public abstract java.lang.String getProxyURL​(HttpServletRequest request,
                                                     HttpServletResponse response)
                                              throws java.io.IOException,
                                                     ServletException

        Returns the absolute URL to send the proxy request to. This method is the only method that needs to be overriden by concrete subclasses of this class.

        If no valid URL can be constructed due to an incorrect request, this method should return null and an appropriate error written to the response.

        Parameters:
        request - the incoming request from the client
        response - the outgoing response to the client - should only be written to if an error has occurred and the method is returning null
        Returns:
        the absolute URL to proxy the request to, or null if an error has occurred and no request should be made.
        Throws:
        java.io.IOException
        ServletException