Class RepositoryStartupServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- org.apache.jackrabbit.servlet.AbstractRepositoryServlet
-
- org.apache.jackrabbit.j2ee.RepositoryStartupServlet
-
- All Implemented Interfaces:
java.io.Serializable
,javax.servlet.Servlet
,javax.servlet.ServletConfig
public class RepositoryStartupServlet extends AbstractRepositoryServlet
The RepositoryStartupServlet starts a jackrabbit repository and registers it to the JNDI environment and optional to the RMI registry.Registration with RMI
Upon successfull creation of the repository in the
init()
method, the repository is registered with an RMI registry if the web application is so configured. To register with RMI, the following web applicationinit-params
are considered:rmi-port
designating the port on which the RMI registry is listening,rmi-host
designating the interface on the local host on which the RMI registry is active,repository-name
designating the name to which the repository is to be bound in the registry, andrmi-uri
designating an RMI URI complete with host, optional port and name to which the object is bound.If the
rmi-uri
parameter is configured with a non-empty value, thermi-port
andrmi-host
parameters are ignored. Therepository-name
parameter is only considered if a non-emptyrmi-uri
parameter is configured if the latter does not contain a name to which to bind the repository.This is the algorithm used to find out the host, port and name for RMI registration:
- If neither a
rmi-uri
nor armi-host
nor armi-port
parameter is configured, the repository is not registered with any RMI registry. - If a non-empty
rmi-uri
parameter is configured extract the host name (or IP address), port number and name to bind to from the URI. If the URI is not valid, host defaults to0.0.0.0
meaning all interfaces on the local host, port defaults to the RMI default port (1099
) and the name defaults to the value of therepository-name
parameter. - If a non-empty
rmi-uri
is not configured, the host is taken from thermi-host
parameter, the port from thermi-port
parameter and the name to bind the repository to from therepository-name
parameter. If thermi-host
parameter is empty or not configured, the host defaults to0.0.0.0
meaning all interfaces on the local host. If thermi-port
parameter is empty, not configured, zero or a negative value, the default port for the RMI registry (1099
) is used.
After finding the host and port of the registry, the RMI registry itself is acquired. It is assumed, that host and port primarily designate an RMI registry, which should be active on the local host but has not been started yet. In this case, the
LocateRegistry.createRegistry
method is called to create a registry on the local host listening on the host and port configured. If creation fails, theLocateRegistry.getRegistry
method is called to get a remote instance of the registry. Note, thatgetRegistry
does not create an actual registry on the given host/port nor does it check, whether an RMI registry is active.When the registry has been retrieved, either by creation or by just creating a remote instance, the repository is bound to the configured name in the registry.
Possible causes for registration failures include:
- The web application is not configured to register with an RMI registry at all.
- The registry is expected to be running on a remote host but does not.
- The registry is expected to be running on the local host but cannot be accessed. Reasons include another application which does not act as an RMI registry is running on the configured port and thus blocks creation of a new RMI registry.
- An object may already be bound to the same name as is configured to be used for the repository.
Note: if a
bootstrap-config
init parameter is specified the servlet tries to read the respective resource, either as context resource or as file. The properties specified in this file override the init params specified in theweb.xml
.Setup Wizard Functionality
When using the first time, the configuraition can miss the relevant repository parameters in the web.xml. if so, it must contain abootstrap-config
parameter that referrs to a propertiy file. This file must exsit for proper working. If not, the repository is not started.
If the servlet is not configured correctly and accessed via http, it will provide a simple wizard for the first time configuration. It propmpts for a new (or existing) repository home and will copy the templates of the repository.xml and bootstrap.properties to the respective location.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
RepositoryStartupServlet.RemoteFactoryDelegater
optional class for RMI, will only be used, if RMI server is presentprotected static class
RepositoryStartupServlet.RMIRemoteFactoryDelegater
optional class for RMI, will only be used, if RMI server is present
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
INIT_PARAM_BOOTSTRAP_CONFIG
initial param name for the bootstrap config location
-
Constructor Summary
Constructors Constructor Description RepositoryStartupServlet()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Repository
createRepository(java.io.File configJson, java.io.File homedir)
Creates the repository instance for the given config and homedir.void
destroy()
destroy the servletprotected void
doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
protected void
doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
BootstrapConfig
getBootstrapConfig()
Returns the config that was used to bootstrap this servlet.static RepositoryStartupServlet
getInstance(javax.servlet.ServletContext context)
Returns an instance of this servlet.protected java.lang.String
getRemoteFactoryDelegaterClass()
Return the fully qualified name of the class providing the remote repository.Repository
getRepository()
Returns the started repository ornull
if not started yet.RepositoryFactory
getRepositoryFactory()
Returns a repository factory that returns the repository if available or throws an exception if not.protected java.rmi.server.RMIServerSocketFactory
getRMIServerSocketFactory(java.net.InetAddress hostAddress)
Returns anRMIServerSocketFactory
used to create the server socket for a locally created RMI registry.void
init()
Initializes the servlet.
Please note that only one repository startup servlet may exist per webapp.void
restart()
Restarts the repository.void
shutdown()
Does a shutdown of the repository and deregisters it from the RMI registry and unbinds if from the JNDI context if so configured.void
startup()
Configures and starts the repository.-
Methods inherited from class org.apache.jackrabbit.servlet.AbstractRepositoryServlet
getAttributeName, getInitParameter
-
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
-
-
-
-
Field Detail
-
INIT_PARAM_BOOTSTRAP_CONFIG
public static final java.lang.String INIT_PARAM_BOOTSTRAP_CONFIG
initial param name for the bootstrap config location- See Also:
- Constant Field Values
-
-
Method Detail
-
init
public void init() throws javax.servlet.ServletException
Initializes the servlet.
Please note that only one repository startup servlet may exist per webapp. it registers itself as context attribute and acts as singleton.- Overrides:
init
in classAbstractRepositoryServlet
- Throws:
javax.servlet.ServletException
- if a same servlet is already registered or of another initialization error occurs.
-
getInstance
public static RepositoryStartupServlet getInstance(javax.servlet.ServletContext context)
Returns an instance of this servlet. Please note, that only 1 repository startup servlet can exist per webapp.- Parameters:
context
- the servlet context- Returns:
- this servlet
-
startup
public void startup() throws javax.servlet.ServletException
Configures and starts the repository. It registers it then to the RMI registry and bind is to the JNDI context if so configured.- Throws:
javax.servlet.ServletException
- if an error occurs.
-
shutdown
public void shutdown()
Does a shutdown of the repository and deregisters it from the RMI registry and unbinds if from the JNDI context if so configured.
-
restart
public void restart() throws javax.servlet.ServletException
Restarts the repository.- Throws:
javax.servlet.ServletException
- if an error occurs.- See Also:
shutdown()
,startup()
-
destroy
public void destroy()
destroy the servlet- Specified by:
destroy
in interfacejavax.servlet.Servlet
- Overrides:
destroy
in classAbstractRepositoryServlet
-
getRepository
public Repository getRepository()
Returns the started repository ornull
if not started yet.- Specified by:
getRepository
in classAbstractRepositoryServlet
- Returns:
- the JCR repository
-
getRepositoryFactory
public RepositoryFactory getRepositoryFactory()
Returns a repository factory that returns the repository if available or throws an exception if not.- Returns:
- repository factory
-
createRepository
protected Repository createRepository(java.io.File configJson, java.io.File homedir) throws RepositoryException
Creates the repository instance for the given config and homedir. Subclasses may override this method of providing own implementations of aRepository
.- Parameters:
configJson
- input source of the repository confighomedir
- the repository home directory- Returns:
- a new jcr repository.
- Throws:
RepositoryException
- if an error during creation occurs.
-
getBootstrapConfig
public BootstrapConfig getBootstrapConfig()
Returns the config that was used to bootstrap this servlet.- Returns:
- the bootstrap config or
null
.
-
getRemoteFactoryDelegaterClass
protected java.lang.String getRemoteFactoryDelegaterClass()
Return the fully qualified name of the class providing the remote repository. The class whose name is returned must implement theRepositoryStartupServlet.RemoteFactoryDelegater
interface.Subclasses may override this method for providing a name of a own implementation.
- Returns:
- getClass().getName() + "$RMIRemoteFactoryDelegater"
-
getRMIServerSocketFactory
protected java.rmi.server.RMIServerSocketFactory getRMIServerSocketFactory(java.net.InetAddress hostAddress)
Returns anRMIServerSocketFactory
used to create the server socket for a locally created RMI registry.This implementation returns a new instance of a simple
RMIServerSocketFactory
which just creates instances of thejava.net.ServerSocket
class bound to the givenhostAddress
. Implementations may overwrite this method to provide factory instances, which provide more elaborate server socket creation, such as SSL server sockets.- Parameters:
hostAddress
- TheInetAddress
instance representing the the interface on the local host to which the server sockets are bound.- Returns:
- A new instance of a simple
RMIServerSocketFactory
creatingjava.net.ServerSocket
instances bound to thermiHost
.
-
doGet
protected void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException
- Overrides:
doGet
in classAbstractRepositoryServlet
- Throws:
javax.servlet.ServletException
java.io.IOException
-
doPost
protected void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException
- Overrides:
doPost
in classjavax.servlet.http.HttpServlet
- Throws:
javax.servlet.ServletException
java.io.IOException
-
-