Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Copyright (c) 1997-2012 Oracle and/or its affiliates. All rights reserved.
   * The contents of this file are subject to the terms of either the GNU
   * General Public License Version 2 only ("GPL") or the Common Development
   * and Distribution License("CDDL") (collectively, the "License").  You
   * may not use this file except in compliance with the License.  You can
  * obtain a copy of the License at
  * or packager/legal/LICENSE.txt.  See the License for the specific
  * language governing permissions and limitations under the License.
  * When distributing the software, include this License Header Notice in each
  * file and include the License file at packager/legal/LICENSE.txt.
  * GPL Classpath Exception:
  * Oracle designates this particular file as subject to the "Classpath"
  * exception as provided by Oracle in the GPL Version 2 section of the License
  * file that accompanied this code.
  * Modifications:
  * If applicable, add the following below the License Header, with the fields
  * enclosed by brackets [] replaced by your own identifying information:
  * "Portions Copyright [year] [name of copyright owner]"
  * Contributor(s):
  * If you wish your version of this file to be governed by only the CDDL or
  * only the GPL Version 2, indicate your decision by adding "[Contributor]
  * elects to include this software in this distribution under the [CDDL or GPL
  * Version 2] license."  If you don't indicate a single choice of license, a
  * recipient has the option to distribute your version of this file under
  * either the CDDL, the GPL Version 2 or to extend the choice of license to
  * its licensees as provided above.  However, if you add GPL Version 2 code
  * and therefore, elected the GPL Version 2 license, then the option applies
  * only if the new code is made subject to such option by the copyright
  * holder.
 package com.sun.enterprise.web;
Represents an embedded Catalina web container within the Application Server.
 public final class EmbeddedWebContainer extends Embedded implements PostConstruct {
     public static final Logger logger = .;
             message = "Unable to instantiate ContainerListener of type {0}",
             level = "SEVERE",
             cause = "An exception occurred during instantiation of ContainerListener of type {0}",
             action = "Check the Exception for error")
     public static final String UNABLE_TO_INSTANTIATE_CONTAINER_LISTENER = "AS-WEB-00044";
             message = "Creating connector for address='{0}' port='{1}' protocol='{2}'",
             level = "FINE")
     public static final String CREATE_CONNECTOR = "AS-WEB-00045";
     private ServiceLocator services;
     private ServerContext serverContext;
     private WebContainer webContainer;
     * The value of the 'file' attribute of the log-service element
    private String logServiceFile;
     * The log level for org.apache.catalina.level as defined in 
    private String logLevel;
    void setWebContainer(WebContainer webContainer) {
        this. = webContainer;
    void setLogServiceFile(String logServiceFile) {
        this. = logServiceFile;
    void setLogLevel(String logLevel) {
        this. = logLevel;
    void setFileLoggerHandlerFactory(FileLoggerHandlerFactory fileLoggerHandlerFactory) {
        this. = fileLoggerHandlerFactory;
    void setWebContainerFeatureFactory(WebContainerFeatureFactory webContainerFeatureFactory) {
        this. = webContainerFeatureFactory;
    // --------------------------------------------------------- Public Methods
    public void postConstruct() {
Creates a virtual server.

vsID Virtual server id
vsBean Bean corresponding to virtual-server element in domain.xml
vsDocroot Virtual server docroot
vsMimeMap Virtual server MIME mappings
The generated virtual server instance
    public Host createHost(
                    String vsID,
                    com.sun.enterprise.config.serverbeans.VirtualServer vsBean,
                    String vsDocroot,
                    String vsLogFile,
                    MimeMap vsMimeMap) {
        VirtualServer vs = new VirtualServer();
        ContainerListener listener = loadListener
        if ( listener != null ) {
        return vs;
Create a web module/application.

ctxPath Context path for the web module
location Absolute pathname to the web module directory
defaultWebXmlLocation Location of default-web.xml
    public Context createContext(String id,
                                 String ctxPath,
                                 File location,
                                 String defaultContextXmlLocation,
                                 String defaultWebXmlLocation
                                 boolean useDOLforDeployment,
                                 WebModuleConfig wmInfo) {
        File configFile = null;
        // check contextPath.xml and /META-INF/context.xml if not found
        if (ctxPath.equals("")) {
            configFile = new File(getCatalinaHome()+"/config""ROOT.xml");
        } else {
            configFile = new File(getCatalinaHome()+"/config"ctxPath+".xml");
        if (!configFile.exists()) {
            configFile = new File(location.);
        WebModule context = new WebModule();
        context.setHasWebXml(wmInfo.getDescriptor() != null);
        if () {
        if (configFile.exists()) {
        ContextConfig config;
        if (useDOLforDeployment) {            
            config = new WebModuleContextConfig();
        } else {
            config = new ContextConfig();
        // TODO: should any of those become WebModuleDecorator, too?
        context.addLifecycleListener(new WebModuleListener(wmInfo.getDescriptor()));
                new WebContainerListener());
        // TODO: monitoring should also hook in via WebModuleDecorator
        //    "com.sun.enterprise.admin.monitor.callflow.WebContainerListener");
        return context;

Util method to load classes that might get compiled after this class is compiled.
    private ContainerListener loadListener(String className){
            Class clazz = Class.forName(className);
            return (ContainerListener)clazz.newInstance();
        } catch (Throwable ex){
            msg = MessageFormat.format(msgclassName);
        return null;
Return the list of engines created (from Embedded API)
    public Engine[] getEngines() {
        return ;

Returns the list of Connector objects associated with this EmbeddedWebContainer.

The list of Connector objects associated with this EmbeddedWebContainer
    public Connector[] getConnectors() {
        return ;

Create a customized version of the Tomcat's 5 Coyote Connector. This connector is required in order to support PE Web Programmatic login functionality.

address InetAddress to bind to, or null if the connector is supposed to bind to all addresses on this server
port Port number to listen to
protocol the http protocol to use.
    public Connector createConnector(String addressint port,
				     String protocol) {
        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);
        if (.isLoggable(.)) {
            .log(.new Object[]{(address == null) ? "ALL" : addressportprotocol});
        WebConnector connector = new WebConnector();
        if (address != null) {
        if (protocol.equals("ajp")) {
        } else if (protocol.equals("memory")) {
        } else if (protocol.equals("https")) {
        return (connector);

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.
    public Engine createEngine() {
        StandardEngine engine = new StandardEngine();
        // Default host will be set to the first host added
        engine.setLogger(super.getLogger());       // 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);
    static class WebEngine extends StandardEngine {
        private WebContainer webContainer;
        public WebEngine(WebContainer webContainer) {
            this.webContainer = webContainer;
        public Realm getRealm(){
            return null;
         * Starts the children (virtual servers) of this StandardEngine
         * concurrently.
        protected void startChildren() {
            new File(webContainer.getAppsWorkRoot()).mkdirs();
            new File(webContainer.getModulesWorkRoot()).mkdirs();
            ArrayList<LifecycleStarter> starters
                = new ArrayList<LifecycleStarter>();
            Container children[] = findChildren();
            for (int i = 0; i < children.length; i++) {
                if (children[i] instanceof Lifecycle) {
                    LifecycleStarter starter =
                        new LifecycleStarter(((Lifecycle) children[i]));
            for (LifecycleStarter starter : starters) {
                Throwable t = starter.waitDone(); 
                if (t != null) {
                    Lifecycle container = starter.getContainer();
                    String msg = rb.getString("embedded.startVirtualServerError");
                    msg = MessageFormat.format(msg, new Object[] { container });
                    _logger.log(Level.SEVERE, msg, t);
New to GrepCode? Check out our FAQ X