Class WebApplication
- java.lang.Object
-
- org.apache.wicket.Application
-
- org.apache.wicket.protocol.http.WebApplication
-
- All Implemented Interfaces:
IEventSink,IMetadataContext<java.lang.Object,Application>,ISessionStore.UnboundListener
- Direct Known Subclasses:
MockApplication
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
FilterConfigobject, 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,ApplicationSettings,DebugSettings,ExceptionSettings,MarkupSettings,PageSettings,RequestCycleSettings,ResourceSettings,SecuritySettings,Filter,FilterConfig,ServletContext
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringMETA_INF_RESOURCES-
Fields inherited from class org.apache.wicket.Application
CONFIGURATION
-
-
Constructor Summary
Constructors Constructor Description WebApplication()Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddResourceReplacement(CssResourceReference base, ResourceReference replacement)Registers a replacement resource for the given CSS resource.voidaddResourceReplacement(JavaScriptResourceReference base, ResourceReference replacement)Registers a replacement resource for the given javascript resource.static WebApplicationget()Covariant override for easy getting the currentWebApplicationwithout having to cast it.AjaxRequestTargetListenerCollectiongetAjaxRequestTargetListeners()Returns the registeredAjaxRequestTarget.IListenerobjects.java.util.function.Function<Page,AjaxRequestTarget>getAjaxRequestTargetProvider()Returns the provider forAjaxRequestTargetobjects.BufferedWebResponsegetAndRemoveBufferedResponse(java.lang.String sessionId, org.apache.wicket.request.Url url)Retrieves a stored buffered response for a given sessionId and url.java.lang.StringgetApplicationKey()Gets the unique key of this application within a given context (like a web application).RuntimeConfigurationTypegetConfigurationType()Gets the configuration mode to use for configuring the app, eitherRuntimeConfigurationType.DEVELOPMENTorRuntimeConfigurationType.DEPLOYMENT.FilterFactoryManagergetFilterFactoryManager()java.lang.StringgetInitParameter(java.lang.String key)Gets an init parameter of the filter, or null if the parameter does not exist.java.lang.StringgetMimeType(java.lang.String fileName)Returns the mime type for given filename.javax.servlet.ServletContextgetServletContext()Gets the servlet context for this application.java.lang.StringgetSessionAttributePrefix(org.apache.wicket.request.http.WebRequest request, java.lang.String filterName)Gets the prefix for storing variables in the actual session (typicallyHttpSessionfor this application instance.booleangetUpdateAutoLabelsOnAjaxRequests()If true, auto label css classes such aserrorandrequiredwill be updated after form component processing during an ajax request.WicketFiltergetWicketFilter()booleanhasBufferedResponse(java.lang.String sessionId, org.apache.wicket.request.Url url)booleanhasFilterFactoryManager()protected voidinit()Initialize; if you need the wicket servlet/filter for initialization, e.g.voidinternalDestroy()THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.protected voidinternalInit()THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.voidlogEventTarget(org.apache.wicket.request.IRequestHandler target)THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.voidlogResponseTarget(org.apache.wicket.request.IRequestHandler target)THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.voidmount(org.apache.wicket.request.IRequestMapper mapper)Mounts an encoder at the given path.<P extends Page>
PackageMappermountPackage(java.lang.String path, java.lang.Class<P> pageClass)Mounts mounts all bookmarkable pages in a the pageClass's package to the given path.<T extends Page>
MountedMappermountPage(java.lang.String path, java.lang.Class<T> pageClass)Mounts a page class to the given path.ResourceMappermountResource(java.lang.String path, ResourceReference reference)Mounts a shared resource to the given path.AjaxRequestTargetnewAjaxRequestTarget(Page page)Creates a new ajax request target used to control ajax responsesSessionnewSession(org.apache.wicket.request.Request request, org.apache.wicket.request.Response response)Creates a new session.org.apache.wicket.request.http.WebRequestnewWebRequest(javax.servlet.http.HttpServletRequest servletRequest, java.lang.String filterPath)Create a new WebRequest.protected org.apache.wicket.request.http.WebResponsenewWebResponse(org.apache.wicket.request.http.WebRequest webRequest, javax.servlet.http.HttpServletResponse httpServletResponse)Creates a WebResponse.protected voidoutputDevelopmentModeWarning()This method prints a warning to stderr that we are starting in development mode.voidrenderXmlDecl(WebPage page, boolean insert)The rules if and when to insert an xml decl in the response are a bit tricky.voidsessionUnbound(java.lang.String sessionId)Informs the listener that session with specific id has been unbound.ApplicationsetAjaxRequestTargetProvider(java.util.function.Function<Page,AjaxRequestTarget> ajaxRequestTargetProvider)Sets the provider forAjaxRequestTargetobjects.ApplicationsetConfigurationType(RuntimeConfigurationType configurationType)set runtime configuration typevoidsetServletContext(javax.servlet.ServletContext servletContext)Sets servlet context this application runs after.voidsetWicketFilter(WicketFilter wicketFilter)THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.voidstoreBufferedResponse(java.lang.String sessionId, org.apache.wicket.request.Url url, BufferedWebResponse response)Store the buffered response at application level to use it at a later time.voidunmount(java.lang.String path)Unregisters allIRequestMappers which would match on a this path.-
Methods inherited from class org.apache.wicket.Application
configure, createRequestCycle, decorateHeaderResponse, exists, fetchCreateAndSetSession, get, getApplicationKeys, getApplicationListeners, getApplicationSettings, getBehaviorInstantiationListeners, getComponentInitializationListeners, getComponentInstantiationListeners, getComponentOnAfterRenderListeners, getComponentOnConfigureListeners, getComponentPostOnBeforeRenderListeners, getComponentPreOnBeforeRenderListeners, getConverterLocator, getDebugSettings, getExceptionMapperProvider, getExceptionSettings, getFrameworkSettings, getHeaderContributorListeners, getHomePage, getInitializers, getJavaScriptLibrarySettings, getMapperContext, getMarkupSettings, getMetaData, getName, getOnComponentTagListeners, getPageFactory, getPageManagerProvider, getPageRendererProvider, getPageSettings, getRequestCycleListeners, getRequestCycleProvider, getRequestCycleSettings, getRequestLogger, getRequestLoggerSettings, getResourceBundles, getResourceReferenceRegistry, getResourceSettings, getRootRequestMapper, getRootRequestMapperAsCompound, getSecuritySettings, getSessionListeners, getSessionStore, getSessionStoreProvider, getSharedResources, getStoreSettings, initApplication, newConverterLocator, newMapperContext, newPageFactory, newRequestLogger, newResourceBundles, newResourceReferenceRegistry, newSharedResources, onDestroy, onEvent, setApplicationSettings, setDebugSettings, setExceptionSettings, setFrameworkSettings, setHeaderResponseDecorator, setJavaScriptLibrarySettings, setMarkupSettings, setMetaData, setName, setPageManagerProvider, setPageRendererProvider, setPageSettings, setRequestCycleProvider, setRequestCycleSettings, setRequestLoggerSettings, setResourceSettings, setRootRequestMapper, setSecuritySettings, setSessionStoreProvider, setStoreSettings, usesDeploymentConfig, usesDevelopmentConfig, validateInit
-
-
-
-
Field Detail
-
META_INF_RESOURCES
public static final java.lang.String META_INF_RESOURCES
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
WebApplication
public WebApplication()
Constructor. Useinit()for any configuration of your application instead of overriding the constructor.
-
-
Method Detail
-
get
public static WebApplication get()
Covariant override for easy getting the currentWebApplicationwithout having to cast it.
-
getApplicationKey
public final java.lang.String getApplicationKey()
Description copied from class:ApplicationGets the unique key of this application within a given context (like a web application). NOT INTENDED FOR FRAMEWORK CLIENTS.- Specified by:
getApplicationKeyin classApplication- Returns:
- The unique key of this application
- See Also:
Application.getApplicationKey()
-
getInitParameter
public 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
-
setServletContext
public void setServletContext(javax.servlet.ServletContext servletContext)
Sets servlet context this application runs after. This is uaully done from a filter or a servlet responsible for managing this application object, such asWicketFilter- Parameters:
servletContext-
-
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(org.apache.wicket.request.http.WebRequest request, java.lang.String filterName)Gets the prefix for storing variables in the actual session (typicallyHttpSessionfor this application instance.- Parameters:
request- the requestfilterName- If null, than it defaults to the WicketFilter filter name. However according to the ServletSpec the Filter is not guaranteed to be initialized e.g. when WicketSessionFilter gets initialized. Thus, though you (and WicketSessionFilter) can provide a filter name, you must make sure it is the same as WicketFilter will provide once initialized.- 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(org.apache.wicket.request.IRequestHandler target)
Description copied from class:ApplicationTHIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL.- Overrides:
logEventTargetin classApplication- See Also:
Application.logEventTarget(org.apache.wicket.request.IRequestHandler)
-
logResponseTarget
public void logResponseTarget(org.apache.wicket.request.IRequestHandler target)
Description copied from class:ApplicationTHIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL.- Overrides:
logResponseTargetin classApplication- See Also:
Application.logResponseTarget(org.apache.wicket.request.IRequestHandler)
-
mount
public void mount(org.apache.wicket.request.IRequestMapper mapper)
Mounts an encoder at the given path.- Parameters:
mapper- the encoder that will be used for this mount
-
mountPage
public <T extends Page> MountedMapper mountPage(java.lang.String path, java.lang.Class<T> pageClass)
Mounts a page class to the given path.NOTE: mount path must not start with reserved URL segments! See
IMapperContextto know which segments are reserved for internal use.- Type Parameters:
T- type of page- Parameters:
path- the path to mount the page class onpageClass- the page class to be mounted
-
mountResource
public ResourceMapper mountResource(java.lang.String path, ResourceReference reference)
Mounts a shared resource to the given path.NOTE: mount path must not start with reserved URL segments! See
IMapperContextto know which segments are reserved for internal use.- Parameters:
path- the path to mount the resource reference onreference- resource reference to be mounted
-
mountPackage
public <P extends Page> PackageMapper mountPackage(java.lang.String path, java.lang.Class<P> pageClass)
Mounts mounts all bookmarkable pages in a the pageClass's package to the given path.NOTE: mount path must not start with reserved URL segments! See
IMapperContextto know which segments are reserved for internal use.- Type Parameters:
P- type of page- Parameters:
path- the path to mount the page class onpageClass- the page class to be mounted
-
unmount
public void unmount(java.lang.String path)
Unregisters allIRequestMappers which would match on a this path.Useful in OSGi environments where a bundle may want to update the mount point.
- Parameters:
path- the path to unmount
-
addResourceReplacement
public final void addResourceReplacement(JavaScriptResourceReference base, ResourceReference replacement)
Registers a replacement resource for the given javascript resource. This replacement can be anotherJavaScriptResourceReferencefor a packaged resource, but it can also be anUrlResourceReferenceto replace the resource by a resource hosted on a CDN. Registering a replacement will cause the resource to replaced by the given resource throughout the application: ifbaseis added,replacementwill be added instead.- Parameters:
base- The resource to replacereplacement- The replacement
-
addResourceReplacement
public final void addResourceReplacement(CssResourceReference base, ResourceReference replacement)
Registers a replacement resource for the given CSS resource. This replacement can be anotherCssResourceReferencefor a packaged resource, but it can also be anUrlResourceReferenceto replace the resource by a resource hosted on a CDN. Registering a replacement will cause the resource to replaced by the given resource throughout the application: ifbaseis added,replacementwill be added instead.- Parameters:
base- The resource to replacereplacement- The replacement
-
newWebRequest
public org.apache.wicket.request.http.WebRequest newWebRequest(javax.servlet.http.HttpServletRequest servletRequest, java.lang.String filterPath)Create a new WebRequest. Subclasses of WebRequest could e.g. decode and obfuscate URL which has been encoded by an appropriate WebResponse.- Parameters:
servletRequest- the current HTTP Servlet requestfilterPath- the filter mapping read from web.xml- Returns:
- a WebRequest object
-
newWebResponse
protected org.apache.wicket.request.http.WebResponse newWebResponse(org.apache.wicket.request.http.WebRequest webRequest, javax.servlet.http.HttpServletResponse httpServletResponse)Creates 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:
webRequest- theWebRequestthat will handle the current HTTP Servlet requesthttpServletResponse- the current HTTP Servlet response- Returns:
- a WebResponse object
-
newSession
public Session newSession(org.apache.wicket.request.Request request, org.apache.wicket.request.Response response)
Description copied from class:ApplicationCreates a new session. Override this method if you want to provide a custom session.- Specified by:
newSessionin classApplication- 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.Request, org.apache.wicket.request.Response)
-
sessionUnbound
public void sessionUnbound(java.lang.String sessionId)
Description copied from interface:ISessionStore.UnboundListenerInforms the listener that session with specific id has been unbound.- Specified by:
sessionUnboundin interfaceISessionStore.UnboundListener- Overrides:
sessionUnboundin classApplication- See Also:
Application.sessionUnbound(java.lang.String)
-
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
-
init
protected void init()
Initialize; if you need the wicket servlet/filter 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/filter is set. Use this method for any application setup instead of the constructor.- Overrides:
initin classApplication
-
internalDestroy
public void internalDestroy()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT.- Overrides:
internalDestroyin classApplication
-
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:
internalInitin classApplication
-
setConfigurationType
public Application setConfigurationType(RuntimeConfigurationType configurationType)
set runtime configuration type this is a write-once property: once configured it can not be changed later on.- Parameters:
configurationType-
-
getConfigurationType
public RuntimeConfigurationType getConfigurationType()
Gets the configuration mode to use for configuring the app, eitherRuntimeConfigurationType.DEVELOPMENTorRuntimeConfigurationType.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.
To change the deployment mode, add the following to your web.xml, inside your
mapping (or mapping if you're using 1.3.x): <init-param> <param-name>configuration</param-name> <param-value>deployment</param-value> </init-param>You can alternatively set this as a <context-param> on the whole context.
Another option is to set the "wicket.configuration" system property to either "deployment" or "development". The value is not case-sensitive.
The system property is checked first, allowing you to add a web.xml param for deployment, and a command-line override when you want to run in development mode during development.
You may also override Application.getConfigurationType() to provide your own custom switch, in which case none of the above logic is used.
IMPORTANT NOTE
THIS METHOD IS CALLED OFTEN FROM MANY DIFFERENT POINTS IN CODE, INCLUDING DURING THE RENDER PROCESS, THEREFORE THE IMPLEMENTATION SHOULD BE FAST - PREFERRABLY USING A FAST-TO-RETRIEVE CACHED VALUE- Specified by:
getConfigurationTypein classApplication- Returns:
- configuration
-
renderXmlDecl
public void renderXmlDecl(WebPage page, boolean insert)
The rules if and when to insert an xml decl in the response are a bit tricky. Hence, we allow the user to replace the default implementation per page and per application.Default implementation: the page mime type must be "application/xhtml+xml" and request HTTP_ACCEPT header must include "application/xhtml+xml" to automatically include the xml decl. Please see Writing JavaScript for XHTML for details.
Please note that xml decls in Wicket's markup are only used for reading the markup. The markup's xml decl will always be removed and never be used to configure the response.
- Parameters:
page- The page currently being renderedinsert- If false, than the rules are applied. If true, it'll always be written. In order to never insert it, than subclass renderXmlDecl() with an empty implementation.
-
newAjaxRequestTarget
public final 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
-
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.
-
hasBufferedResponse
public boolean hasBufferedResponse(java.lang.String sessionId, org.apache.wicket.request.Url url)- Parameters:
sessionId-url-- Returns:
- true if has buffered response
-
getAndRemoveBufferedResponse
public BufferedWebResponse getAndRemoveBufferedResponse(java.lang.String sessionId, org.apache.wicket.request.Url url)
Retrieves a stored buffered response for a given sessionId and url.- Parameters:
url- The url used as a key- Returns:
- the stored buffered response.
nullif there is no stored response for the given url - See Also:
RequestCycleSettings.RenderStrategy.REDIRECT_TO_BUFFER
-
storeBufferedResponse
public void storeBufferedResponse(java.lang.String sessionId, org.apache.wicket.request.Url url, BufferedWebResponse response)Store the buffered response at application level to use it at a later time.- Parameters:
sessionId-url-response-
-
getMimeType
public java.lang.String getMimeType(java.lang.String fileName)
Description copied from class:ApplicationReturns the mime type for given filename.- Overrides:
getMimeTypein classApplication- Returns:
- mime type
-
getAjaxRequestTargetProvider
public java.util.function.Function<Page,AjaxRequestTarget> getAjaxRequestTargetProvider()
Returns the provider forAjaxRequestTargetobjects.- Returns:
- the provider for
AjaxRequestTargetobjects.
-
setAjaxRequestTargetProvider
public Application setAjaxRequestTargetProvider(java.util.function.Function<Page,AjaxRequestTarget> ajaxRequestTargetProvider)
Sets the provider forAjaxRequestTargetobjects.- Parameters:
ajaxRequestTargetProvider- the new provider
-
getAjaxRequestTargetListeners
public AjaxRequestTargetListenerCollection getAjaxRequestTargetListeners()
Returns the registeredAjaxRequestTarget.IListenerobjects.- Returns:
- the registered
AjaxRequestTarget.IListenerobjects.
-
hasFilterFactoryManager
public final boolean hasFilterFactoryManager()
- Returns:
- True if at least one filter factory has been added.
-
getFilterFactoryManager
public final FilterFactoryManager getFilterFactoryManager()
- Returns:
- The filter factory manager
-
getUpdateAutoLabelsOnAjaxRequests
public boolean getUpdateAutoLabelsOnAjaxRequests()
If true, auto label css classes such aserrorandrequiredwill be updated after form component processing during an ajax request. This allows auto labels to correctly reflect the state of the form component even if they are not part of the ajax markup update. TODO in wicket-7 this should move into a settings object. cannot move in 6.x because it requires a change to a setting interface.- Returns:
trueiff enabled
-
-