Class PDFProxyServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- org.faceless.report.PDFProxyServlet
-
- All Implemented Interfaces:
java.io.Serializable
,Servlet
,ServletConfig
,org.xml.sax.ErrorHandler
public abstract class PDFProxyServlet extends HttpServlet 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.
- 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.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description PDFProxyServlet()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
doGet(HttpServletRequest request, HttpServletResponse response)
void
doPost(HttpServletRequest request, HttpServletResponse response)
Currently the POST method is unimplemented, and returns a 405 error to the browser.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.org.faceless.report.HttpRequestWriter
getRequest(org.faceless.report.HttpRequestReader request, HttpServletResponse response)
Implements the getRequest method of the generic HttpProxyServlet.org.faceless.report.HttpResponseWriter
getResponse(org.faceless.report.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(org.faceless.report.HttpResponseReader reader, org.faceless.report.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 javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
-
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
-
-
-
-
Method Detail
-
init
public void init() throws ServletException
- Throws:
ServletException
-
getRequest
public org.faceless.report.HttpRequestWriter getRequest(org.faceless.report.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.- Parameters:
request
- the incoming request to this proxyresponse
- the outgoing response. Should only be written to if this method is returning null due to an error.- Returns:
- the request that this proxy should pass on.
- Throws:
ServletException
java.io.IOException
-
getResponse
public org.faceless.report.HttpResponseWriter getResponse(org.faceless.report.HttpResponseReader in) throws ServletException, java.io.IOException
Implements the getResponse method of the generic HttpProxyServlet. Subclasses should be able to leave this method untouched.- Parameters:
in
- the response from the request specified by getRequest()- Returns:
- the response that this proxy should pass on
- Throws:
ServletException
java.io.IOException
-
metaTag
public void metaTag(org.faceless.report.HttpResponseReader reader, org.faceless.report.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 requestresponse
- the Servlet requestname
- the "name" attribute from the meta tagvalue
- 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 interfaceorg.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 interfaceorg.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 interfaceorg.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 clientresponse
- 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
-
doPost
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException
Currently the POST method is unimplemented, and returns a 405 error to the browser.- Overrides:
doPost
in classHttpServlet
- Throws:
ServletException
java.io.IOException
-
doGet
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException
- Overrides:
doGet
in classHttpServlet
- Throws:
ServletException
java.io.IOException
-
-