public class

ConfluenceVelocityServlet

extends HttpServlet
java.lang.Object
   ↳ javax.servlet.GenericServlet
     ↳ javax.servlet.http.HttpServlet
       ↳ com.atlassian.confluence.servlet.ConfluenceVelocityServlet

Class Overview

An improved WW VelocityServlet which doesn't load velocity twice!

We have copied code here because we can't override the WebWorkVelocityServlet as it calls VelocityServlet.init() which loads _another_ entire identical instance of Velocity (beyond the VelocityManager's instance), and the two are used interchangeably.

http://jira.atlassian.com/browse/CONF-6355

Summary

Constants
String DEFAULT_CONTENT_TYPE The default content type for the response
Public Constructors
ConfluenceVelocityServlet()
Public Methods
void doGet(HttpServletRequest request, HttpServletResponse response)
Handles GET - calls doRequest()
void doPost(HttpServletRequest request, HttpServletResponse response)
Handle a POST request - calls doRequest()
Template getTemplate(String name, String encoding)
Retrieves the requested template with the specified character encoding.
void init(ServletConfig servletConfig)
Protected Methods
Context createContext(HttpServletRequest request, HttpServletResponse response)
void doRequest(HttpServletRequest request, HttpServletResponse response)
Handles all requests
void error(HttpServletRequest request, HttpServletResponse response, Exception cause)
Invoked when there is an error thrown in any part of doRequest() processing.
String getEncoding()
Template handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Context context)
void mergeTemplate(Template template, Context context, HttpServletResponse response)
Copy of the method from WebworkVelocityServlet, adding a flush for the writer to get around problems we were having with truncated content when a filter started talking directly to the servletresponse writer without the webwork writer having been flushed in the meanwhile.
void setContentType(HttpServletRequest request, HttpServletResponse response)
Sets the content type of the response.
[Expand]
Inherited Methods
From class javax.servlet.http.HttpServlet
From class javax.servlet.GenericServlet
From class java.lang.Object
From interface javax.servlet.Servlet
From interface javax.servlet.ServletConfig

Constants

public static final String DEFAULT_CONTENT_TYPE

The default content type for the response

Constant Value: "text/html"

Public Constructors

public ConfluenceVelocityServlet ()

Public Methods

public void doGet (HttpServletRequest request, HttpServletResponse response)

Handles GET - calls doRequest()

Throws
IOException
ServletException

public void doPost (HttpServletRequest request, HttpServletResponse response)

Handle a POST request - calls doRequest()

Throws
IOException
ServletException

public Template getTemplate (String name, String encoding)

Retrieves the requested template with the specified character encoding.

Parameters
name The file name of the template to retrieve relative to the template root.
encoding the character encoding of the template
Returns
  • The requested template.
Throws
ResourceNotFoundException if template not found from any available source.
ParseErrorException if template cannot be parsed due to syntax (or other) error.
Exception if an error occurs in template initialization

public void init (ServletConfig servletConfig)

Throws
ServletException

Protected Methods

protected Context createContext (HttpServletRequest request, HttpServletResponse response)

protected void doRequest (HttpServletRequest request, HttpServletResponse response)

Handles all requests

Parameters
request HttpServletRequest object containing client request
response HttpServletResponse object for the response
Throws
IOException
ServletException

protected void error (HttpServletRequest request, HttpServletResponse response, Exception cause)

Invoked when there is an error thrown in any part of doRequest() processing.

Default will send a simple HTML response indicating there was a problem.

Parameters
request original HttpServletRequest from servlet container.
response HttpServletResponse object from servlet container.
cause Exception that was thrown by some other part of process.
Throws
IOException
ServletException

protected String getEncoding ()

protected Template handleRequest (HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Context context)

Throws
Exception

protected void mergeTemplate (Template template, Context context, HttpServletResponse response)

Copy of the method from WebworkVelocityServlet, adding a flush for the writer to get around problems we were having with truncated content when a filter started talking directly to the servletresponse writer without the webwork writer having been flushed in the meanwhile. TODO: When this gets fixed in WebWork, remove this method.

protected void setContentType (HttpServletRequest request, HttpServletResponse response)

Sets the content type of the response. This is available to be overriden by a derived class.

The default implementation is :

response.setContentType( defaultContentType );

where defaultContentType is set to the value of the default.contentType property, or "text/html" if that is not set.
Parameters
request servlet request from client
response servlet reponse to client