Class WebContainerImpl
- java.lang.Object
-
- org.glassfish.web.embed.impl.WebContainerImpl
-
- All Implemented Interfaces:
WebContainer
@Service @ContractsProvided({WebContainerImpl.class,WebContainer.class}) public class WebContainerImpl extends Object implements WebContainer
Class representing an embedded web container, which supports the programmatic creation of different types of web protocol listeners and virtual servers, and the registration of static and dynamic web resources into the URI namespace.- Author:
- Amy Roh
-
-
Constructor Summary
Constructors Constructor Description WebContainerImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addContext(Context context, String contextRoot)
Registers the given Context with all VirtualServer at the given context root.void
addVirtualServer(VirtualServer virtualServer)
Adds the given VirtualServer to this WebContainer.void
addWebListener(WebListener webListener)
Adds the given WebListener to this WebContainer.Context
createContext(File docRoot)
Creates a Context and configures it with the given docroot and classloader.Context
createContext(File docRoot, ClassLoader classLoader)
Creates a Context and configures it with the given docroot and classloader.Context
createContext(File docRoot, String contextRoot, ClassLoader classLoader)
Creates a Context, configures it with the given docroot and classloader, and registers it with all VirtualServer.VirtualServer
createVirtualServer(String id, File docRoot)
Creates a VirtualServer with the given id and docroot, and maps it to all WebListener instances.VirtualServer
createVirtualServer(String id, File docRoot, WebListener... webListeners)
Creates a VirtualServer with the given id and docroot, and maps it to the given WebListener instances.<T extends WebListener>
TcreateWebListener(String id, Class<T> c)
Creates a WebListener from the given class type and assigns the given id to it.List<Sniffer>
getSniffers()
Returns the list of sniffers associated with this embedded containerVirtualServer
getVirtualServer(String id)
Finds the VirtualServer with the given id.Collection<VirtualServer>
getVirtualServers()
Gets the collection of VirtualServer instances registered with this WebContainer.WebListener
getWebListener(String id)
Finds the WebListener with the given id.Collection<WebListener>
getWebListeners()
Gets the collection of WebListener instances registered with this WebContainer.void
removeContext(Context context)
Stops the given Context and removes it from all VirtualServer.void
removeVirtualServer(VirtualServer virtualServer)
Stops the given virtualServer and removes it from this WebContainer.void
removeWebListener(WebListener webListener)
Stops the given webListener and removes it from this WebContainer.void
setConfiguration(WebContainerConfig config)
Sets the embedded configuration for this embedded instance.void
setLogLevel(Level level)
Sets log level
-
-
-
Method Detail
-
setConfiguration
public void setConfiguration(WebContainerConfig config)
Description copied from interface:WebContainer
Sets the embedded configuration for this embedded instance. Such configuration will always override any xml based configuration.- Specified by:
setConfiguration
in interfaceWebContainer
- Parameters:
config
- the embedded instance configuration
-
getSniffers
public List<Sniffer> getSniffers()
Returns the list of sniffers associated with this embedded container- Returns:
- list of sniffers
-
createContext
public Context createContext(File docRoot)
Creates a Context and configures it with the given docroot and classloader.The classloader of the class on which this method is called will be used.
In order to access the new Context or any of its resources, the Context must be registered with a VirtualServer that has been started.
- Specified by:
createContext
in interfaceWebContainer
- Parameters:
docRoot
- the docroot of the Context- Returns:
- the new Context
- See Also:
VirtualServer.addContext(org.glassfish.embeddable.web.Context, java.lang.String)
-
createContext
public Context createContext(File docRoot, ClassLoader classLoader)
Creates a Context and configures it with the given docroot and classloader.The given classloader will be set as the thread's context classloader whenever the new Context or any of its resources are asked to process a request. If a null classloader is passed, the classloader of the class on which this method is called will be used.
In order to access the new Context or any of its resources, the Context must be registered with a VirtualServer that has been started.
- Specified by:
createContext
in interfaceWebContainer
- Parameters:
docRoot
- the docroot of the ContextclassLoader
- the classloader of the Context- Returns:
- the new Context
- See Also:
VirtualServer.addContext(org.glassfish.embeddable.web.Context, java.lang.String)
-
createContext
public Context createContext(File docRoot, String contextRoot, ClassLoader classLoader)
Creates a Context, configures it with the given docroot and classloader, and registers it with all VirtualServer.The given classloader will be set as the thread's context classloader whenever the new Context or any of its resources are asked to process a request. If a null classloader is passed, the classloader of the class on which this method is called will be used.
- Specified by:
createContext
in interfaceWebContainer
- Parameters:
docRoot
- the docroot of the ContextcontextRoot
- the contextroot at which to registerclassLoader
- the classloader of the Context- Returns:
- the new Context
-
addContext
public void addContext(Context context, String contextRoot) throws ConfigException, GlassFishException
Registers the given Context with all VirtualServer at the given context root.If VirtualServer has already been started, the given context will be started as well.
- Specified by:
addContext
in interfaceWebContainer
- Parameters:
context
- the Context to registercontextRoot
- the context root at which to register- Throws:
ConfigException
- if a Context already exists at the given context root on VirtualServerGlassFishException
- if the given context fails to be started
-
removeContext
public void removeContext(Context context) throws ConfigException, GlassFishException
Stops the given Context and removes it from all VirtualServer.- Specified by:
removeContext
in interfaceWebContainer
- Parameters:
context
- the Context to be stopped and removed- Throws:
GlassFishException
- if an error occurs during the stopping or removal of the given contextConfigException
-
createWebListener
public <T extends WebListener> T createWebListener(String id, Class<T> c) throws InstantiationException, IllegalAccessException
Creates a WebListener from the given class type and assigns the given id to it.- Specified by:
createWebListener
in interfaceWebContainer
- Parameters:
id
- the id of the new WebListenerc
- the class from which to instantiate the WebListener- Returns:
- the new WebListener instance
- Throws:
IllegalAccessException
- if the given Class or its nullary constructor is not accessible.InstantiationException
- if the given Class represents an abstract class, an interface, an array class, a primitive type, or void; or if the class has no nullary constructor; or if the instantiation fails for some other reason.ExceptionInInitializerError
- if the initialization failsSecurityException
- if a security manager, s, is present and any of the following conditions is met:- invocation of
s.checkMemberAccess(this, Member.PUBLIC)
denies creation of new instances of the given Class - the caller's class loader is not the same as or an
ancestor of the class loader for the current class and
invocation of
s.checkPackageAccess()
denies access to the package of this class
- invocation of
-
addWebListener
public void addWebListener(WebListener webListener) throws ConfigException, GlassFishException
Adds the given WebListener to this WebContainer.If this WebContainer has already been started, the given webListener will be started as well.
- Specified by:
addWebListener
in interfaceWebContainer
- Parameters:
webListener
- the WebListener to add- Throws:
ConfigException
- if a WebListener with the same id has already been registered with this WebContainerGlassFishException
- if the given webListener fails to be started
-
getWebListener
public WebListener getWebListener(String id)
Finds the WebListener with the given id.- Specified by:
getWebListener
in interfaceWebContainer
- Parameters:
id
- the id of the WebListener to find- Returns:
- the WebListener with the given id, or null if no WebListener with that id has been registered with this WebContainer
-
getWebListeners
public Collection<WebListener> getWebListeners()
Gets the collection of WebListener instances registered with this WebContainer.- Specified by:
getWebListeners
in interfaceWebContainer
- Returns:
- the (possibly empty) collection of WebListener instances registered with this WebContainer
-
removeWebListener
public void removeWebListener(WebListener webListener) throws GlassFishException
Stops the given webListener and removes it from this WebContainer.- Specified by:
removeWebListener
in interfaceWebContainer
- Parameters:
webListener
- the WebListener to be stopped and removed- Throws:
GlassFishException
- if an error occurs during the stopping or removal of the given webListener
-
createVirtualServer
public VirtualServer createVirtualServer(String id, File docRoot, WebListener... webListeners)
Creates a VirtualServer with the given id and docroot, and maps it to the given WebListener instances.- Specified by:
createVirtualServer
in interfaceWebContainer
- Parameters:
id
- the id of the VirtualServerdocRoot
- the docroot of the VirtualServerwebListeners
- the list of WebListener instances from which the VirtualServer will receive requests- Returns:
- the new VirtualServer instance
-
createVirtualServer
public VirtualServer createVirtualServer(String id, File docRoot)
Creates a VirtualServer with the given id and docroot, and maps it to all WebListener instances.- Specified by:
createVirtualServer
in interfaceWebContainer
- Parameters:
id
- the id of the VirtualServerdocRoot
- the docroot of the VirtualServer- Returns:
- the new VirtualServer instance
-
addVirtualServer
public void addVirtualServer(VirtualServer virtualServer) throws ConfigException, GlassFishException
Adds the given VirtualServer to this WebContainer.If this WebContainer has already been started, the given virtualServer will be started as well.
- Specified by:
addVirtualServer
in interfaceWebContainer
- Parameters:
virtualServer
- the VirtualServer to add- Throws:
ConfigException
- if a VirtualServer with the same id has already been registered with this WebContainerGlassFishException
- if the given virtualServer fails to be started
-
getVirtualServer
public VirtualServer getVirtualServer(String id)
Finds the VirtualServer with the given id.- Specified by:
getVirtualServer
in interfaceWebContainer
- Parameters:
id
- the id of the VirtualServer to find- Returns:
- the VirtualServer with the given id, or null if no VirtualServer with that id has been registered with this WebContainer
-
getVirtualServers
public Collection<VirtualServer> getVirtualServers()
Gets the collection of VirtualServer instances registered with this WebContainer.- Specified by:
getVirtualServers
in interfaceWebContainer
- Returns:
- the (possibly empty) collection of VirtualServer instances registered with this WebContainer
-
removeVirtualServer
public void removeVirtualServer(VirtualServer virtualServer) throws GlassFishException
Stops the given virtualServer and removes it from this WebContainer.- Specified by:
removeVirtualServer
in interfaceWebContainer
- Parameters:
virtualServer
- the VirtualServer to be stopped and removed- Throws:
GlassFishException
- if an error occurs during the stopping or removal of the given virtualServer
-
setLogLevel
public void setLogLevel(Level level)
Sets log level- Specified by:
setLogLevel
in interfaceWebContainer
- Parameters:
level
-
-
-