|
Arch4J 1.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.servlet.GenericServlet | +--javax.servlet.http.HttpServlet | +--org.arch4j.property.StartupServlet
This class is used to initialize property management for applications that run inside a web container.
Since it is non-trivial to add Java VM -D arguments to the web container startup,
this servlet class can be used at servlet initialization time to configure the system properties
needed to bootstrap the PropertyProvider
, specifically for XML property management,
which is the new-style way of handling application configuration via Arch4J.
Using this servlet requires that a valid servlet section in the web.xml deployment file
be set up to initialize this servlet. Along with the servlet name, two servlet initialization
parameters must be made available to the servlet. These two parameters directly correspond to
the two system properties that are used by the PropertyProvider
when it is initialized.
The first parameter is named arch4j.constants.class
.
Its value is a class name, which is a subclass of StartupConstants
.
This class is used to get the other startup properties.
The second parameter comes by way of the method StartupConstants.getApplicationHomeProperty()
.
This string is the parameter name to use to find the application's home directory.
The name chosen is up to the application developer, and it is the developer's responsibility to make
sure that the name matches in both the web.xml deployment file and the constants subclass.
For example, let us suppose that a web application named counter is being deployed.
The application will contain a subclass of StartupConstants
named
com.mycompany.counter.CounterStartupConstants
.
In addition to the web container archive,
there is an external location for properties to be modified and data files to be stored.
This application home directory will be located in C:/var/appData/counter
.
The developer arbitrarily chooses the application home property name to be counter.app.home
,
which is what the overridden method StartupConstants.getApplicationHomeProperty()
will return.
To ensure that this happens when the web container starts the application, we will load this servlet on startup as the first loaded servlet. Here is the servlet section that will initialize the application correctly.
<servlet> <servlet-name>PropertyStartupServlet</servlet-name> <servlet-class>org.arch4j.property.StartupServlet</servlet-class> <init-param> <param-name>arch4j.constants.class</param-name> <param-value>com.mycompany.counter.CounterStartupConstants</param-value> </init-param> <init-param> <param-name>counter.app.home</param-name> <param-value>C:/var/appData/counter</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet>
If you really, really do not want to use an application home directory,
do not include the application home init parameter in your servlet specification
(counter.app.home
in the example above).
Also, force the default application home method StartupConstants.getDefaultApplicationHome()
in your StartupConstants
subclass to return a null
.
Just make sure to store the XML property file somewhere in your classpath.
It will be found and parsed.
Constructor Summary | |
StartupServlet()
|
Method Summary | |
void |
init()
This method handles the servlet initialization. |
Methods inherited from class javax.servlet.http.HttpServlet |
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, 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 |
public StartupServlet()
Method Detail |
public void init() throws javax.servlet.ServletException
PropertyProvider
from a web containter.
init
in class javax.servlet.GenericServlet
javax.servlet.ServletException
- if an exception occurs that interrupts the servlet's normal operation
|
Arch4J 1.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |