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

📄 apacheconfig.java

📁 低版本的tomcat 对于有些老版本的应用还真的需要老版的中间件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * ====================================================================
 *
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 1999 The Apache Software Foundation.  All rights 
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer. 
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution, if
 *    any, must include the following acknowlegement:  
 *       "This product includes software developed by the 
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowlegement may appear in the software itself,
 *    if and wherever such third-party acknowlegements normally appear.
 *
 * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
 *    Foundation" must not be used to endorse or promote products derived
 *    from this software without prior written permission. For written 
 *    permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache"
 *    nor may "Apache" appear in their names without prior written
 *    permission of the Apache Group.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 *
 * [Additional notices, if required by prior licensing conditions]
 *
 */
package org.apache.tomcat.task;

import org.apache.tomcat.core.*;
import org.apache.tomcat.util.*;
import java.io.*;
import java.net.*;
import java.util.*;

// Used to find Ajp12 connector port
import org.apache.tomcat.service.PoolTcpConnector;
import org.apache.tomcat.service.connector.Ajp12ConnectionHandler;

/**
 * Used by ContextManager to generate automatic apache configurations
 *
 * @author costin@dnt.ro
 */
public class ApacheConfig  { // implements XXX
    // XXX maybe conf/
    public static final String APACHE_CONFIG  = "/conf/tomcat-apache.conf";
    public static final String MOD_JK_CONFIG  = "/conf/mod_jk.conf";
    public static final String WORKERS_CONFIG = "/conf/workers.properties";
    public static final String JK_LOG_LOCATION = "/logs/mod_jk.log";

    public ApacheConfig() {
    }

    String findApache() {
	return null;
    }

    public void execute(ContextManager cm) throws TomcatException {
	try {
	    String tomcatHome = cm.getHome();
	    String apacheHome = findApache();

	    //System.out.println("Tomcat home= " + tomcatHome);

	    FileWriter configW=new FileWriter(tomcatHome + APACHE_CONFIG);
	    PrintWriter pw=new PrintWriter(configW);
        PrintWriter mod_jk = new PrintWriter(new FileWriter(tomcatHome + MOD_JK_CONFIG + "-auto"));

        mod_jk.println("###################################################################");
        mod_jk.println("# Auto generated configuration. Dated: " +  new Date());
        mod_jk.println("###################################################################");
        mod_jk.println();
        
        mod_jk.println("#");
        mod_jk.println("# The following line instructs Apache to load the jk module");
        mod_jk.println("#");
	    if( System.getProperty( "os.name" ).toLowerCase().indexOf("windows") >= 0 ) {
		pw.println("LoadModule jserv_module modules/ApacheModuleJServ.dll");
                mod_jk.println("LoadModule jk_module modules/mod_jk.dll");
                mod_jk.println();                
                mod_jk.println("JkWorkersFile \"" + new File(tomcatHome, WORKERS_CONFIG).toString().replace('\\', '/') + "\"");
                mod_jk.println("JkLogFile \"" + new File(tomcatHome, JK_LOG_LOCATION).toString().replace('\\', '/') + "\"");
	    } else if( System.getProperty( "os.name" ).startsWith("NetWare")) {
		// NetWare is a special case
		pw.println("LoadModule jserv_module modules/JServ.nlm");
                   mod_jk.println("LoadModule jk_module modules/mod_jk.nlm");
                   mod_jk.println();                
                   mod_jk.println("JkWorkersFile \"" + new File(tomcatHome, WORKERS_CONFIG).toString().replace('\\', '/') + "\"");
                   mod_jk.println("JkLogFile \"" + new File(tomcatHome, JK_LOG_LOCATION).toString().replace('\\', '/') + "\"");
	    } else {
		// XXX XXX change it to mod_jserv_${os.name}.so, put all so in tomcat
		// home
		pw.println("LoadModule jserv_module libexec/mod_jserv.so");
                mod_jk.println("LoadModule jk_module libexec/mod_jk.so");
                mod_jk.println();                                
                mod_jk.println("JkWorkersFile " + new File(tomcatHome, WORKERS_CONFIG));
                mod_jk.println("JkLogFile " + new File(tomcatHome, JK_LOG_LOCATION));
	    }


	    pw.println("ApJServManual on");
	    pw.println("ApJServDefaultProtocol ajpv12");
	    pw.println("ApJServSecretKey DISABLED");
	    pw.println("ApJServMountCopy on");
	    pw.println("ApJServLogLevel notice");
	    pw.println();

		// Find Ajp12 connector
		int portInt=8007;
		Enumeration enum=cm.getConnectors();
		while( enum.hasMoreElements() ) {
			Object con=enum.nextElement();
			if( con instanceof  PoolTcpConnector ) {
				PoolTcpConnector tcpCon=(PoolTcpConnector) con;
				if( tcpCon.getTcpConnectionHandler()
						instanceof Ajp12ConnectionHandler ) {
					portInt=tcpCon.getPort();
				}
			}
		}
		pw.println("ApJServDefaultPort " + portInt);
	    pw.println();

	    pw.println("AddType text/jsp .jsp");
	    pw.println("AddHandler jserv-servlet .jsp");
	    pw.println();

        mod_jk.println();
        mod_jk.println("#");        
        mod_jk.println("# Log level to be used by mod_jk");
        mod_jk.println("#");        
        mod_jk.println("JkLogLevel error");
	    mod_jk.println();

        mod_jk.println("###################################################################");
        mod_jk.println("#                     SSL configuration                           #");
        mod_jk.println("# ");                
        mod_jk.println("# By default mod_jk is configured to collect SSL information from");
        mod_jk.println("# the apache environment and send it to the Tomcat workers. The");
        mod_jk.println("# problem is that there are many SSL solutions for Apache and as");
        mod_jk.println("# a result the environment variable names may change.");
        mod_jk.println("#");        
        mod_jk.println("# The following (commented out) JK related SSL configureation");        
        mod_jk.println("# can be used to customize mod_jk's SSL behaviour.");        
        mod_jk.println("# ");        
        mod_jk.println("# Should mod_jk send SSL information to Tomact (default is On)");        
        mod_jk.println("# JkExtractSSL Off");        
        mod_jk.println("# ");        
        mod_jk.println("# What is the indicator for SSL (default is HTTPS)");        
        mod_jk.println("# JkHTTPSIndicator HTTPS");        
        mod_jk.println("# ");        
        mod_jk.println("# What is the indicator for SSL session (default is SSL_SESSION_ID)");        

⌨️ 快捷键说明

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