// Needs to be protected so it can be used by subclasses 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()); } // If ApplicationContext is slow to start we want Tomcat not to bind to the socket // prematurely... connector.setProperty("bindOnInit", "false"); if (getSsl() != null && getSsl().isEnabled()) { customizeSsl(connector); } if (getCompression() != null && getCompression().getEnabled()) { customizeCompression(connector); } for (TomcatConnectorCustomizer customizer : this.tomcatConnectorCustomizers) { customizer.customize(connector); } }
private void customizeConnectionTimeout( TomcatEmbeddedServletContainerFactory factory, int connectionTimeout) { for (Connector connector : factory.getAdditionalTomcatConnectors()) { if (connector.getProtocolHandler() instanceof AbstractProtocol) { AbstractProtocol<?> handler = (AbstractProtocol<?>) connector.getProtocolHandler(); handler.setConnectionTimeout(connectionTimeout); } } }
public void _setExecutor(Connector con, Executor ex) throws Exception { Method m = IntrospectionUtils.findMethod( con.getProtocolHandler().getClass(), "setExecutor", new Class[] {java.util.concurrent.Executor.class}); if (m != null) { m.invoke(con.getProtocolHandler(), new Object[] {ex}); } else { log.warn( "Connector [" + con + "] does not support external executors. Method setExecutor(java.util.concurrent.Executor) not found."); } }
private void stopProtocolHandler(Connector connector) { try { connector.getProtocolHandler().stop(); } catch (Exception ex) { this.logger.error("Cannot pause connector: ", ex); } }
private void customizeSsl(Connector connector) { ProtocolHandler handler = connector.getProtocolHandler(); Assert.state( handler instanceof AbstractHttp11JsseProtocol, "To use SSL, the connector's protocol handler must be an " + "AbstractHttp11JsseProtocol subclass"); configureSsl((AbstractHttp11JsseProtocol<?>) handler, getSsl()); connector.setScheme("https"); connector.setSecure(true); }
// Needs to be protected so it can be used by subclasses protected void customizeConnector(Connector connector) { int port = (getPort() >= 0 ? getPort() : 0); connector.setPort(port); if (connector.getProtocolHandler() instanceof AbstractProtocol) { if (getAddress() != null) { ((AbstractProtocol) connector.getProtocolHandler()).setAddress(getAddress()); } } if (getUriEncoding() != null) { connector.setURIEncoding(getUriEncoding()); } // If ApplicationContext is slow to start we want Tomcat not to bind to the socket // prematurely... connector.setProperty("bindOnInit", "false"); for (TomcatConnectorCustomizer customizer : this.tomcatConnectorCustomizers) { customizer.customize(connector); } }
/** * Return the address. * * @return An address string */ public String getAddress() { String hostAddress = null; Connector connector = ServerUtil.getDefaultConnector(); if (connector.getProtocolHandler() instanceof Http11Protocol) { Http11Protocol protocol = (Http11Protocol) connector.getProtocolHandler(); InetAddress address = protocol.getAddress(); hostAddress = address.getHostAddress(); } else { _log.warn( "Unable to determine host address from connector. Using alias definition instead."); hostAddress = ServerUtil.getDefaultHost().getHost().findAliases()[0]; } return connector.getScheme() + "://" + hostAddress + ":" + connector.getPort() + "/" + _contextName; }
private void customizeCompression(Connector connector) { ProtocolHandler handler = connector.getProtocolHandler(); if (handler instanceof AbstractHttp11Protocol) { AbstractHttp11Protocol<?> protocol = (AbstractHttp11Protocol<?>) handler; Compression compression = getCompression(); protocol.setCompression("on"); protocol.setCompressionMinSize(compression.getMinResponseSize()); protocol.setCompressableMimeTypes( StringUtils.arrayToCommaDelimitedString(compression.getMimeTypes())); if (getCompression().getExcludedUserAgents() != null) { protocol.setNoCompressionUserAgents( StringUtils.arrayToCommaDelimitedString(getCompression().getExcludedUserAgents())); } } }
/** * Start, register and bind the web connector. * * @param context the start context * @throws StartException if the connector cannot be started */ public synchronized void start(StartContext context) throws StartException { final SocketBinding binding = this.binding.getValue(); final InetSocketAddress address = binding.getSocketAddress(); final Executor executor = this.executor.getOptionalValue(); try { // Create connector final Connector connector = new Connector(protocol); connector.setPort(address.getPort()); connector.setScheme(scheme); if (enableLookups != null) connector.setEnableLookups(enableLookups); if (maxPostSize != null) connector.setMaxPostSize(maxPostSize); if (maxSavePostSize != null) connector.setMaxSavePostSize(maxSavePostSize); if (proxyName != null) connector.setProxyName(proxyName); if (proxyPort != null) connector.setProxyPort(proxyPort); if (redirectPort != null) connector.setRedirectPort(redirectPort); if (secure != null) connector.setSecure(secure); if (executor != null) { Method m = connector.getProtocolHandler().getClass().getMethod("setExecutor", Executor.class); m.invoke(connector.getProtocolHandler(), executor); } if (address != null && address.getAddress() != null) { Method m = connector.getProtocolHandler().getClass().getMethod("setAddress", InetAddress.class); m.invoke(connector.getProtocolHandler(), address.getAddress()); } if (maxConnections != null) { try { Method m = connector.getProtocolHandler().getClass().getMethod("setPollerSize", Integer.TYPE); m.invoke(connector.getProtocolHandler(), maxConnections); } catch (NoSuchMethodException e) { // Not all connectors will have this } try { Method m = connector.getProtocolHandler().getClass().getMethod("setSendfileSize", Integer.TYPE); m.invoke(connector.getProtocolHandler(), maxConnections); } catch (NoSuchMethodException e) { // Not all connectors will have this } } if (virtualServers != null) { HashSet<String> virtualServersList = new HashSet<String>(); for (final ModelNode virtualServer : virtualServers.asList()) { virtualServersList.add(virtualServer.asString()); } connector.setAllowedHosts(virtualServersList); } if (ssl != null) { boolean nativeSSL = false; if (connector.getProtocolHandler() instanceof Http11AprProtocol) { nativeSSL = true; } else if (!(connector.getProtocolHandler() instanceof Http11Protocol)) { throw new StartException("Non HTTP connectors dor not support SSL"); } // Enable SSL try { Method m = connector.getProtocolHandler().getClass().getMethod("setSSLEnabled", Boolean.TYPE); m.invoke(connector.getProtocolHandler(), true); } catch (NoSuchMethodException e) { // No SSL support throw new StartException(e); } if (nativeSSL) { // OpenSSL configuration try { if (ssl.hasDefined(Constants.PASSWORD)) { Method m = connector .getProtocolHandler() .getClass() .getMethod("setSSLPassword", String.class); m.invoke(connector.getProtocolHandler(), ssl.get(Constants.PASSWORD).asString()); } if (ssl.hasDefined(Constants.CERTIFICATE_KEY_FILE)) { Method m = connector .getProtocolHandler() .getClass() .getMethod("setSSLCertificateKeyFile", String.class); m.invoke( connector.getProtocolHandler(), ssl.get(Constants.CERTIFICATE_KEY_FILE).asString()); } if (ssl.hasDefined(Constants.CIPHER_SUITE)) { Method m = connector .getProtocolHandler() .getClass() .getMethod("setSSLCipherSuite", String.class); m.invoke(connector.getProtocolHandler(), ssl.get(Constants.CIPHER_SUITE).asString()); } if (ssl.hasDefined(Constants.PROTOCOL)) { Method m = connector .getProtocolHandler() .getClass() .getMethod("setSSLProtocol", String.class); m.invoke(connector.getProtocolHandler(), ssl.get(Constants.PROTOCOL).asString()); } if (ssl.hasDefined(Constants.VERIFY_CLIENT)) { Method m = connector .getProtocolHandler() .getClass() .getMethod("setSSLVerifyClient", String.class); m.invoke(connector.getProtocolHandler(), ssl.get(Constants.VERIFY_CLIENT).asString()); } if (ssl.hasDefined(Constants.VERIFY_DEPTH)) { Method m = connector .getProtocolHandler() .getClass() .getMethod("setSSLVerifyDepth", Integer.TYPE); m.invoke(connector.getProtocolHandler(), ssl.get(Constants.VERIFY_DEPTH).asInt()); } if (ssl.hasDefined(Constants.CERTIFICATE_FILE)) { Method m = connector .getProtocolHandler() .getClass() .getMethod("setSSLCertificateFile", String.class); m.invoke( connector.getProtocolHandler(), ssl.get(Constants.CERTIFICATE_FILE).asString()); } if (ssl.hasDefined(Constants.CA_CERTIFICATE_FILE)) { Method m = connector .getProtocolHandler() .getClass() .getMethod("setSSLCACertificateFile", String.class); m.invoke( connector.getProtocolHandler(), ssl.get(Constants.CA_CERTIFICATE_FILE).asString()); } if (ssl.hasDefined(Constants.CA_REVOCATION_URL)) { Method m = connector .getProtocolHandler() .getClass() .getMethod("setSSLCARevocationFile", String.class); m.invoke( connector.getProtocolHandler(), ssl.get(Constants.CA_REVOCATION_URL).asString()); } } catch (NoSuchMethodException e) { throw new StartException(e); } } else { // JSSE configuration try { if (ssl.hasDefined(Constants.KEY_ALIAS)) { Method m = connector.getProtocolHandler().getClass().getMethod("setKeyAlias", String.class); m.invoke(connector.getProtocolHandler(), ssl.get(Constants.KEY_ALIAS).asString()); } if (ssl.hasDefined(Constants.PASSWORD)) { Method m = connector.getProtocolHandler().getClass().getMethod("setKeypass", String.class); m.invoke(connector.getProtocolHandler(), ssl.get(Constants.PASSWORD).asString()); } if (ssl.hasDefined(Constants.CERTIFICATE_KEY_FILE)) { Method m = connector.getProtocolHandler().getClass().getMethod("setKeystore", String.class); m.invoke( connector.getProtocolHandler(), ssl.get(Constants.CERTIFICATE_KEY_FILE).asString()); } if (ssl.hasDefined(Constants.CIPHER_SUITE)) { Method m = connector.getProtocolHandler().getClass().getMethod("setCiphers", String.class); m.invoke(connector.getProtocolHandler(), ssl.get(Constants.CIPHER_SUITE).asString()); } if (ssl.hasDefined(Constants.PROTOCOL)) { Method m = connector.getProtocolHandler().getClass().getMethod("setProtocols", String.class); m.invoke(connector.getProtocolHandler(), ssl.get(Constants.PROTOCOL).asString()); } if (ssl.hasDefined(Constants.VERIFY_CLIENT)) { Method m = connector .getProtocolHandler() .getClass() .getMethod("setClientauth", String.class); m.invoke(connector.getProtocolHandler(), ssl.get(Constants.VERIFY_CLIENT).asString()); } if (ssl.hasDefined(Constants.SESSION_CACHE_SIZE)) { Method m = connector .getProtocolHandler() .getClass() .getMethod("setAttribute", String.class, Object.class); m.invoke( connector.getProtocolHandler(), "sessionCacheSize", ssl.get(Constants.SESSION_CACHE_SIZE).asString()); } if (ssl.hasDefined(Constants.SESSION_TIMEOUT)) { Method m = connector .getProtocolHandler() .getClass() .getMethod("setAttribute", String.class, Object.class); m.invoke( connector.getProtocolHandler(), "sessionCacheTimeout", ssl.get(Constants.SESSION_TIMEOUT).asString()); } } catch (NoSuchMethodException e) { throw new StartException(e); } } } getWebServer().addConnector(connector); this.connector = connector; } catch (Exception e) { throw new StartException(e); } // Register the binding after the connector is started binding.getSocketBindings().getNamedRegistry().registerBinding(new ConnectorBinding(binding)); }
/** {@inheritDoc} */ public synchronized void removeConnector(Connector connector) { if (connector.getProtocolHandler() instanceof SipProtocolHandler) { final StandardService service = this.sipService; service.removeConnector(connector); } }