org.apache.wicket.protocol.http
Class WebApplication

java.lang.Object
  extended by org.apache.wicket.Application
      extended by org.apache.wicket.protocol.http.WebApplication
Direct Known Subclasses:
Application, AuthenticatedWebApplication, BaseWicketTester.DummyWebApplication, BreadCrumbApplication, RepeaterApplication, RolesApplication, SpringWebApplication, VelocityTemplateApplication, WicketExampleApplication, WicketExamplesMenuApplication, WicketTester.DummyWebApplication, WizardApplication

public abstract class WebApplication
extends Application

A web application is a subclass of Application which associates with an instance of WicketServlet to serve pages over the HTTP protocol. This class is intended to be subclassed by framework clients to define a web application.

Application settings are given defaults by the WebApplication() constructor and internalInit method, such as error page classes appropriate for HTML. WebApplication subclasses can override these values and/or modify other application settings by overriding the init() method and then by calling getXXXSettings() to retrieve an interface to a mutable Settings object. Do not do this in the constructor itself because the defaults will then override your settings.

If you want to use a filter specific configuration, e.g. using init parameters from the FilterConfig object, you should override the init() method. For example:

  public void init() {
  String webXMLParameter = getInitParameter("myWebXMLParameter");
  URL schedulersConfig = getServletContext().getResource("/WEB-INF/schedulers.xml");
  ...
 

Author:
Jonathan Locke, Chris Turner, Johan Compagner, Eelco Hillenius, Juergen Donnerstag
See Also:
WicketFilter, IApplicationSettings, IDebugSettings, IExceptionSettings, IMarkupSettings, IPageSettings, IRequestCycleSettings, IResourceSettings, ISecuritySettings, ISessionSettings, Filter, FilterConfig, ServletContext

Field Summary
 
Fields inherited from class org.apache.wicket.Application
CONFIGURATION, CONTEXTPATH, DEPLOYMENT, DEVELOPMENT
 
Constructor Summary
WebApplication()
          Constructor.
 
Method Summary
 java.lang.String getApplicationKey()
          Gets the unique key of this application within a given context (like a web application).
 java.lang.String getConfigurationType()
          Gets the configuration mode to use for configuring the app, either Application.DEVELOPMENT or Application.DEPLOYMENT.
protected  java.lang.Object getDefaultRequestCycleFactory()
          Deprecated. Replaced by newRequestCycle(Request, Response)
 java.lang.String getInitParameter(java.lang.String key)
          Gets an init parameter of the filter, or null if the parameter does not exist.
 IRequestCycleProcessor getRequestCycleProcessor()
          Gets the default request cycle processor (with lazy initialization).
protected  IResourceFinder getResourceFinder()
           
 javax.servlet.ServletContext getServletContext()
          Gets the servlet context for this application.
 java.lang.String getSessionAttributePrefix(WebRequest request)
          Gets the prefix for storing variables in the actual session (typically HttpSession for this application instance.
 WicketFilter getWicketFilter()
           
protected  void init()
          Initialize; if you need the wicket servlet for initialization, e.g.
protected  void internalDestroy()
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
protected  void internalInit()
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
 void logEventTarget(IRequestTarget target)
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
 void logResponseTarget(IRequestTarget target)
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
 void mount(IRequestTargetUrlCodingStrategy encoder)
          Mounts an encoder at the given path.
 void mount(java.lang.String path, PackageName packageName)
          Mounts all bookmarkable pages at the given path.
 void mountBookmarkablePage(java.lang.String path, java.lang.Class bookmarkablePageClass)
          Mounts a bookmarkable page class to the given path.
 void mountBookmarkablePage(java.lang.String path, java.lang.String pageMapName, java.lang.Class bookmarkablePageClass)
          Mounts a bookmarkable page class to the given pagemap and path.
 void mountSharedResource(java.lang.String path, java.lang.String resourceKey)
          Mounts a shared resource class to the given path.
 AjaxRequestTarget newAjaxRequestTarget(Page page)
          Creates a new ajax request target used to control ajax responses
 RequestCycle newRequestCycle(Request request, Response response)
          Creates a new RequestCycle object.
protected  IRequestCycleProcessor newRequestCycleProcessor()
          Gets a new request cycle processor for web requests.
 Session newSession()
          Deprecated. see newSession(Request, Response).
 Session newSession(Request request)
          Deprecated. newSession(Request, Response).
 Session newSession(Request request, Response response)
          Creates a new session.
protected  ISessionStore newSessionStore()
          Creates a new session facade.
protected  WebRequest newWebRequest(javax.servlet.http.HttpServletRequest servletRequest)
          Create a new WebRequest.
protected  WebResponse newWebResponse(javax.servlet.http.HttpServletResponse servletResponse)
          Create a WebResponse.
protected  void outputDevelopmentModeWarning()
          This method prints a warning to stderr that we are starting in development mode.
 void sessionDestroyed(java.lang.String sessionId)
           
protected  void setApplicationKey(java.lang.String applicationKey)
          Set the application key value
 void setWicketFilter(WicketFilter wicketFilter)
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
 void unmount(java.lang.String path)
          Unmounts whatever encoder is mounted at a given path.
 
Methods inherited from class org.apache.wicket.Application
addComponentInstantiationListener, addComponentOnAfterRenderListener, addComponentOnBeforeRenderListener, addRenderHeadListener, configure, destroy, exists, get, get, getApplicationKeys, getApplicationSettings, getConverterLocator, getDebugSettings, getExceptionSettings, getFrameworkSettings, getHomePage, getMarkupCache, getMarkupSettings, getMetaData, getName, getPageSettings, getRequestCycleFactory, getRequestCycleSettings, getRequestLogger, getRequestLoggerSettings, getResourceSettings, getSecuritySettings, getSessionFactory, getSessionSettings, getSessionStore, getSharedResources, initializeComponents, newConverterLocator, newRequestCycle, newRequestLogger, notifyRenderHeadListener, onDestroy, removeComponentInstantiationListener, removeComponentOnAfterRenderListener, removeComponentOnBeforeRenderListener, removeRenderHeadListener, set, setMetaData, unset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebApplication

public WebApplication()
Constructor. Use init() for any configuration of your application instead of overriding the constructor.

Method Detail

getApplicationKey

public final java.lang.String getApplicationKey()
Description copied from class: Application
Gets the unique key of this application within a given context (like a web application). NOT INTENDED FOR FRAMEWORK CLIENTS.

Specified by:
getApplicationKey in class Application
Returns:
The unique key of this application
See Also:
Application.getApplicationKey()

getInitParameter

public final java.lang.String getInitParameter(java.lang.String key)
Gets an init parameter of the filter, or null if the parameter does not exist.

Parameters:
key - the key to search for
Returns:
the value of the filter init parameter

getRequestCycleProcessor

public final IRequestCycleProcessor getRequestCycleProcessor()
Gets the default request cycle processor (with lazy initialization). This is the IRequestCycleProcessor that will be used by RequestCycles when custom implementations of the request cycle do not provide their own customized versions.

Returns:
the default request cycle processor

getServletContext

public javax.servlet.ServletContext getServletContext()
Gets the servlet context for this application. Use this to get references to absolute paths, global web.xml parameters (<context-param>), etc.

Returns:
The servlet context for this application

getSessionAttributePrefix

public java.lang.String getSessionAttributePrefix(WebRequest request)
Gets the prefix for storing variables in the actual session (typically HttpSession for this application instance.

Parameters:
request - the request
Returns:
the prefix for storing variables in the actual session

getWicketFilter

public final WicketFilter getWicketFilter()
Returns:
The Wicket filter for this application

logEventTarget

public void logEventTarget(IRequestTarget target)
Description copied from class: Application
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL.

Overrides:
logEventTarget in class Application
See Also:
Application.logEventTarget(org.apache.wicket.IRequestTarget)

logResponseTarget

public void logResponseTarget(IRequestTarget target)
Description copied from class: Application
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL.

Overrides:
logResponseTarget in class Application
See Also:
Application.logResponseTarget(org.apache.wicket.IRequestTarget)

mount

public final void mount(IRequestTargetUrlCodingStrategy encoder)
Mounts an encoder at the given path.

Parameters:
encoder - the encoder that will be used for this mount

mount

public final void mount(java.lang.String path,
                        PackageName packageName)
Mounts all bookmarkable pages at the given path.

Parameters:
path - the path to mount the bookmarkable page class on
packageName - the name of the package for which all bookmarkable pages or sharedresources should be mounted

mountBookmarkablePage

public final void mountBookmarkablePage(java.lang.String path,
                                        java.lang.Class bookmarkablePageClass)
Mounts a bookmarkable page class to the given path.

Parameters:
path - the path to mount the bookmarkable page class on
bookmarkablePageClass - the bookmarkable page class to mount

mountBookmarkablePage

public final void mountBookmarkablePage(java.lang.String path,
                                        java.lang.String pageMapName,
                                        java.lang.Class bookmarkablePageClass)
Mounts a bookmarkable page class to the given pagemap and path.

Parameters:
path - the path to mount the bookmarkable page class on
pageMapName - name of the pagemap this mount is for
bookmarkablePageClass - the bookmarkable page class to mount

mountSharedResource

public final void mountSharedResource(java.lang.String path,
                                      java.lang.String resourceKey)
Mounts a shared resource class to the given path.

Parameters:
path - the path to mount the resource class on
resourceKey - the shared key of the resource being mounted

newRequestCycle

public RequestCycle newRequestCycle(Request request,
                                    Response response)
Description copied from class: Application
Creates a new RequestCycle object. Override this method if you want to provide a custom request cycle.

Specified by:
newRequestCycle in class Application
Parameters:
request - The request
response - The response
Returns:
The request cycle
See Also:
Application.newRequestCycle(org.apache.wicket.Request, org.apache.wicket.Response)

newSession

public final Session newSession()
Deprecated. see newSession(Request, Response).

Create new Wicket Session object. Note, this method is not called if you registered your own ISessionFactory with the Application.

Returns:
The created session

newSession

public final Session newSession(Request request)
Deprecated. newSession(Request, Response).

Create new Wicket Session object. Note, this method is not called if you registered your own ISessionFactory with the Application.

Parameters:
request -
Returns:
The created session

newSession

public Session newSession(Request request,
                          Response response)
Description copied from class: Application
Creates a new session. Override this method if you want to provide a custom session.

Specified by:
newSession in class Application
Parameters:
request - The request that will create this session.
response - The response to initialize, for example with cookies. This is important to use cases involving unit testing because those use cases might want to be able to sign a user in automatically when the session is created.
Returns:
The session
See Also:
Application.newSession(org.apache.wicket.Request, org.apache.wicket.Response)

sessionDestroyed

public void sessionDestroyed(java.lang.String sessionId)
Parameters:
sessionId - The session id that was destroyed

setWicketFilter

public final void setWicketFilter(WicketFilter wicketFilter)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT.

Parameters:
wicketFilter - The wicket filter instance for this application

unmount

public final void unmount(java.lang.String path)
Unmounts whatever encoder is mounted at a given path.

Parameters:
path - the path of the encoder to unmount

getDefaultRequestCycleFactory

protected final java.lang.Object getDefaultRequestCycleFactory()
Deprecated. Replaced by newRequestCycle(Request, Response)

Returns:
nada

init

protected void init()
Initialize; if you need the wicket servlet for initialization, e.g. because you want to read an initParameter from web.xml or you want to read a resource from the servlet's context path, you can override this method and provide custom initialization. This method is called right after this application class is constructed, and the wicket servlet is set. Use this method for any application setup instead of the constructor.

Overrides:
init in class Application

internalDestroy

protected void internalDestroy()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT.

Overrides:
internalDestroy in class Application

internalInit

protected void internalInit()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT. Internal initialization. First determine the deployment mode. First check the system property -Dwicket.configuration. If it does not exist check the servlet init parameter ( <init-param><param-name>configuration</param-name>). If not found check the servlet context init parameter <context-param><param-name6gt;configuration</param-name>). If the parameter is "development" (which is default), settings appropriate for development are set. If it's "deployment" , deployment settings are used. If development is specified and a "sourceFolder" init parameter is also set, then resources in that folder will be polled for changes.

Overrides:
internalInit in class Application

getConfigurationType

public java.lang.String getConfigurationType()
Description copied from class: Application
Gets the configuration mode to use for configuring the app, either Application.DEVELOPMENT or Application.DEPLOYMENT.

The configuration type. Must currently be either DEVELOPMENT or DEPLOYMENT. Currently, if the configuration type is DEVELOPMENT, resources are polled for changes, component usage is checked, wicket tags are not stripped from output and a detailed exception page is used. If the type is DEPLOYMENT, component usage is not checked, wicket tags are stripped from output and a non-detailed exception page is used to display errors.

Note that you should not run Wicket in DEVELOPMENT mode on production servers - the various debugging checks and resource polling is inefficient and may leak resources, particularly on webapp redeploy.

Specified by:
getConfigurationType in class Application
Returns:
configuration
See Also:
Application.getConfigurationType()

getResourceFinder

protected IResourceFinder getResourceFinder()

newRequestCycleProcessor

protected IRequestCycleProcessor newRequestCycleProcessor()
Gets a new request cycle processor for web requests. May be replaced by subclasses which wish to use their own implementation of IRequestCycleProcessor. NOTE this can't be moved to application as portlets use two different request cycle processors, and hence have two different methods for them, depending on the kind of request.

Returns:
IRequestCycleProcessor

newSessionStore

protected ISessionStore newSessionStore()
Description copied from class: Application
Creates a new session facade. Is called once per application, and is typically not something clients reimplement.

Specified by:
newSessionStore in class Application
Returns:
The session facade
See Also:
Application.newSessionStore()

newWebRequest

protected WebRequest newWebRequest(javax.servlet.http.HttpServletRequest servletRequest)
Create a new WebRequest. Subclasses of WebRequest could e.g. decode and obfuscated URL which has been encoded by an appropriate WebResponse.

Parameters:
servletRequest -
Returns:
a WebRequest object

newWebResponse

protected WebResponse newWebResponse(javax.servlet.http.HttpServletResponse servletResponse)
Create a WebResponse. Subclasses of WebRequest could e.g. encode wicket's default URL and hide the details from the user. A appropriate WebRequest must be implemented and configured to decode the encoded URL.

Parameters:
servletResponse -
Returns:
a WebResponse object

newAjaxRequestTarget

public AjaxRequestTarget newAjaxRequestTarget(Page page)
Creates a new ajax request target used to control ajax responses

Parameters:
page - page on which ajax response is made
Returns:
non-null ajax request target instance

setApplicationKey

protected final void setApplicationKey(java.lang.String applicationKey)
Set the application key value

Parameters:
applicationKey - Unique application key (typically the filter name).

outputDevelopmentModeWarning

protected void outputDevelopmentModeWarning()
This method prints a warning to stderr that we are starting in development mode.

If you really need to test Wicket in development mode on a staging server somewhere and are annoying the sysadmin for it with stderr messages, you can override this to make it do something else.



Copyright © 2004-2010 Apache Software Foundation. All Rights Reserved.