Class 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 Detail

      • WebContainerImpl

        public WebContainerImpl()
    • 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 interface WebContainer
        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,
                                     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 interface WebContainer
        Parameters:
        docRoot - the docroot of the Context
        classLoader - 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 interface WebContainer
        Parameters:
        docRoot - the docroot of the Context
        contextRoot - the contextroot at which to register
        classLoader - 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 interface WebContainer
        Parameters:
        context - the Context to register
        contextRoot - the context root at which to register
        Throws:
        ConfigException - if a Context already exists at the given context root on VirtualServer
        GlassFishException - if the given context fails to be started
      • 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 interface WebContainer
        Parameters:
        id - the id of the new WebListener
        c - 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 fails
        SecurityException - 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
      • 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 interface WebContainer
        Parameters:
        webListener - the WebListener to add
        Throws:
        ConfigException - if a WebListener with the same id has already been registered with this WebContainer
        GlassFishException - 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 interface WebContainer
        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 interface WebContainer
        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 interface WebContainer
        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 interface WebContainer
        Parameters:
        id - the id of the VirtualServer
        docRoot - the docroot of the VirtualServer
        webListeners - 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 interface WebContainer
        Parameters:
        id - the id of the VirtualServer
        docRoot - 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 interface WebContainer
        Parameters:
        virtualServer - the VirtualServer to add
        Throws:
        ConfigException - if a VirtualServer with the same id has already been registered with this WebContainer
        GlassFishException - 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 interface WebContainer
        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 interface WebContainer
        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 interface WebContainer
        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 interface WebContainer
        Parameters:
        level -