use of org.apache.coyote.http2.Http2Protocol in project cas by apereo.
the class CasTomcatServletWebServerFactoryCustomizer method configureHttp.
private void configureHttp(final TomcatServletWebServerFactory tomcat) {
val http = casProperties.getServer().getTomcat().getHttp();
if (http.isEnabled()) {
LOGGER.debug("Creating HTTP configuration for the embedded tomcat container...");
val connector = new Connector(http.getProtocol());
var port = http.getPort();
if (port <= 0) {
LOGGER.warn("No explicit port configuration is provided to CAS. Scanning for available ports...");
port = SocketUtils.findAvailableTcpPort();
}
LOGGER.info("Activated embedded tomcat container HTTP port on [{}]", port);
connector.setPort(port);
if (http.getRedirectPort() > 0) {
connector.setRedirectPort(http.getRedirectPort());
}
connector.setScheme("http");
LOGGER.debug("Configuring embedded tomcat container for HTTP2 protocol support");
connector.addUpgradeProtocol(new Http2Protocol());
http.getAttributes().forEach(connector::setProperty);
tomcat.addAdditionalTomcatConnectors(connector);
}
}
use of org.apache.coyote.http2.Http2Protocol in project cas by apereo.
the class CasTomcatServletWebServerFactoryCustomizer method configureConnectorForProtocol.
private static void configureConnectorForProtocol(final Connector connector, final CasEmbeddedApacheTomcatHttpProxyProperties proxy) {
val handler = ReflectionUtils.findField(connector.getClass(), "protocolHandler");
if (handler != null) {
ReflectionUtils.makeAccessible(handler);
if ("HTTP/2".equalsIgnoreCase(proxy.getProtocol())) {
connector.addUpgradeProtocol(new Http2Protocol());
} else {
var protocolHandlerInstance = (AbstractProtocol) null;
switch(proxy.getProtocol()) {
case "AJP/2":
protocolHandlerInstance = new AjpNio2Protocol();
val ajp1 = AbstractAjpProtocol.class.cast(protocolHandlerInstance);
ajp1.setSecretRequired(proxy.isSecure());
ajp1.setSecret(proxy.getSecret());
break;
case "AJP/1.3":
protocolHandlerInstance = new AjpNioProtocol();
val ajp2 = AbstractAjpProtocol.class.cast(protocolHandlerInstance);
ajp2.setSecretRequired(proxy.isSecure());
ajp2.setSecret(proxy.getSecret());
break;
case "APR":
protocolHandlerInstance = new Http11AprProtocol();
break;
case "HTTP/1.2":
protocolHandlerInstance = new Http11Nio2Protocol();
break;
case "HTTP/1.1":
default:
protocolHandlerInstance = new Http11NioProtocol();
break;
}
protocolHandlerInstance.setPort(connector.getPort());
ReflectionUtils.setField(handler, connector, protocolHandlerInstance);
}
val handlerClass = ReflectionUtils.findField(connector.getClass(), "protocolHandlerClassName");
if (handlerClass != null) {
ReflectionUtils.makeAccessible(handlerClass);
ReflectionUtils.setField(handlerClass, connector, connector.getProtocolHandler().getClass().getName());
}
}
}
use of org.apache.coyote.http2.Http2Protocol in project cas by apereo.
the class CasTomcatServletWebServerFactoryCustomizer method configureAjp.
private void configureAjp(final TomcatServletWebServerFactory tomcat) {
val ajp = casProperties.getServer().getTomcat().getAjp();
if (ajp.isEnabled() && ajp.getPort() > 0) {
LOGGER.debug("Creating AJP configuration for the embedded tomcat container...");
val ajpConnector = new Connector(ajp.getProtocol());
ajpConnector.setPort(ajp.getPort());
ajpConnector.setSecure(ajp.isSecure());
ajpConnector.setAllowTrace(ajp.isAllowTrace());
ajpConnector.setScheme(ajp.getScheme());
ajpConnector.setAsyncTimeout(Beans.newDuration(ajp.getAsyncTimeout()).toMillis());
ajpConnector.setEnableLookups(ajp.isEnableLookups());
ajpConnector.setMaxPostSize(ajp.getMaxPostSize());
ajpConnector.addUpgradeProtocol(new Http2Protocol());
val handler = (AbstractAjpProtocol) ajpConnector.getProtocolHandler();
if (handler != null) {
handler.setSecretRequired(ajp.isSecure());
handler.setSecret(ajp.getSecret());
}
if (ajp.getProxyPort() > 0) {
LOGGER.debug("Set AJP proxy port to [{}]", ajp.getProxyPort());
ajpConnector.setProxyPort(ajp.getProxyPort());
}
if (ajp.getRedirectPort() > 0) {
LOGGER.debug("Set AJP redirect port to [{}]", ajp.getRedirectPort());
ajpConnector.setRedirectPort(ajp.getRedirectPort());
}
ajp.getAttributes().forEach(ajpConnector::setProperty);
tomcat.addAdditionalTomcatConnectors(ajpConnector);
}
}
use of org.apache.coyote.http2.Http2Protocol in project cas by apereo.
the class CasEmbeddedContainerTomcatConfiguration method configureHttpProxy.
private void configureHttpProxy(final TomcatEmbeddedServletContainerFactory tomcat) {
final CasEmbeddedApacheTomcatHttpProxyProperties proxy = casProperties.getServer().getHttpProxy();
if (proxy.isEnabled()) {
LOGGER.debug("Customizing HTTP proxying for connector listening on port [{}]", tomcat.getPort());
tomcat.getTomcatConnectorCustomizers().add(connector -> {
connector.setSecure(proxy.isSecure());
connector.setScheme(proxy.getScheme());
if (StringUtils.isNotBlank(proxy.getProtocol())) {
LOGGER.debug("Setting HTTP proxying protocol to [{}]", proxy.getProtocol());
connector.setProtocol(proxy.getProtocol());
}
if (proxy.getRedirectPort() > 0) {
LOGGER.debug("Setting HTTP proxying redirect port to [{}]", proxy.getRedirectPort());
connector.setRedirectPort(proxy.getRedirectPort());
}
if (proxy.getProxyPort() > 0) {
LOGGER.debug("Setting HTTP proxying proxy port to [{}]", proxy.getProxyPort());
connector.setProxyPort(proxy.getProxyPort());
}
connector.addUpgradeProtocol(new Http2Protocol());
proxy.getAttributes().forEach(connector::setAttribute);
LOGGER.info("Configured connector listening on port [{}]", tomcat.getPort());
});
} else {
LOGGER.debug("HTTP proxying is not enabled for CAS; Connector configuration for port [{}] is not modified.", tomcat.getPort());
}
}
use of org.apache.coyote.http2.Http2Protocol in project cas by apereo.
the class CasTomcatServletWebServerFactoryCustomizer method configureHttpProxy.
private void configureHttpProxy(final TomcatServletWebServerFactory tomcat) {
val proxy = casProperties.getServer().getTomcat().getHttpProxy();
if (proxy.isEnabled()) {
LOGGER.debug("Customizing HTTP proxying for connector listening on port [{}]", tomcat.getPort());
tomcat.getTomcatConnectorCustomizers().add(connector -> {
connector.setSecure(proxy.isSecure());
connector.setScheme(proxy.getScheme());
if (StringUtils.isNotBlank(proxy.getProtocol())) {
LOGGER.debug("Setting HTTP proxying protocol to [{}]", proxy.getProtocol());
configureConnectorForProtocol(connector, proxy);
}
if (proxy.getRedirectPort() > 0) {
LOGGER.debug("Setting HTTP proxying redirect port to [{}]", proxy.getRedirectPort());
connector.setRedirectPort(proxy.getRedirectPort());
}
if (proxy.getProxyPort() > 0) {
LOGGER.debug("Setting HTTP proxying proxy port to [{}]", proxy.getProxyPort());
connector.setProxyPort(proxy.getProxyPort());
}
connector.addUpgradeProtocol(new Http2Protocol());
proxy.getAttributes().forEach(connector::setProperty);
LOGGER.info("Configured connector listening on port [{}]", tomcat.getPort());
});
} else {
LOGGER.trace("HTTP proxying is not enabled for CAS; Connector configuration for port [{}] is not modified.", tomcat.getPort());
}
}
Aggregations