private void configureSslClientAuth(AbstractHttp11JsseProtocol<?> protocol, Ssl ssl) { if (ssl.getClientAuth() == Ssl.ClientAuth.NEED) { protocol.setClientAuth(Boolean.TRUE.toString()); } else if (ssl.getClientAuth() == Ssl.ClientAuth.WANT) { protocol.setClientAuth("want"); } }
private void customize(AbstractHttp11Protocol<?> protocol) { Compression compression = this.compression; protocol.setCompression("on"); protocol.setCompressionMinSize(getMinResponseSize(compression)); protocol.setCompressibleMimeType(getMimeTypes(compression)); if (this.compression.getExcludedUserAgents() != null) { protocol.setNoCompressionUserAgents(getExcludedUserAgents()); } }
@Bean public TomcatEmbeddedServletContainerFactory tomcatEmbedded() { TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory(); tomcat.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> { if ((connector.getProtocolHandler() instanceof AbstractHttp11Protocol<?>)) { //-1 means unlimited ((AbstractHttp11Protocol<?>) connector.getProtocolHandler()).setMaxSwallowSize(-1); } }); return tomcat; }
public Http11NioProtocol() { cHandler = new Http11ConnectionHandler( this ); setSoLinger(Constants.DEFAULT_CONNECTION_LINGER); setSoTimeout(Constants.DEFAULT_CONNECTION_TIMEOUT); //setServerSoTimeout(Constants.DEFAULT_SERVER_SOCKET_TIMEOUT); setTcpNoDelay(Constants.DEFAULT_TCP_NO_DELAY); }
protocol.setSSLEnabled(true); protocol.setSslProtocol(ssl.getProtocol()); configureSslClientAuth(protocol, ssl); protocol.setKeystorePass(ssl.getKeyStorePassword()); protocol.setKeyPass(ssl.getKeyPassword()); protocol.setKeyAlias(ssl.getKeyAlias()); String ciphers = StringUtils.arrayToCommaDelimitedString(ssl.getCiphers()); if (StringUtils.hasText(ciphers)) { protocol.setCiphers(ciphers); for (SSLHostConfig sslHostConfig : protocol.findSslHostConfigs()) { sslHostConfig.setProtocols(StringUtils .arrayToCommaDelimitedString(ssl.getEnabledProtocols()));
private void configureSslTrustStore(AbstractHttp11JsseProtocol<?> protocol, Ssl ssl) { if (ssl.getTrustStore() != null) { try { protocol.setTruststoreFile( ResourceUtils.getURL(ssl.getTrustStore()).toString()); } catch (FileNotFoundException ex) { throw new WebServerException( "Could not load trust store: " + ex.getMessage(), ex); } } protocol.setTruststorePass(ssl.getTrustStorePassword()); if (ssl.getTrustStoreType() != null) { protocol.setTruststoreType(ssl.getTrustStoreType()); } if (ssl.getTrustStoreProvider() != null) { protocol.setTruststoreProvider(ssl.getTrustStoreProvider()); } }
protected void configureSslStoreProvider(AbstractHttp11JsseProtocol<?> protocol, SslStoreProvider sslStoreProvider) { Assert.isInstanceOf(Http11NioProtocol.class, protocol, "SslStoreProvider can only be used with Http11NioProtocol"); TomcatURLStreamHandlerFactory instance = TomcatURLStreamHandlerFactory .getInstance(); instance.addUserFactory( new SslStoreProviderUrlStreamHandlerFactory(sslStoreProvider)); try { if (sslStoreProvider.getKeyStore() != null) { protocol.setKeystorePass(""); protocol.setKeystoreFile( SslStoreProviderUrlStreamHandlerFactory.KEY_STORE_URL); } if (sslStoreProvider.getTrustStore() != null) { protocol.setTruststorePass(""); protocol.setTruststoreFile( SslStoreProviderUrlStreamHandlerFactory.TRUST_STORE_URL); } } catch (Exception ex) { throw new WebServerException("Could not load store: " + ex.getMessage(), ex); } }
@Bean public EmbeddedServletContainerCustomizer servletContainerCustomizer() { return new EmbeddedServletContainerCustomizer() { @Override public void customize(ConfigurableEmbeddedServletContainer servletContainer) { ((TomcatEmbeddedServletContainerFactory) servletContainer).addConnectorCustomizers( new TomcatConnectorCustomizer() { @Override public void customize(Connector connector) { AbstractHttp11Protocol httpProtocol = (AbstractHttp11Protocol) connector.getProtocolHandler(); httpProtocol.setCompression("on"); httpProtocol.setCompressionMinSize(256); String mimeTypes = httpProtocol.getCompressableMimeTypes(); String mimeTypesWithJson = mimeTypes + "," + MediaType.APPLICATION_JSON_VALUE; httpProtocol.setCompressableMimeTypes(mimeTypesWithJson); } } ); } }; }
private void configureSslKeyStore(AbstractHttp11JsseProtocol<?> protocol, Ssl ssl) { try { protocol.setKeystoreFile(ResourceUtils.getURL(ssl.getKeyStore()).toString()); } catch (FileNotFoundException ex) { throw new WebServerException("Could not load key store: " + ex.getMessage(), ex); } if (ssl.getKeyStoreType() != null) { protocol.setKeystoreType(ssl.getKeyStoreType()); } if (ssl.getKeyStoreProvider() != null) { protocol.setKeystoreProvider(ssl.getKeyStoreProvider()); } }
@Override public void start() throws Exception { super.start(); if (npnHandler != null) { npnHandler.init(getEndpoint(), 0, getAdapter()); } }
@Override public long getBytesWritten() { if (lastActiveFilter == -1) { return outputStreamOutputBuffer.getBytesWritten(); } else { return activeFilters[lastActiveFilter].getBytesWritten(); } }
/** * Set the socket buffer flag. */ @Override public void setSocketBuffer(int socketBuffer) { super.setSocketBuffer(socketBuffer); outputBuffer.setSocketBuffer(socketBuffer); } }
@Override public void start() throws Exception { super.start(); if (npnHandler != null) { npnHandler.init(endpoint, 0, getAdapter()); } }
/** * Instantiates a new SSL host config helper. * * @param protocol the protocol * @param info the info * @throws IllegalAccessException the illegal access exception * @throws InvocationTargetException the invocation target exception */ public SslHostConfigHelper(AbstractHttp11JsseProtocol<?> protocol, ConnectorInfo info) throws IllegalAccessException, InvocationTargetException { SSLHostConfig[] sslHostConfigs = protocol.findSslHostConfigs(); List<SslHostConfigInfo> sslHostConfigInfos = new ArrayList<>(sslHostConfigs.length); info.setSslHostConfigInfos(sslHostConfigInfos); for (SSLHostConfig sslHostConfig : sslHostConfigs) { sslHostConfigInfos.add(toSslHostConfigInfo(sslHostConfig)); } }
/** * * @param channel */ private void setChannel(NioChannel channel) { // Setting up the channel this.channel = channel; this.inputBuffer.setChannel(channel); this.outputBuffer.setChannel(channel); }
/** * Gets the connector infos. * * @param connectors the connectors * @return the connector infos * @throws IllegalAccessException the illegal access exception * @throws InvocationTargetException the invocation target exception */ private List<ConnectorInfo> getConnectorInfos(List<Connector> connectors) throws IllegalAccessException, InvocationTargetException { List<ConnectorInfo> infos = new ArrayList<>(); for (Connector connector : connectors) { if (!connector.getSecure()) { continue; } ProtocolHandler protocolHandler = connector.getProtocolHandler(); if (protocolHandler instanceof AbstractHttp11JsseProtocol) { AbstractHttp11JsseProtocol<?> protocol = (AbstractHttp11JsseProtocol<?>) protocolHandler; if (!protocol.getSecure()) { continue; } infos.add(toConnectorInfo(protocol)); } } return infos; }
throws IllegalAccessException, InvocationTargetException { ConnectorInfo info = new ConnectorInfo(); info.setName(ObjectName.unquote(protocol.getName()));