FileDocCategorySizeDatePackage
EmbeddedWebContainer.javaAPI DocGlassfish v2 API16562Wed Jun 13 19:54:36 BST 2007com.sun.enterprise.web

EmbeddedWebContainer

public final class EmbeddedWebContainer extends org.apache.catalina.startup.Embedded
Represents an embedded Catalina web container within the Application Server. This class is intended for use in versions of the application server that *do not* have web-core as well as in versions that do. When used with a web container that is integrated via the NSAPI j2ee-plugin, the virtual server implementation that createHost returns is customized to "com.sun.enterprise.web.NSAPIVirtualServer".

Fields Summary
private Logger
_logger
The logger to use for logging ALL web container related messages.
private com.sun.enterprise.server.pluggable.WebContainerFeatureFactory
webContainerFeatureFactory
private WebContainer
webContainer
private String
logServiceFile
Constructors Summary
public EmbeddedWebContainer(Logger webLogger, com.sun.enterprise.server.ServerContext serverContext, WebContainer webContainer, String logServiceFile)


 
    // ------------------------------------------------------------ Constructor

      
                                 
                                 
                                  
        super();
        _logger = webLogger;
        this.webContainer = webContainer;
        this.logServiceFile = logServiceFile;
        webContainerFeatureFactory =
            serverContext.getPluggableFeatureFactory().getWebContainerFeatureFactory();        
    
Methods Summary
public org.apache.catalina.ConnectorcreateConnector(java.lang.String address, int port, java.lang.String protocol)
Create a customized version of the Tomcat's 5 Coyote Connector. This connector is required in order to support PE Web Programmatic login functionality.

param
address InetAddress to bind to, or null if the connector is supposed to bind to all addresses on this server
param
port Port number to listen to
param
protocol the http protocol to use.


        if (address != null) {
            /*
             * InetAddress.toString() returns a string of the form
             * "<hostname>/<literal_IP>". Get the latter part, so that the
             * address can be parsed (back) into an InetAddress using
             * InetAddress.getByName().
             */
            int index = address.indexOf('/");
            if (index != -1) {
                address = address.substring(index + 1);
            }
        }

        _logger.log(Level.FINE,"Creating connector for address='" +
                  ((address == null) ? "ALL" : address) +
                  "' port='" + port + "' protocol='" + protocol + "'");

        PECoyoteConnector connector = new PECoyoteConnector();

        if (address != null) {
            connector.setAddress(address);
        }

        connector.setPort(port);

        if (protocol.equals("ajp")) {
            connector.setProtocolHandlerClassName(
                 "org.apache.jk.server.JkCoyoteHandler");
        } else if (protocol.equals("memory")) {
            connector.setProtocolHandlerClassName(
                 "org.apache.coyote.memory.MemoryProtocolHandler");
        } else if (protocol.equals("https")) {
            connector.setScheme("https");
            connector.setSecure(true);
        }

        return (connector);

    
public org.apache.catalina.ContextcreateContext(java.lang.String ctxPath, java.lang.String location, java.lang.String defaultContextXmlLocation, java.lang.String defaultWebXmlLocation, boolean useDOLforDeployment, com.sun.enterprise.deployment.WebBundleDescriptor wbd)
Create a web module/application.

param
ctxPath Context path for the web module
param
location Absolute pathname to the web module directory
param
defaultWebXmlLocation Location of default-web.xml


        File configFile = new File(location, Constants.WEB_CONTEXT_XML);
        WebModule context = new WebModule(webContainer);
        context.setDebug(debug);
        context.setPath(ctxPath);
        context.setDocBase(location);
        context.setCrossContext(true);
        context.setUseNaming(isUseNaming());
        context.setHasWebXml(wbd == null ? false : true);
        context.setWebBundleDescriptor(wbd);
        context.setManagerChecksFrequency(1);

        if (configFile.exists()) {
            context.setConfigFile(configFile.getAbsolutePath());
        }
            
        ContextConfig config;
        if (useDOLforDeployment) {            
            config = new WebModuleContextConfig();  
            ((WebModuleContextConfig)config).setDescriptor(wbd);
        } else {
            config = new ContextConfig();
        }
        
        config.setDefaultContextXml(defaultContextXmlLocation);
        config.setDefaultWebXml(defaultWebXmlLocation);
        ((Lifecycle) context).addLifecycleListener(config);

        context.addLifecycleListener(new WebModuleListener(
                webContainer.getInstanceClassPath(), location, wbd));

        context.addInstanceListener(Constants.J2EE_INSTANCE_LISTENER);
        
        context.addContainerListener(new WebContainerListener());

        context.addInstanceListener(
            "com.sun.enterprise.admin.monitor.callflow.WebContainerListener");
        
        return context;
    
public org.apache.catalina.EnginecreateEngine()
Create, configure, and return an Engine that will process all HTTP requests received from one of the associated Connectors, based on the specified properties. Do not create the JAAS default realm since all children will have their own.


        StandardEngine engine = new WebEngine(webContainer, _logger);

        engine.setDebug(debug);
        // Default host will be set to the first host added
        engine.setLogger(logger);       // Inherited by all children
        engine.setRealm(null);         // Inherited by all children
        
        ContainerListener listener = loadListener
            ("com.sun.enterprise.admin.monitor.callflow.WebContainerListener");
        if ( listener != null ) {
            engine.addContainerListener(listener);
        }
        return (engine);

    
public org.apache.catalina.HostcreateHost(java.lang.String vsID, com.sun.enterprise.config.serverbeans.VirtualServer vsBean, java.lang.String vsDocroot, java.lang.String vsLogFile, MimeMap vsMimeMap)
Creates a virtual server.

param
vsID Virtual server id
param
vsBean Bean corresponding to virtual-server element in domain.xml
param
vsDocRoot Virtual server docroot
param
vsMimeMap Virtual server MIME mappings
return
The generated virtual server instance


        VirtualServer vs = webContainerFeatureFactory.getVirtualServer();
        vs.setDebug(debug);
        vs.setAppBase(vsDocroot);
        vs.setName(vsID);
        vs.setID(vsID);
        vs.setBean(vsBean);
        vs.setMimeMap(vsMimeMap);

        String defaultContextXmlLocation = Constants.DEFAULT_CONTEXT_XML;
        String defaultWebXmlLocation = Constants.DEFAULT_WEB_XML;
    
        boolean allowLinking = false;
        String state = null;

        if (vsBean != null) {

            state = vsBean.getState();

            ElementProperty prop = null;

            //Begin EE: 4920692 Make the default-web.xml be relocatable
            prop = vsBean.getElementPropertyByName("default-web-xml");
            if (prop != null) {
                defaultWebXmlLocation = prop.getValue();
            }
            //End EE: 4920692 Make the default-web.xml be relocatable

            // allowLinking
            prop = vsBean.getElementPropertyByName("allowLinking");
            if (prop != null) {
                allowLinking = ConfigBean.toBoolean(prop.getValue());
            }

            prop = vsBean.getElementPropertyByName("contextXmlDefault");
            if (prop != null) {
                defaultContextXmlLocation = prop.getValue();
            }

        }

        vs.setDefaultWebXmlLocation(defaultWebXmlLocation);
       
        vs.setDefaultContextXmlLocation(defaultContextXmlLocation);

        // Set vs state
        if (state == null) {
            state = VirtualServer.ON;
        }
        if (VirtualServer.DISABLED.equalsIgnoreCase(state)) {
            vs.setIsActive(false);
        } else {
            vs.setIsActive(ConfigBean.toBoolean(state));
        }
        
        vs.setAllowLinking(allowLinking);

        if (vsLogFile != null && !vsLogFile.equals(logServiceFile)) {
            /*
             * Configure separate logger for this virtual server only if
             * 'log-file' attribute of this <virtual-server> and 'file'
             * attribute of <log-service> are different (See 6189219).
             */
            setLogFile(vs, vsLogFile);
        }
         
        ContainerListener listener = loadListener
                ("com.sun.enterprise.web.connector.extension.CatalinaListener");
        if ( listener != null )
            vs.addContainerListener(listener);     
        
        return vs;
    
public org.apache.catalina.Connector[]getConnectors()
Returns the list of Connector objects associated with this EmbeddedWebContainer.

return
The list of Connector objects associated with this EmbeddedWebContainer

        return connectors;
    
public org.apache.catalina.Engine[]getEngines()
Return the list of engines created (from Embedded API)

        return engines;
    
private org.apache.catalina.ContainerListenerloadListener(java.lang.String className)
Util method to load classes that might get compiled after this class is compiled.

        try{
            Class clazz = Class.forName(className);
            return (ContainerListener)clazz.newInstance();
        } catch (Throwable ex){
            _logger.log(Level.SEVERE,ex.getMessage() + ":" + className, ex);          
        }
        return null;
    
protected voidsetLogFile(org.apache.catalina.Host vs, java.lang.String logFile)


        String logPrefix = logFile;
        String logDir = null;
        String logSuffix = null;

        if (logPrefix == null || logPrefix.equals("")) {
            return;
        }

        int index = logPrefix.lastIndexOf(File.separatorChar);
        if (index != -1) {
            logDir = logPrefix.substring(0, index);
            logPrefix = logPrefix.substring(index+1);
        }
        
        index = logPrefix.indexOf('.");
        if (index != -1) {
            logSuffix = logPrefix.substring(index);
            logPrefix = logPrefix.substring(0, index);
        }

        logPrefix += "_";

        FileLogger contextLogger = new FileLogger();
        if (logDir != null) {
            contextLogger.setDirectory(logDir);
        }
        contextLogger.setPrefix(logPrefix);
        if (logSuffix != null) {
            contextLogger.setSuffix(logSuffix);
        }
        contextLogger.setTimestamp(true);

        vs.setLogger(contextLogger);