⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jettycontainer.java

📁 国外的一套开源CRM
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * $Id: JettyContainer.java,v 1.20 2004/01/24 18:43:02 ajzeneski Exp $
 *
 * Copyright (c) 2003 The Open For Business Project - www.ofbiz.org
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
 * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */
package org.ofbiz.base.container;

import java.io.IOException;
import java.net.UnknownHostException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.log4j.Priority;
import org.mortbay.http.NCSARequestLog;
import org.mortbay.http.SocketListener;
import org.mortbay.http.SunJsseListener;
import org.mortbay.http.ajp.AJP13Listener;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.WebApplicationContext;
import org.mortbay.util.Frame;
import org.mortbay.util.Log;
import org.mortbay.util.LogSink;
import org.mortbay.util.MultiException;
import org.mortbay.util.ThreadedServer;
import org.ofbiz.base.component.ComponentConfig;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilURL;
import org.ofbiz.base.util.SSLUtil;

/**
 * JettyContainer - Container implementation for Jetty
 * This container depends on the ComponentContainer as well.
 *
 * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
  *@version    $Revision: 1.20 $
 * @since      3.0
 */
public class JettyContainer implements Container {

    public static final String module = JettyContainer.class.getName();
    private Map servers = new HashMap();

    private void init(String configFile) throws ContainerException {
        // configure JSSE properties
        SSLUtil.loadJsseProperties();

        // configure jetty logging
        Log log = Log.instance();
        log.disableLog();
        Log4jSink sink = new Log4jSink();
        log.add(sink);
        sink.setOptions(UtilURL.fromResource("debug.properties").toExternalForm());
        try {
            sink.start();
        } catch (Exception e) {
            Debug.logWarning(e, module);
        }

        // get the container
        ContainerConfig.Container jc = ContainerConfig.getContainer("jetty-container", configFile);

        // create the servers
        Iterator sci = jc.properties.values().iterator();
        while (sci.hasNext()) {
            ContainerConfig.Container.Property prop = (ContainerConfig.Container.Property) sci.next();
            servers.put(prop.name, createServer(prop));
        }

        // load the applications
        Collection componentConfigs = ComponentConfig.getAllComponents();
        if (componentConfigs != null) {
            Iterator components = componentConfigs.iterator();
            while (components.hasNext()) {
                ComponentConfig component = (ComponentConfig) components.next();
                Iterator appInfos = component.getWebappInfos().iterator();
                while (appInfos.hasNext()) {
                    ComponentConfig.WebappInfo appInfo = (ComponentConfig.WebappInfo) appInfos.next();
                    List virtualHosts = appInfo.getVirtualHosts();
                    Map initParameters = appInfo.getInitParameters();
                    Server server = (Server) servers.get(appInfo.server);
                    if (server == null) {
                        Debug.logWarning("Server with name [" + appInfo.server + "] not found; not mounting [" + appInfo.name + "]", module);
                    } else {
                        try {
                            // set the root location (make sure we set the paths correctly)
                            String location = component.getRootLocation() + appInfo.location;
                            location = location.replace('\\', '/');
                            if (!location.endsWith("/")) {
                                location = location + "/";
                            }

                            // load the application
                            WebApplicationContext ctx = server.addWebApplication(appInfo.mountPoint, location);
                            ctx.setAttribute("_serverId", appInfo.server);

                            // set the virtual hosts
                            Iterator vh = virtualHosts.iterator();
                            while (vh.hasNext()) {
                                ctx.addVirtualHost((String)vh.next());
                            }

                            // set the init parameters
                            Iterator ip = initParameters.keySet().iterator();
                            while (ip.hasNext()) {
                                String paramName = (String) ip.next();
                                ctx.setInitParameter(paramName, (String) initParameters.get(paramName));
                            }

                        } catch (IOException e) {
                            Debug.logError(e, "Problem mounting application [" + appInfo.name + " / " + appInfo.location + "]", module);
                        }
                    }
                }
            }
        }
    }

    private Server createServer(ContainerConfig.Container.Property serverConfig) throws ContainerException {
        Server server = new Server();

        // configure the listeners/loggers
        Iterator properties = serverConfig.properties.values().iterator();
        while (properties.hasNext()) {
            ContainerConfig.Container.Property props =
                    (ContainerConfig.Container.Property) properties.next();

            if ("listener".equals(props.value)) {
                if ("default".equals(props.getProperty("type").value)) {
                    SocketListener listener = new SocketListener();
                    setListenerOptions(listener, props);
                    if (props.getProperty("identify-listener") != null) {
                        boolean identifyListener = "true".equalsIgnoreCase(props.getProperty("identify-listener").value);
                        listener.setIdentifyListener(identifyListener);
                    }
                    if (props.getProperty("buffer-size") != null) {
                        int value = 0;
                        try {
                            value = Integer.parseInt(props.getProperty("buffer-size").value);
                        } catch (NumberFormatException e) {
                            value = 0;
                        }
                        if (value > 0) {
                            listener.setBufferSize(value);
                        }
                    }
                    if (props.getProperty("low-resource-persist-time") != null) {
                        int value = 0;
                        try {
                            value = Integer.parseInt(props.getProperty("low-resource-persist-time").value);
                        } catch (NumberFormatException e) {
                            value = 0;
                        }
                        if (value > 0) {
                            listener.setLowResourcePersistTimeMs(value);
                        }
                    }
                    server.addListener(listener);
                } else if ("sun-jsse".equals(props.getProperty("type").value)) {
                    SunJsseListener listener = new SunJsseListener();
                    setListenerOptions(listener, props);
                    if (props.getProperty("keystore") != null) {
                        listener.setKeystore(props.getProperty("keystore").value);
                    }
                    if (props.getProperty("password") != null) {
                        listener.setPassword(props.getProperty("password").value);
                    }
                    if (props.getProperty("key-password") != null) {
                        listener.setKeyPassword(props.getProperty("key-password").value);
                    }
                    if (props.getProperty("need-client-auth") != null) {
                        boolean needClientAuth = "true".equalsIgnoreCase(props.getProperty("need-client-auth").value);
                        listener.setNeedClientAuth(needClientAuth);
                    }
                    if (props.getProperty("identify-listener") != null) {
                        boolean identifyListener = "true".equalsIgnoreCase(props.getProperty("identify-listener").value);
                        listener.setIdentifyListener(identifyListener);
                    }
                    if (props.getProperty("buffer-size") != null) {
                        int value = 0;
                        try {
                            value = Integer.parseInt(props.getProperty("buffer-size").value);
                        } catch (NumberFormatException e) {
                            value = 0;
                        }
                        if (value > 0) {
                            listener.setBufferSize(value);
                        }
                    }
                    if (props.getProperty("low-resource-persist-time") != null) {
                        int value = 0;
                        try {
                            value = Integer.parseInt(props.getProperty("low-resource-persist-time").value);
                        } catch (NumberFormatException e) {
                            value = 0;
                        }
                        if (value > 0) {
                            listener.setLowResourcePersistTimeMs(value);
                        }
                    }
                    server.addListener(listener);
                } else if ("ibm-jsse".equals(props.getProperty("type").value)) {
                    throw new ContainerException("Listener not supported yet [" + props.getProperty("type").value + "]");
                } else if ("nio".equals(props.getProperty("type").value)) {
                    throw new ContainerException("Listener not supported yet [" + props.getProperty("type").value + "]");
                } else if ("ajp13".equals(props.getProperty("type").value)) {
                    AJP13Listener listener = new AJP13Listener();
                    setListenerOptions(listener, props);
                    if (props.getProperty("identify-listener") != null) {
                        boolean identifyListener = "true".equalsIgnoreCase(props.getProperty("identify-listener").value);
                        listener.setIdentifyListener(identifyListener);
                    }
                    if (props.getProperty("buffer-size") != null) {
                        int value = 0;
                        try {
                            value = Integer.parseInt(props.getProperty("buffer-size").value);
                        } catch (NumberFormatException e) {
                            value = 0;
                        }
                        if (value > 0) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -