/*
* Copyright 2005-2007 WSO2, Inc. (http://wso2.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wso2.carbon.server;
import org.apache.catalina.connector.Connector;
import org.wso2.carbon.tomcat.BetterTomcat;
import org.wso2.carbon.utils.CarbonUtils;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* A set of utility methods for interacting with Embedded Tomcat
*/
public class TomcatUtil {
private static BetterTomcat tomcat;
private static Map<String, TomcatGenericWebappsDeployer> webappsDeployers
= new HashMap<String, TomcatGenericWebappsDeployer>();
public synchronized static BetterTomcat getTomcat() {
CarbonUtils.checkSecurity();
if (tomcat == null) {
tomcat = new BetterTomcat();
boolean unpackWars =
Boolean.parseBoolean(System.getProperty("carbon.unpack.wars", "false"));
tomcat.setUnpackWars(unpackWars);
}
return tomcat;
}
/**
* Get a Tomcat Connector. If a connector with th
*
* @param protocol The protocol of the connector.
* @param address The IP address of the network interface to which this connector should bind
* to. Specify this as null if the connector should bind to all network interfaces.
* @param port The port on which this connector has to be run
* @return The Tomcat connector
*/
public static Connector getConnector(BetterTomcat.Protocol protocol, String address, int port) {
CarbonUtils.checkSecurity();
return getTomcat().addConnector(protocol, address, port);
}
/**
* Add a TomcatGenericWebappsDeployer
*
* @param webappsDir The directory in which the webapps are found
* @param webappsDeployer The corresponding TomcatGenericWebappsDeployer
*/
@SuppressWarnings("unused")
public static void addWebappsDeployer(String webappsDir,
TomcatGenericWebappsDeployer webappsDeployer) {
CarbonUtils.checkSecurity();
webappsDeployers.put(webappsDir, webappsDeployer);
}
/**
* Retrieve the list of registered webapps deployers
*
* @return an unmodifiable list of registered webapps deployers
*/
@SuppressWarnings("unused")
public static Map<String, TomcatGenericWebappsDeployer> getWebappsDeployers() {
CarbonUtils.checkSecurity();
return Collections.unmodifiableMap(webappsDeployers);
}
}