Package com.atlassian.confluence.servlet
Class ConfluenceVelocityServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- com.atlassian.confluence.servlet.ConfluenceVelocityServlet
-
- All Implemented Interfaces:
Serializable
,javax.servlet.Servlet
,javax.servlet.ServletConfig
public class ConfluenceVelocityServlet extends javax.servlet.http.HttpServlet
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
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_CONTENT_TYPE
The default content type for the response
-
Constructor Summary
Constructors Constructor Description ConfluenceVelocityServlet()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.apache.velocity.context.Context
createContext(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
void
doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Handles GET - calls doRequest()void
doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Handle a POST request - calls doRequest()protected void
doRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Handles all requestsprotected void
error(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Exception cause)
Invoked when there is an error thrown in any part of doRequest() processing.protected String
getEncoding()
org.apache.velocity.Template
getTemplate(String name, String encoding)
Retrieves the requested template with the specified character encoding.protected org.apache.velocity.Template
handleRequest(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse, org.apache.velocity.context.Context context)
void
init(javax.servlet.ServletConfig servletConfig)
protected void
mergeTemplate(org.apache.velocity.Template template, org.apache.velocity.context.Context context, javax.servlet.http.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 struts writer having been flushed in the meanwhile.protected void
setContentType(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Sets the content type of the response.-
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
-
-
-
-
Field Detail
-
DEFAULT_CONTENT_TYPE
public static final String DEFAULT_CONTENT_TYPE
The default content type for the response- See Also:
- Constant Field Values
-
-
Method Detail
-
init
public void init(javax.servlet.ServletConfig servletConfig) throws javax.servlet.ServletException
- Specified by:
init
in interfacejavax.servlet.Servlet
- Overrides:
init
in classjavax.servlet.GenericServlet
- Throws:
javax.servlet.ServletException
-
createContext
protected org.apache.velocity.context.Context createContext(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
-
handleRequest
protected org.apache.velocity.Template handleRequest(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse, org.apache.velocity.context.Context context) throws Exception
- Throws:
Exception
-
getEncoding
protected String getEncoding()
-
getTemplate
public org.apache.velocity.Template getTemplate(String name, String encoding) throws org.apache.velocity.exception.ResourceNotFoundException, org.apache.velocity.exception.ParseErrorException, Exception
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:
org.apache.velocity.exception.ResourceNotFoundException
- if template not found from any available source.org.apache.velocity.exception.ParseErrorException
- if template cannot be parsed due to syntax (or other) error.Exception
- if an error occurs in template initialization- Since:
- 2.3
-
doGet
public void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
Handles GET - calls doRequest()- Overrides:
doGet
in classjavax.servlet.http.HttpServlet
- Throws:
javax.servlet.ServletException
IOException
-
doPost
public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
Handle a POST request - calls doRequest()- Overrides:
doPost
in classjavax.servlet.http.HttpServlet
- Throws:
javax.servlet.ServletException
IOException
-
doRequest
protected void doRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
Handles all requests- Parameters:
request
- HttpServletRequest object containing client requestresponse
- HttpServletResponse object for the response- Throws:
javax.servlet.ServletException
IOException
-
setContentType
protected void setContentType(javax.servlet.http.HttpServletRequest request, javax.servlet.http.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 clientresponse
- servlet reponse to client
-
mergeTemplate
protected void mergeTemplate(org.apache.velocity.Template template, org.apache.velocity.context.Context context, javax.servlet.http.HttpServletResponse response) throws org.apache.velocity.exception.ResourceNotFoundException, org.apache.velocity.exception.ParseErrorException, org.apache.velocity.exception.MethodInvocationException, IOException, UnsupportedEncodingException, Exception
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 struts writer having been flushed in the meanwhile.TODO: When this gets fixed in WebWork, remove this method.
- Throws:
org.apache.velocity.exception.ResourceNotFoundException
org.apache.velocity.exception.ParseErrorException
org.apache.velocity.exception.MethodInvocationException
IOException
UnsupportedEncodingException
Exception
-
error
protected void error(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Exception cause) throws javax.servlet.ServletException, IOException
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:
javax.servlet.ServletException
IOException
-
-