private static void setConnectorAttribute(Connector c, String key, @Nullable Object value) { if (value != null) { c.setAttribute(key, value); } } }
public static void main(String[] args) throws Exception { String webappsPath = args[0]; int port = Integer.parseInt( args[1] ); File dataDir = Files.createTempDir(); dataDir.deleteOnExit(); Tomcat tomcat = new Tomcat(); tomcat.setBaseDir(dataDir.getAbsolutePath()); tomcat.setPort(port); tomcat.getConnector().setAttribute("maxThreads", "1000"); tomcat.addWebapp("/", new File(webappsPath).getAbsolutePath()); logger.info("-----------------------------------------------------------------"); logger.info("Starting Tomcat port {} dir {}", port, webappsPath); logger.info("-----------------------------------------------------------------"); tomcat.start(); while ( true ) { Thread.sleep(1000); } }
connector.setSecure(true); connector.setScheme("https"); connector.setAttribute("SSLEnabled", "true"); SSLHostConfig sslHostConfig = new SSLHostConfig(); SSLHostConfigCertificate cert = connector.setAttribute("maxThreads", 400); connector.setAttribute("acceptCount", 50); connector.setAttribute("maxKeepAliveRequests", 100); connector.setAttribute("socket.soReuseAddress", true); connector.setAttribute("disableUploadTimeout", false); connector.setAttribute("maxHttpHeaderSize", 65536); connector.setAttribute("compression", "on"); connector.setAttribute("compressableMimeType", "text/html,text/xml,text/plain,text/css,text/csv,application/json");
protected void customizeConnector(Connector connector) { int port = (getPort() >= 0) ? getPort() : 0; connector.setPort(port); if (StringUtils.hasText(this.getServerHeader())) { connector.setAttribute("server", this.getServerHeader()); } if (connector.getProtocolHandler() instanceof AbstractProtocol) { customizeProtocol((AbstractProtocol<?>) connector.getProtocolHandler()); } if (getUriEncoding() != null) { connector.setURIEncoding(getUriEncoding().name()); } // Don't bind to the socket prematurely if ApplicationContext is slow to start connector.setProperty("bindOnInit", "false"); if (getSsl() != null && getSsl().isEnabled()) { customizeSsl(connector); } TomcatConnectorCustomizer compression = new CompressionConnectorCustomizer( getCompression()); compression.customize(connector); for (TomcatConnectorCustomizer customizer : this.tomcatConnectorCustomizers) { customizer.customize(connector); } }
protected void customizeConnector(Connector connector) { int port = (getPort() >= 0) ? getPort() : 0; connector.setPort(port); if (StringUtils.hasText(this.getServerHeader())) { connector.setAttribute("server", this.getServerHeader()); } if (connector.getProtocolHandler() instanceof AbstractProtocol) { customizeProtocol((AbstractProtocol<?>) connector.getProtocolHandler()); } if (getUriEncoding() != null) { connector.setURIEncoding(getUriEncoding().name()); } // Don't bind to the socket prematurely if ApplicationContext is slow to start connector.setProperty("bindOnInit", "false"); if (getSsl() != null && getSsl().isEnabled()) { customizeSsl(connector); } TomcatConnectorCustomizer compression = new CompressionConnectorCustomizer( getCompression()); compression.customize(connector); for (TomcatConnectorCustomizer customizer : this.tomcatConnectorCustomizers) { customizer.customize(connector); } }
private void enableSSLConnector(Tomcat tomcat) { log.info("Using https protocol"); Connector connector = tomcat.getConnector(); connector.setPort(getSettings().getPort()); connector.setSecure(true); connector.setScheme("https"); connector.setAttribute("keyAlias", getSettings().getKeyAlias()); connector.setAttribute("keystorePass", getSettings().getKeystorePassword()); connector.setAttribute("keystoreType", getSettings().getKeyType()); connector.setAttribute("keystoreFile", getSettings().getKeystoreFile()); connector.setAttribute("clientAuth", getSettings().getClientAuth()); if (getSettings().getClientAuth()) { connector.setAttribute("truststoreFile", getSettings().getTruststoreFile()); connector.setAttribute("truststorePass", getSettings().getTruststorePassword()); } connector.setAttribute("protocol", "HTTP/1.1"); connector.setAttribute("sslProtocol", "TLS"); connector.setAttribute("maxThreads", getSettings().getMaxConnections()); connector.setAttribute("protocol", "org.apache.coyote.http11.Http11AprProtocol"); connector.setAttribute("SSLEnabled", true); }
/** * Sets the hostname/IP that this connector listens on. This is typically * most useful for machines with multiple network cards, but can be used * to limit a connector to only listen for connections from the local * machine (127.0.0.1). To listen on all available network interfaces, * specify an address of 0.0.0.0. */ public void setHost(String host) throws UnknownHostException { connector.setAttribute("address", host); }
/** * Sets the password used to access the keystore, and by default, used to * access the server private key inside the keystore. Not all connectors * support configuring different passwords for those two features; if so, * a separate PrivateKeyPassword should be defined in an * implementation-specific connector interface. */ public void setKeystorePassword(String password) { connector.setAttribute("keystorePass", password); }
/** * Gets the protocol used for secure communication. This should usually * be TLS, though some JVM implementations (particularly some of IBM's) * may not be compatible with popular browsers unless this is changed to * SSL. Don't change it if you're not having problems. */ public void setSecureProtocol(String protocol) { connector.setAttribute("sslProtocol", protocol); }
/** * Sets whether the TCP_NODELAY flag is set for the sockets used by this * connector. This usually enhances performance, so it should typically * be set. */ public void setTcpNoDelay(boolean enable) { connector.setAttribute("tcpNoDelay", new Boolean(enable)); }
/** * Gets the size of the buffer used to handle network data for this * connector. */ public void setBufferSizeBytes(int bytes) { connector.setAttribute("bufferSize", new Integer(bytes)); }
/** * Sets the amount of time the socket used by this connector will linger * after being closed. Use -1 to disable socket linger. */ public void setLingerMillis(int millis) { connector.setAttribute("connectionLinger", new Integer(millis)); }
/** * Sets the certificate algorithm used to access the keystore. This may * be different for different JVM vendors, but should not usually be * changed otherwise. */ public void setAlgorithm(String algorithm) { this.algorithm = algorithm; if ("default".equalsIgnoreCase(algorithm)) { algorithm = KeyManagerFactory.getDefaultAlgorithm(); } connector.setAttribute("algorithm", algorithm); }
@Persistent(manageable=false) public void setSslPassword(String sslPassword) { if (sslPassword != null && sslPassword.equals("")) sslPassword = null; connector.setAttribute("SSLPassword", sslPassword); }
@Persistent(manageable=false) public void setTruststoreType(String truststoreType) { if (truststoreType!= null && truststoreType.equals("")) truststoreType = null; connector.setAttribute("truststoreType", truststoreType); }
@Persistent(manageable=false) public void setServer(String server) { if (server.equals("")) server = null; connector.setAttribute("server", server); }
@Persistent(manageable=false) public void setKeyAlias(String keyAlias) { if (keyAlias.equals("")) keyAlias = null; connector.setAttribute("keyAlias", keyAlias); }
@Persistent(manageable=false) public void setTruststorePass(String truststorePass) { if (truststorePass!= null && truststorePass.equals("")) truststorePass = null; connector.setAttribute("truststorePass", truststorePass); }
@Persistent(manageable=false) public void setKeystoreType(String keystoreType) { if (keystoreType!= null && keystoreType.equals("")) keystoreType = null; connector.setAttribute("keystoreType", keystoreType); }
private Connector createAJPConnector() { final Connector ajpConnector = new Connector("AJP/1.3"); ajpConnector.setPort(ajpPort); ajpConnector.setAttribute("address", "127.0.0.1"); ajpConnector.setSecure(false); ajpConnector.setAllowTrace(false); ajpConnector.setScheme("http"); return ajpConnector; } }