Java Code Examples for org.apache.catalina.connector.Connector#getProtocolHandler()

The following examples show how to use org.apache.catalina.connector.Connector#getProtocolHandler() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TomcatConfig.java    From tailstreamer with MIT License 6 votes vote down vote up
private Connector createSslConnector() {
    if (sslConfig == null) {
        throw new IllegalStateException("SSL configuration not specified");
    }

    Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
    Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
    connector.setScheme("https");
    connector.setSecure(true);
    connector.setPort(sslConfig.getPort());
    protocol.setSSLEnabled(sslConfig.isEnable());
    protocol.setKeystoreFile(sslConfig.getKeystore());
    protocol.setKeystorePass(sslConfig.getKeystorePassword());
    protocol.setKeyAlias(sslConfig.getKeyAlias());

    logger.info(String.format("Initializing SSL connector on port %d", sslConfig.getPort()));
    return connector;
}
 
Example 2
Source File: TomcatConfiguration.java    From odata with Apache License 2.0 6 votes vote down vote up
private Connector createSslConnector() {
    Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
    Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
    try {
        File keystore = new ClassPathResource(keystorePath).getFile();
        connector.setScheme(HTTPS_SCHEME);
        connector.setSecure(true);
        connector.setPort(Integer.parseInt(httpsPort));
        protocol.setSSLEnabled(true);
        protocol.setKeystoreFile(keystore.getAbsolutePath());
        protocol.setKeystorePass(keystorePasswd);
        protocol.setTruststoreFile(keystore.getAbsolutePath());
        protocol.setTruststorePass(truststorePasswd);
        protocol.setKeyAlias(keyAlias);
        return connector;
    } catch (IOException ex) {
        throw new IllegalStateException("cant access keystore: [" + "keystore"
                + "] or truststore: [" + "keystore" + "]", ex);
    }
}
 
Example 3
Source File: ServletContainerConfiguration.java    From haven-platform with Apache License 2.0 6 votes vote down vote up
/**
 * Configures ssl connector
 *
 * @return
 */
Connector createSslConnector() {
    log.info("About to start ssl connector at port {} with {} keystoreFile", tlsPort, keystoreFile);
    final String absoluteKeystoreFile = new File(keystoreFile).getAbsolutePath();

    Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
    connector.setPort(tlsPort);
    connector.setSecure(true);
    connector.setScheme("https");

    Http11NioProtocol proto = (Http11NioProtocol) connector.getProtocolHandler();
    proto.setSSLEnabled(true);
    proto.setKeystoreFile(absoluteKeystoreFile);
    proto.setKeystorePass(keystorePass);
    proto.setKeystoreType("PKCS12");
    proto.setSslProtocol("TLSv1.2");
    proto.setKeyAlias("tomcat");
    return connector;
}
 
Example 4
Source File: TomcatApplication.java    From micro-server with Apache License 2.0 6 votes vote down vote up
private void addSSL(Connector connector) {
    try {

        SSLProperties sslProperties = serverData.getRootContext().getBean(SSLProperties.class);
        ProtocolHandler handler = connector.getProtocolHandler();
        if (sslProperties != null && handler instanceof AbstractHttp11JsseProtocol) {
            new SSLConfigurationBuilder().build((AbstractHttp11JsseProtocol) handler, sslProperties);
            connector.setScheme("https");
            connector.setSecure(true);
        }

    } catch (BeanNotOfRequiredTypeException e) {

    }


}
 
Example 5
Source File: CrnkTomcatAutoConfiguration.java    From crnk-framework with Apache License 2.0 6 votes vote down vote up
@Override
public void customize(Connector connector) {
	ProtocolHandler protocolHandler = connector.getProtocolHandler();
	if (protocolHandler instanceof AbstractHttp11Protocol) {
		AbstractHttp11Protocol protocol11 = (AbstractHttp11Protocol) protocolHandler;
		try {
			String relaxedQueryChars = (String) PropertyUtils.getProperty(protocol11, PROPERTY_NAME);
			if (relaxedQueryChars == null) {
				relaxedQueryChars = "";
			}
			relaxedQueryChars += "[]{}";
			PropertyUtils.setProperty(protocol11, PROPERTY_NAME, relaxedQueryChars);
		} catch (Exception e) {
			LOGGER.debug("failed to set relaxed query charts, Tomcat might be outdated");
		}
	}
}
 
Example 6
Source File: HttpProxyContainer.java    From odo with Apache License 2.0 6 votes vote down vote up
private Connector createSslConnector() {
    Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
    Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
    final int httpsPort = Utils.getSystemPort(Constants.SYS_HTTPS_PORT);
    try {
        File keyStore = com.groupon.odo.proxylib.Utils.copyResourceToLocalFile("tomcat.ks", "tomcat.ks");
        connector.setScheme("https");
        connector.setSecure(true);
        connector.setPort(httpsPort);
        protocol.setSSLEnabled(true);
        protocol.setSslProtocol("TLS");
        protocol.setKeystoreFile(keyStore.getAbsolutePath());
        protocol.setKeystorePass("changeit");
        return connector;
    } catch (IOException ex) {
        throw new IllegalStateException("can't access keystore: [" + "keystore"
                                            + "] or truststore: [" + "keystore" + "]", ex);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 7
Source File: TomcatConfig.java    From singleton with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * create the https additional connection for tomcat
 */
private Connector initiateHttpsConnector(ServerProperties serverProperties) {
	Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
	connector.setScheme(ConstantsTomcat.HTTPS);
	connector.setPort(serverProperties.getServerPort());
	connector.setSecure(true);
	Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
	protocol.setSSLEnabled(true);
	protocol.setKeystoreFile(serverProperties.getHttpsKeyStore());
	protocol.setKeystorePass(serverProperties.getHttpsKeyStorePassword());
	protocol.setKeystoreType(serverProperties.getHttpsKeyStoreType());
	protocol.setKeyPass(serverProperties.getHttpsKeyPassword());
	protocol.setKeyAlias(serverProperties.getHttpsKeyAlias());
	protocol.setMaxHttpHeaderSize(serverProperties.getMaxHttpHeaderSize());
	connector.setRedirectPort(ConstantsTomcat.REDIRECT_PORT);
	connector.setAllowTrace(serverProperties.isAllowTrace());
	return connector;
}
 
Example 8
Source File: TomcatConfig.java    From singleton with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * create the https additional connection for tomcat
 */
private Connector initiateHttpsConnector(ServerProperties serverProperties) {
	Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
	connector.setScheme(ConstantsTomcat.HTTPS);
	connector.setPort(serverProperties.getServerPort());
	connector.setSecure(true);
	Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
	protocol.setSSLEnabled(true);
	protocol.setKeystoreFile(serverProperties.getHttpsKeyStore());
	protocol.setKeystorePass(serverProperties.getHttpsKeyStorePassword());
	protocol.setKeystoreType(serverProperties.getHttpsKeyStoreType());
	protocol.setKeyPass(serverProperties.getHttpsKeyPassword());
	protocol.setKeyAlias(serverProperties.getHttpsKeyAlias());
	protocol.setMaxHttpHeaderSize(serverProperties.getMaxHttpHeaderSize());
	connector.setRedirectPort(ConstantsTomcat.REDIRECT_PORT);
	connector.setAllowTrace(serverProperties.isAllowTrace());
	return connector;
}
 
Example 9
Source File: Bootstrap.java    From lite-tracer with Apache License 2.0 5 votes vote down vote up
@Override
public void customize(Connector connector) {
    Http11NioProtocol protocol = (Http11NioProtocol) connector
            .getProtocolHandler();
    // 设置最大连接数
    protocol.setMaxConnections(2000);
    // 设置最大线程数
    protocol.setMaxThreads(2000);
    protocol.setConnectionTimeout(30000);
}
 
Example 10
Source File: Bootstrap.java    From lite-tracer with Apache License 2.0 5 votes vote down vote up
@Override
public void customize(Connector connector) {
    Http11NioProtocol protocol = (Http11NioProtocol) connector
            .getProtocolHandler();
    // 设置最大连接数
    protocol.setMaxConnections(2000);
    // 设置最大线程数
    protocol.setMaxThreads(2000);
    protocol.setConnectionTimeout(30000);
}
 
Example 11
Source File: TomcatConnectorBean.java    From amazon-echo-ha-bridge with Apache License 2.0 5 votes vote down vote up
private Connector createConnector(int portNumber) {
    Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
    Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
    connector.setScheme("http");
    connector.setPort(portNumber);
    return connector;
}
 
Example 12
Source File: TomcatServerFactory.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
static int getLocalPort(Tomcat tomcat) {
    Service[] services = tomcat.getServer().findServices();
    for (Service service : services) {
        for (Connector connector : service.findConnectors()) {
            ProtocolHandler protocolHandler = connector.getProtocolHandler();
            if (protocolHandler instanceof Http11AprProtocol || protocolHandler instanceof Http11NioProtocol) {
                return connector.getLocalPort();
            }
        }
    }
    return 0;
}
 
Example 13
Source File: WebServerConfiguration.java    From goods-seckill with Apache License 2.0 5 votes vote down vote up
public void customize(Connector connector) {
	Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
	// 设置最大连接数
	protocol.setMaxConnections(2000);
	// 设置最大线程数
	protocol.setMaxThreads(2000);
	protocol.setConnectionTimeout(30000);
}
 
Example 14
Source File: MBeanUtils.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Deregister the MBean for this
 * <code>Connector</code> object.
 *
 * @param connector The Connector to be managed
 *
 * @exception Exception if an MBean cannot be deregistered
 * @deprecated  Unused. Will be removed in Tomcat 8.0.x
 */
@Deprecated
static void destroyMBean(Connector connector, Service service)
    throws Exception {

    // domain is engine name
    String domain = service.getContainer().getName();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ObjectName oname = createObjectName(domain, connector);
    if( mserver.isRegistered( oname ))  {
        mserver.unregisterMBean(oname);
    }
    // Unregister associated request processor
    String worker = null;
    ProtocolHandler handler = connector.getProtocolHandler();
    if (handler instanceof Http11Protocol) {
        worker = ((Http11Protocol)handler).getName();
    } else if (handler instanceof Http11NioProtocol) {
        worker = ((Http11NioProtocol)handler).getName();
    } else if (handler instanceof Http11AprProtocol) {
        worker = ((Http11AprProtocol)handler).getName();
    } else if (handler instanceof AjpProtocol) {
        worker = ((AjpProtocol)handler).getName();
    } else if (handler instanceof AjpAprProtocol) {
        worker = ((AjpAprProtocol)handler).getName();
    }
    ObjectName query = new ObjectName(
            domain + ":type=RequestProcessor,worker=" + worker + ",*");
    Set<ObjectName> results = mserver.queryNames(query, null);
    for(ObjectName result : results) {
        mserver.unregisterMBean(result);
    }
}
 
Example 15
Source File: ThreadLocalLeakPreventionListener.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Updates each ThreadPoolExecutor with the current time, which is the time
 * when a context is being stopped.
 * 
 * @param context
 *            the context being stopped, used to discover all the Connectors
 *            of its parent Service.
 */
private void stopIdleThreads(Context context) {
    if (serverStopping) return;

    if (!(context instanceof StandardContext) ||
        !((StandardContext) context).getRenewThreadsWhenStoppingContext()) {
        log.debug("Not renewing threads when the context is stopping. "
            + "It is not configured to do it.");
        return;
    }

    Engine engine = (Engine) context.getParent().getParent();
    Service service = engine.getService();
    Connector[] connectors = service.findConnectors();
    if (connectors != null) {
        for (Connector connector : connectors) {
            ProtocolHandler handler = connector.getProtocolHandler();
            Executor executor = null;
            if (handler != null) {
                executor = handler.getExecutor();
            }

            if (executor instanceof ThreadPoolExecutor) {
                ThreadPoolExecutor threadPoolExecutor =
                    (ThreadPoolExecutor) executor;
                threadPoolExecutor.contextStopping();
            } else if (executor instanceof StandardThreadExecutor) {
                StandardThreadExecutor stdThreadExecutor =
                    (StandardThreadExecutor) executor;
                stdThreadExecutor.contextStopping();
            }

        }
    }
}
 
Example 16
Source File: HttpsConfiguration.java    From spring-boot with Apache License 2.0 5 votes vote down vote up
public Connector createSslConnector() {

        Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
        Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();

        connector.setPort(properties.getPort());
        connector.setScheme("https");
        connector.setSecure(true);
        protocol.setSSLEnabled(true);
        protocol.setClientAuth("false");
        protocol.setSSLProtocol("TLSv1+TLSv1.1+TLSv1.2");
        protocol.setKeystoreFile(properties.getKeystoreFile());
        protocol.setKeystorePass(properties.getKeystorePassword());
        return connector;
    }
 
Example 17
Source File: MBeanUtils.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Deregister the MBean for this
 * <code>Connector</code> object.
 *
 * @param connector The Connector to be managed
 *
 * @exception Exception if an MBean cannot be deregistered
 * @deprecated  Unused. Will be removed in Tomcat 8.0.x
 */
@Deprecated
static void destroyMBean(Connector connector, Service service)
    throws Exception {

    // domain is engine name
    String domain = service.getContainer().getName();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ObjectName oname = createObjectName(domain, connector);
    if( mserver.isRegistered( oname ))  {
        mserver.unregisterMBean(oname);
    }
    // Unregister associated request processor
    String worker = null;
    ProtocolHandler handler = connector.getProtocolHandler();
    if (handler instanceof Http11Protocol) {
        worker = ((Http11Protocol)handler).getName();
    } else if (handler instanceof Http11NioProtocol) {
        worker = ((Http11NioProtocol)handler).getName();
    } else if (handler instanceof Http11AprProtocol) {
        worker = ((Http11AprProtocol)handler).getName();
    } else if (handler instanceof AjpProtocol) {
        worker = ((AjpProtocol)handler).getName();
    } else if (handler instanceof AjpAprProtocol) {
        worker = ((AjpAprProtocol)handler).getName();
    }
    ObjectName query = new ObjectName(
            domain + ":type=RequestProcessor,worker=" + worker + ",*");
    Set<ObjectName> results = mserver.queryNames(query, null);
    for(ObjectName result : results) {
        mserver.unregisterMBean(result);
    }
}
 
Example 18
Source File: WebServerConfiguration.java    From youkefu with Apache License 2.0 5 votes vote down vote up
public void customize(Connector connector)  
{  
    Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();  
    //设置最大连接数
    protocol.setMaxConnections(maxthread!=null ? maxthread : 2000);  
    //设置最大线程数  
    protocol.setMaxThreads(maxconnection!=null ? maxconnection: 2000);  
    protocol.setConnectionTimeout(30000);  
}
 
Example 19
Source File: ManagerServlet.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
protected void sslReload(PrintWriter writer, String tlsHostName, StringManager smClient) {
    Connector connectors[] = getConnectors();
    boolean found = false;
    for (Connector connector : connectors) {
        if (Boolean.TRUE.equals(connector.getProperty("SSLEnabled"))) {
            ProtocolHandler protocol = connector.getProtocolHandler();
            if (protocol instanceof AbstractHttp11Protocol<?>) {
                AbstractHttp11Protocol<?> http11Protoocol = (AbstractHttp11Protocol<?>) protocol;
                if (tlsHostName == null || tlsHostName.length() == 0) {
                    found = true;
                    http11Protoocol.reloadSslHostConfigs();
                } else {
                    SSLHostConfig[] sslHostConfigs = http11Protoocol.findSslHostConfigs();
                    for (SSLHostConfig sslHostConfig : sslHostConfigs) {
                        if (sslHostConfig.getHostName().equalsIgnoreCase(tlsHostName)) {
                            found = true;
                            http11Protoocol.reloadSslHostConfig(tlsHostName);
                        }
                    }
                }
            }
        }
    }
    if (found) {
        if (tlsHostName == null || tlsHostName.length() == 0) {
            writer.println(smClient.getString("managerServlet.sslReloadAll"));
        } else {
            writer.println(smClient.getString("managerServlet.sslReload", tlsHostName));
        }
    } else {
        writer.println(smClient.getString("managerServlet.sslReloadFail"));
    }
}
 
Example 20
Source File: TomcatServer.java    From onetwo with Apache License 2.0 4 votes vote down vote up
public void initialize() {
		try {
			JFishTomcat tomcat = new JFishTomcat();
			if(serverConfig.getTomcatContextClassName()!=null){
				tomcat.setContextClass((Class<StandardContext>)ReflectUtils.loadClass(serverConfig.getTomcatContextClassName(), true));
			}
			int port = serverConfig.getPort();
			tomcat.setPort(port);
//			tomcat.setBaseDir(webConfig.getServerBaseDir());
			String baseDir = null;
			if(!Utils.isBlank(serverConfig.getServerBaseDir())){
				baseDir = serverConfig.getServerBaseDir();
			}else{
				baseDir = System.getProperty("java.io.tmpdir");
				logger.info("set serverBaseDir as java.io.tmpdir : {} ", baseDir);
			}
			tomcat.setBaseDir(baseDir);
			
			// This magic line makes Tomcat look for WAR files in catalinaHome/webapps
			// and automatically deploy them
//			tomcat.getHost().addLifecycleListener(new HostConfig());
			appBaseFile = new File(baseDir+"/tomcat.webapps."+this.serverConfig.getPort());
			if(!appBaseFile.exists()){
				appBaseFile.mkdirs();
			}
			appBaseFile.deleteOnExit();
			tomcat.getHost().setAppBase(appBaseFile.getAbsolutePath());
			Connector connector = tomcat.getConnector();
			connector.setURIEncoding("UTF-8");
			connector.setRedirectPort(serverConfig.getRedirectPort());
			connector.setMaxPostSize(serverConfig.getMaxPostSize());
			
			ProtocolHandler protocol = connector.getProtocolHandler();
			if(protocol instanceof AbstractHttp11Protocol){
				/*****
				 * <Connector port="8080" protocol="HTTP/1.1" 
					   connectionTimeout="20000" 
   						redirectPort="8181" compression="500" 
  						compressableMimeType="text/html,text/xml,text/plain,application/octet-stream" />
				 */
				AbstractHttp11Protocol<?> hp = (AbstractHttp11Protocol<?>) protocol;
				hp.setCompression("on");
				hp.setCompressableMimeTypes("text/html,text/xml,text/plain,application/octet-stream");
			}
			
			
			StandardServer server = (StandardServer) tomcat.getServer();
			AprLifecycleListener listener = new AprLifecycleListener();
			server.addLifecycleListener(listener);

			/*tomcat.addUser("adminuser", "adminuser");
			tomcat.addRole("adminuser", "admin");
			tomcat.addRole("adminuser", "admin");*/
			
			this.tomcat = tomcat;
		} catch (Exception e) {
			throw new RuntimeException("web server initialize error , check it. " + e.getMessage(), e);
		}
		
		/*Runtime.getRuntime().addShutdownHook(new Thread(){

			@Override
			public void run() {
				appBaseFile.delete();
			}
			
		});*/
	}