com.vaadin.terminal.gwt.server
Class AbstractApplicationServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by com.vaadin.terminal.gwt.server.AbstractApplicationServlet
All Implemented Interfaces:
Constants, Serializable, Servlet, ServletConfig
Direct Known Subclasses:
ApplicationServlet

public abstract class AbstractApplicationServlet
extends HttpServlet
implements Constants

Abstract implementation of the ApplicationServlet which handles all communication between the client and the server. It is possible to extend this class to provide own functionality but in most cases this is unnecessary.

Since:
6.0
Version:
7.0.0.alpha3
Author:
Vaadin Ltd.
See Also:
Serialized Form

Nested Class Summary
 class AbstractApplicationServlet.RequestError
           
protected static class AbstractApplicationServlet.RequestType
           
 
Field Summary
 
Fields inherited from interface com.vaadin.terminal.gwt.server.Constants
AJAX_UIDL_URI, DEFAULT_BUFFER_SIZE, DEFAULT_THEME_CACHETIME, DEFAULT_THEME_NAME, DEFAULT_WIDGETSET, ERROR_NO_ROOT_FOUND, INVALID_SECURITY_KEY_MSG, MAX_BUFFER_SIZE, NOT_PRODUCTION_MODE_INFO, PARAMETER_VAADIN_RESOURCES, PARAMETER_WIDGETSET, PORTAL_PARAMETER_VAADIN_RESOURCE_PATH, PORTAL_PARAMETER_VAADIN_THEME, PORTAL_PARAMETER_VAADIN_WIDGETSET, SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION, SERVLET_PARAMETER_PRODUCTION_MODE, SERVLET_PARAMETER_RESOURCE_CACHE_TIME, THEME_DIRECTORY_PATH, URL_PARAMETER_CLOSE_APPLICATION, URL_PARAMETER_REPAINT_ALL, URL_PARAMETER_RESTART_APPLICATION, URL_PARAMETER_THEME, WARNING_RESOURCE_CACHING_TIME_NOT_NUMERIC, WARNING_XSRF_PROTECTION_DISABLED, WIDGETSET_DIRECTORY_PATH, WIDGETSET_MISMATCH_INFO
 
Constructor Summary
AbstractApplicationServlet()
           
 
Method Summary
 CommunicationManager createCommunicationManager(Application application)
          Deprecated. Instead of overriding this method, override WebApplicationContext implementation via getApplicationContext(HttpSession) method and in that customized implementation return your CommunicationManager in WebApplicationContext.getApplicationManager(Application, AbstractApplicationServlet) method.
protected  WrappedHttpServletRequest createWrappedRequest(HttpServletRequest request)
          Create a wrapped request for a http servlet request.
protected  void criticalNotification(HttpServletRequest request, HttpServletResponse response, String caption, String message, String details, String url)
          Send a notification to client's application.
protected abstract  Class<? extends Application> getApplicationClass()
           
protected  WebApplicationContext getApplicationContext(HttpSession session)
          Gets the application context from an HttpSession.
protected  String getApplicationProperty(String parameterName)
          Gets an application property value.
protected  URL getApplicationUrl(HttpServletRequest request)
          Gets the current application URL from request.
protected  ClassLoader getClassLoader()
           
static String getDefaultTheme()
          Returns the default theme.
protected  DeploymentConfiguration getDeploymentConfiguration()
          Gets a the deployment configuration for this servlet.
protected  Application getExistingApplication(HttpServletRequest request, boolean allowSessionCreation)
          Gets the existing application for given request.
protected abstract  Application getNewApplication(HttpServletRequest request)
          Creates a new application for the given request.
protected  String getRequestPathInfo(HttpServletRequest request)
          Returns the path info; note that this _can_ be different than request.getPathInfo().
protected  AbstractApplicationServlet.RequestType getRequestType(HttpServletRequest request)
           
 int getResourceCacheTime()
          Returns the amount of milliseconds the browser should cache a file.
 String getResourceLocation(String theme, ThemeResource resource)
          Gets relative location of a theme resource.
protected static String getResourcePath(ServletContext servletContext, String path)
          Gets resource path using different implementations.
protected  String getStaticFilesLocation(HttpServletRequest request)
          Return the URL from where static files, e.g.
protected  Application.SystemMessages getSystemMessages()
          Get system messages from the current application class
static Application.SystemMessages getSystemMessages(Class<? extends Application> appCls)
           
protected  String getSystemProperty(String parameterName)
          Gets an system property value.
 void init(ServletConfig servletConfig)
          Called by the servlet container to indicate to a servlet that the servlet is being placed into service.
protected  boolean isAllowedVAADINResourceUrl(HttpServletRequest request, URL resourceUrl)
          Check whether a URL obtained from a classloader refers to a valid static resource in the directory VAADIN.
 boolean isProductionMode()
          Returns true if the servlet is running in production mode.
static String safeEscapeForHtml(String unsafe)
          Escapes characters to html entities.
protected  void service(HttpServletRequest request, HttpServletResponse response)
          Receives standard HTTP requests from the public service method and dispatches them.
protected static String stripSpecialChars(String themeName)
          A helper method to strip away characters that might somehow be used for XSS attacs.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractApplicationServlet

public AbstractApplicationServlet()
Method Detail

init

public void init(ServletConfig servletConfig)
          throws ServletException
Called by the servlet container to indicate to a servlet that the servlet is being placed into service.

Specified by:
init in interface Servlet
Overrides:
init in class GenericServlet
Parameters:
servletConfig - the object containing the servlet's configuration and initialization parameters
Throws:
ServletException - if an exception has occurred that interferes with the servlet's normal operation.

getApplicationProperty

protected String getApplicationProperty(String parameterName)
Gets an application property value.

Parameters:
parameterName - the Name or the parameter.
Returns:
String value or null if not found

getSystemProperty

protected String getSystemProperty(String parameterName)
Gets an system property value.

Parameters:
parameterName - the Name or the parameter.
Returns:
String value or null if not found

isProductionMode

public boolean isProductionMode()
Returns true if the servlet is running in production mode. Production mode disables all debug facilities.

Returns:
true if in production mode, false if in debug mode

getResourceCacheTime

public int getResourceCacheTime()
Returns the amount of milliseconds the browser should cache a file. Default is 1 hour (3600 ms).

Returns:
The amount of milliseconds files are cached in the browser

service

protected void service(HttpServletRequest request,
                       HttpServletResponse response)
                throws ServletException,
                       IOException
Receives standard HTTP requests from the public service method and dispatches them.

Overrides:
service in class HttpServlet
Parameters:
request - the object that contains the request the client made of the servlet.
response - the object that contains the response the servlet returns to the client.
Throws:
ServletException - if an input or output error occurs while the servlet is handling the TRACE request.
IOException - if the request for the TRACE cannot be handled.

createWrappedRequest

protected WrappedHttpServletRequest createWrappedRequest(HttpServletRequest request)
Create a wrapped request for a http servlet request. This method can be overridden if the wrapped request should have special properties.

Parameters:
request - the original http servlet request
Returns:
a wrapped request for the original request

getDeploymentConfiguration

protected DeploymentConfiguration getDeploymentConfiguration()
Gets a the deployment configuration for this servlet.

Returns:
the deployment configuration

getClassLoader

protected ClassLoader getClassLoader()
                              throws ServletException
Throws:
ServletException

criticalNotification

protected void criticalNotification(HttpServletRequest request,
                                    HttpServletResponse response,
                                    String caption,
                                    String message,
                                    String details,
                                    String url)
                             throws IOException
Send a notification to client's application. Used to notify client of critical errors, session expiration and more. Server has no knowledge of what application client refers to.

Parameters:
request - the HTTP request instance.
response - the HTTP response to write to.
caption - the notification caption
message - to notification body
details - a detail message to show in addition to the message. Currently shown directly below the message but could be hidden behind a details drop down in the future. Mainly used to give additional information not necessarily useful to the end user.
url - url to load when the message is dismissed. Null will reload the current page.
Throws:
IOException - if the writing failed due to input/output error.

getResourcePath

protected static String getResourcePath(ServletContext servletContext,
                                        String path)
Gets resource path using different implementations. Required to supporting different servlet container implementations (application servers).

Parameters:
servletContext -
path - the resource path.
Returns:
the resource path.

stripSpecialChars

protected static String stripSpecialChars(String themeName)
A helper method to strip away characters that might somehow be used for XSS attacs. Leaves at least alphanumeric characters intact. Also removes eg. ( and ), so values should be safe in javascript too.

Parameters:
themeName -
Returns:

getDefaultTheme

public static String getDefaultTheme()
Returns the default theme. Must never return null.

Returns:

getNewApplication

protected abstract Application getNewApplication(HttpServletRequest request)
                                          throws ServletException
Creates a new application for the given request.

Parameters:
request - the HTTP request.
Returns:
A new Application instance.
Throws:
ServletException

isAllowedVAADINResourceUrl

protected boolean isAllowedVAADINResourceUrl(HttpServletRequest request,
                                             URL resourceUrl)
Check whether a URL obtained from a classloader refers to a valid static resource in the directory VAADIN. Warning: Overriding of this method is not recommended, but is possible to support non-default classloaders or servers that may produce URLs different from the normal ones. The method prototype may change in the future. Care should be taken not to expose class files or other resources outside the VAADIN directory if the method is overridden.

Parameters:
request -
resourceUrl -
Returns:
Since:
6.6.7

getRequestType

protected AbstractApplicationServlet.RequestType getRequestType(HttpServletRequest request)

getSystemMessages

protected Application.SystemMessages getSystemMessages()
Get system messages from the current application class

Returns:

getSystemMessages

public static Application.SystemMessages getSystemMessages(Class<? extends Application> appCls)

getApplicationClass

protected abstract Class<? extends Application> getApplicationClass()
                                                             throws ClassNotFoundException
Throws:
ClassNotFoundException

getStaticFilesLocation

protected String getStaticFilesLocation(HttpServletRequest request)
Return the URL from where static files, e.g. the widgetset and the theme, are served. In a standard configuration the VAADIN folder inside the returned folder is what is used for widgetsets and themes. The returned folder is usually the same as the context path and independent of the application.

Parameters:
request -
Returns:
The location of static resources (should contain the VAADIN directory). Never ends with a slash (/).

getApplicationUrl

protected URL getApplicationUrl(HttpServletRequest request)
                         throws MalformedURLException
Gets the current application URL from request.

Parameters:
request - the HTTP request.
Throws:
MalformedURLException - if the application is denied access to the persistent data store represented by the given URL.

getExistingApplication

protected Application getExistingApplication(HttpServletRequest request,
                                             boolean allowSessionCreation)
                                      throws MalformedURLException,
                                             SessionExpiredException
Gets the existing application for given request. Looks for application instance for given request based on the requested URL.

Parameters:
request - the HTTP request.
allowSessionCreation - true if a session should be created if no session exists, false if no session should be created
Returns:
Application instance, or null if the URL does not map to valid application.
Throws:
MalformedURLException - if the application is denied access to the persistent data store represented by the given URL.
IllegalAccessException
InstantiationException
SessionExpiredException

getRequestPathInfo

protected String getRequestPathInfo(HttpServletRequest request)
Returns the path info; note that this _can_ be different than request.getPathInfo(). Examples where this might be useful:

getResourceLocation

public String getResourceLocation(String theme,
                                  ThemeResource resource)
Gets relative location of a theme resource.

Parameters:
theme - the Theme name.
resource - the Theme resource.
Returns:
External URI specifying the resource

getApplicationContext

protected WebApplicationContext getApplicationContext(HttpSession session)
Gets the application context from an HttpSession. If no context is currently stored in a session a new context is created and stored in the session.

Parameters:
session - the HTTP session.
Returns:
the application context for HttpSession.

createCommunicationManager

@Deprecated
public CommunicationManager createCommunicationManager(Application application)
Deprecated. Instead of overriding this method, override WebApplicationContext implementation via getApplicationContext(HttpSession) method and in that customized implementation return your CommunicationManager in WebApplicationContext.getApplicationManager(Application, AbstractApplicationServlet) method.

Override this method if you need to use a specialized communicaiton mananger implementation.

Parameters:
application -
Returns:

safeEscapeForHtml

public static final String safeEscapeForHtml(String unsafe)
Escapes characters to html entities. An exception is made for some "safe characters" to keep the text somewhat readable.

Parameters:
unsafe -
Returns:
a safe string to be added inside an html tag


Copyright © 2000-2011 Vaadin Ltd. All Rights Reserved.