|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.wicket.Application org.apache.wicket.protocol.http.WebApplication
public abstract class WebApplication
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"); ...
WicketFilter
,
IApplicationSettings
,
IDebugSettings
,
IExceptionSettings
,
IMarkupSettings
,
IPageSettings
,
IRequestCycleSettings
,
IResourceSettings
,
ISecuritySettings
,
Filter
,
FilterConfig
,
ServletContext
Field Summary | |
---|---|
static String |
META_INF_RESOURCES
|
Fields inherited from class org.apache.wicket.Application |
---|
CONFIGURATION |
Constructor Summary | |
---|---|
WebApplication()
Constructor. |
Method Summary | ||
---|---|---|
void |
addResourceReplacement(CssResourceReference base,
ResourceReference replacement)
Registers a replacement resource for the given CSS resource. |
|
void |
addResourceReplacement(JavaScriptResourceReference base,
ResourceReference replacement)
Registers a replacement resource for the given javascript resource. |
|
static WebApplication |
get()
Covariant override for easy getting the current WebApplication without having to cast
it. |
|
AjaxRequestTargetListenerCollection |
getAjaxRequestTargetListeners()
Returns the registered AjaxRequestTarget.IListener objects. |
|
IContextProvider<AjaxRequestTarget,Page> |
getAjaxRequestTargetProvider()
Returns the provider for AjaxRequestTarget objects. |
|
BufferedWebResponse |
getAndRemoveBufferedResponse(String sessionId,
Url url)
|
|
String |
getApplicationKey()
Gets the unique key of this application within a given context (like a web application). |
|
RuntimeConfigurationType |
getConfigurationType()
Gets the configuration mode to use for configuring the app, either RuntimeConfigurationType.DEVELOPMENT or RuntimeConfigurationType.DEPLOYMENT . |
|
FilterFactoryManager |
getFilterFactoryManager()
|
|
String |
getInitParameter(String key)
Gets an init parameter of the filter, or null if the parameter does not exist. |
|
String |
getMimeType(String fileName)
Returns the mime type for given filename. |
|
javax.servlet.ServletContext |
getServletContext()
Gets the servlet context for this application. |
|
String |
getSessionAttributePrefix(WebRequest request,
String filterName)
Gets the prefix for storing variables in the actual session (typically HttpSession
for this application instance. |
|
WicketFilter |
getWicketFilter()
|
|
boolean |
hasBufferedResponse(String sessionId,
Url url)
|
|
boolean |
hasFilterFactoryManager()
|
|
protected void |
init()
Initialize; if you need the wicket servlet/filter for initialization, e.g. |
|
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(IRequestHandler target)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. |
|
void |
logResponseTarget(IRequestHandler target)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. |
|
void |
mount(IRequestMapper mapper)
Mounts an encoder at the given path. |
|
|
mountPackage(String path,
Class<P> pageClass)
Mounts mounts all bookmarkable pages in a the pageClass's package to the given path. |
|
|
mountPage(String path,
Class<T> pageClass)
Mounts a page class to the given path. |
|
void |
mountResource(String path,
ResourceReference reference)
Mounts a shared resource to the given path. |
|
AjaxRequestTarget |
newAjaxRequestTarget(Page page)
Creates a new ajax request target used to control ajax responses |
|
Session |
newSession(Request request,
Response response)
Creates a new session. |
|
WebRequest |
newWebRequest(javax.servlet.http.HttpServletRequest servletRequest,
String filterPath)
Create a new WebRequest. |
|
protected WebResponse |
newWebResponse(WebRequest webRequest,
javax.servlet.http.HttpServletResponse httpServletResponse)
Creates a WebResponse. |
|
protected void |
outputDevelopmentModeWarning()
This method prints a warning to stderr that we are starting in development mode. |
|
void |
renderXmlDecl(WebPage page,
boolean insert)
The rules if and when to insert an xml decl in the response are a bit tricky. |
|
void |
sessionUnbound(String sessionId)
Informs the listener that session with specific id has been unbound. |
|
void |
setAjaxRequestTargetProvider(IContextProvider<AjaxRequestTarget,Page> ajaxRequestTargetProvider)
Sets the provider for AjaxRequestTarget objects. |
|
void |
setConfigurationType(RuntimeConfigurationType configurationType)
set runtime configuration type this is a write-once property: once configured it can not be changed later on. |
|
void |
setServletContext(javax.servlet.ServletContext servletContext)
Sets servlet context this application runs after. |
|
void |
setWicketFilter(WicketFilter wicketFilter)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. |
|
void |
storeBufferedResponse(String sessionId,
Url url,
BufferedWebResponse response)
|
|
void |
unmount(String path)
Unregisters all IRequestMapper s which would match on a this path. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String META_INF_RESOURCES
Constructor Detail |
---|
public WebApplication()
init()
for any configuration of your application instead of
overriding the constructor.
Method Detail |
---|
public static WebApplication get()
WebApplication
without having to cast
it.
public final String getApplicationKey()
Application
getApplicationKey
in class Application
Application.getApplicationKey()
public String getInitParameter(String key)
key
- the key to search for
public void setServletContext(javax.servlet.ServletContext servletContext)
WicketFilter
servletContext
- public javax.servlet.ServletContext getServletContext()
public String getSessionAttributePrefix(WebRequest request, String filterName)
HttpSession
for this application instance.
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.
public final WicketFilter getWicketFilter()
public void logEventTarget(IRequestHandler target)
Application
logEventTarget
in class Application
Application.logEventTarget(org.apache.wicket.request.IRequestHandler)
public void logResponseTarget(IRequestHandler target)
Application
logResponseTarget
in class Application
Application.logResponseTarget(org.apache.wicket.request.IRequestHandler)
public final void mount(IRequestMapper mapper)
mapper
- the encoder that will be used for this mountpublic final <T extends Page> void mountPage(String path, Class<T> pageClass)
T
- type of pagepath
- the path to mount the page class onpageClass
- the page class to be mountedpublic final void mountResource(String path, ResourceReference reference)
path
- the path to mount the resource reference onreference
- resource reference to be mountedpublic final <P extends Page> void mountPackage(String path, Class<P> pageClass)
P
- type of pagepath
- the path to mount the page class onpageClass
- the page class to be mountedpublic final void unmount(String path)
IRequestMapper
s which would match on a this path.
Useful in OSGi environments where a bundle may want to update the mount point.
path
- the path to unmountpublic final void addResourceReplacement(JavaScriptResourceReference base, ResourceReference replacement)
JavaScriptResourceReference
for a packaged resource, but it can also be an
UrlResourceReference
to 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: if base
is added, replacement
will be added
instead.
base
- The resource to replacereplacement
- The replacementpublic final void addResourceReplacement(CssResourceReference base, ResourceReference replacement)
CssResourceReference
for a packaged resource, but it can also be an
UrlResourceReference
to 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: if base
is added, replacement
will be added
instead.
base
- The resource to replacereplacement
- The replacementpublic WebRequest newWebRequest(javax.servlet.http.HttpServletRequest servletRequest, String filterPath)
servletRequest
- the current HTTP Servlet requestfilterPath
- the filter mapping read from web.xml
protected WebResponse newWebResponse(WebRequest webRequest, javax.servlet.http.HttpServletResponse httpServletResponse)
webRequest
- the WebRequest
that will handle the current HTTP Servlet requesthttpServletResponse
- the current HTTP Servlet response
public Session newSession(Request request, Response response)
Application
newSession
in class Application
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.
Application.newSession(org.apache.wicket.request.Request,
org.apache.wicket.request.Response)
public void sessionUnbound(String sessionId)
ISessionStore.UnboundListener
sessionUnbound
in interface ISessionStore.UnboundListener
sessionUnbound
in class Application
Application.sessionUnbound(java.lang.String)
public final void setWicketFilter(WicketFilter wicketFilter)
wicketFilter
- The wicket filter instance for this applicationprotected void init()
init
in class Application
public void internalDestroy()
internalDestroy
in class Application
protected void internalInit()
<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.
internalInit
in class Application
public void setConfigurationType(RuntimeConfigurationType configurationType)
configurationType
- public RuntimeConfigurationType getConfigurationType()
RuntimeConfigurationType.DEVELOPMENT
or RuntimeConfigurationType.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
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.
<init-param>
<param-name>configuration</param-name>
<param-value>deployment</param-value>
</init-param>
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
getConfigurationType
in class Application
public void renderXmlDecl(WebPage page, boolean insert)
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.
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.public final AjaxRequestTarget newAjaxRequestTarget(Page page)
page
- page on which ajax response is made
protected void outputDevelopmentModeWarning()
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.
public boolean hasBufferedResponse(String sessionId, Url url)
sessionId
- url
-
public BufferedWebResponse getAndRemoveBufferedResponse(String sessionId, Url url)
sessionId
- url
-
public void storeBufferedResponse(String sessionId, Url url, BufferedWebResponse response)
sessionId
- url
- response
- public String getMimeType(String fileName)
Application
getMimeType
in class Application
public IContextProvider<AjaxRequestTarget,Page> getAjaxRequestTargetProvider()
AjaxRequestTarget
objects.
AjaxRequestTarget
objects.public void setAjaxRequestTargetProvider(IContextProvider<AjaxRequestTarget,Page> ajaxRequestTargetProvider)
AjaxRequestTarget
objects.
ajaxRequestTargetProvider
- the new providerpublic AjaxRequestTargetListenerCollection getAjaxRequestTargetListeners()
AjaxRequestTarget.IListener
objects.
AjaxRequestTarget.IListener
objects.public final boolean hasFilterFactoryManager()
public final FilterFactoryManager getFilterFactoryManager()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |