Skip to content

Commit

Permalink
MID-7573: added support for AJP address and jvmRoute
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed Jan 25, 2022
1 parent 6f37faa commit f6f0574
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/*
* Copyright (c) 2018 Evolveum and contributors
* Copyright (C) 2018-2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.web.boot;

import java.net.InetAddress;
import java.net.UnknownHostException;
import javax.servlet.Servlet;

import com.evolveum.midpoint.model.common.SystemObjectCache;

import com.google.common.base.Strings;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.startup.Tomcat;
import org.apache.coyote.UpgradeProtocol;
Expand All @@ -29,8 +30,7 @@
import org.springframework.context.annotation.Profile;
import org.springframework.core.Ordered;

import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.model.common.SystemObjectCache;

/**
* Custom configuration (factory) for embedded tomcat factory.
Expand All @@ -45,8 +45,6 @@
@Import(BeanPostProcessorsRegistrar.class)
public class EmbeddedTomcatAutoConfiguration {

private static final Trace LOGGER = TraceManager.getTrace(EmbeddedTomcatAutoConfiguration.class);

@Profile("!test")
@Configuration
@ConditionalOnClass({ Servlet.class, Tomcat.class, UpgradeProtocol.class })
Expand All @@ -59,6 +57,12 @@ public static class EmbeddedTomcat {
@Value("${server.tomcat.ajp.port:9090}")
private int port;

@Value("${server.tomcat.ajp.address:}")
private String address;

@Value("${server.tomcat.ajp.jvmRoute:}")
private String jvmRoute;

@Value("${server.tomcat.ajp.secret:}")
private String secret;

Expand All @@ -69,22 +73,26 @@ public static class EmbeddedTomcat {
private SystemObjectCache systemObjectCache;

@Bean
public TomcatServletWebServerFactory tomcatEmbeddedServletContainerFactory() {
public TomcatServletWebServerFactory tomcatEmbeddedServletContainerFactory() throws UnknownHostException {
MidPointTomcatServletWebServerFactory tomcat = new MidPointTomcatServletWebServerFactory(contextPath, systemObjectCache);

if (enableAjp) {
Connector ajpConnector = new Connector("AJP/1.3");
AjpNioProtocol protocol = (AjpNioProtocol) ajpConnector.getProtocolHandler();
protocol.setSecret(secret);
if (!Strings.isNullOrEmpty(address)) {
protocol.setAddress(InetAddress.getByName(address));
}
ajpConnector.setPort(port);
ajpConnector.setSecure(false);
ajpConnector.setScheme("http");
ajpConnector.setAllowTrace(false);

tomcat.addAdditionalTomcatConnectors(ajpConnector);
tomcat.setJvmRoute(jvmRoute); // will be set on Engine there
}

return tomcat;
}

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2020 Evolveum and contributors
* Copyright (C) 2018-2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand All @@ -8,6 +8,7 @@

import java.io.File;

import com.google.common.base.Strings;
import org.apache.catalina.Context;
import org.apache.catalina.Engine;
import org.apache.catalina.Valve;
Expand Down Expand Up @@ -41,13 +42,14 @@ public class MidPointTomcatServletWebServerFactory extends TomcatServletWebServe

private final SystemObjectCache systemObjectCache;

private String jvmRoute;

public MidPointTomcatServletWebServerFactory(String contextPath, SystemObjectCache systemObjectCache) {
this.contextPath = contextPath;
this.systemObjectCache = systemObjectCache;
}

@Override

protected TomcatWebServer getTomcatWebServer(Tomcat tomcat) {

// We are setting up fake context here. This context does not really do anything.
Expand Down Expand Up @@ -100,7 +102,11 @@ public Response createResponse() {
customizeConnector(connector);
tomcat.setConnector(connector);
tomcat.getHost().setAutoDeploy(false);
configureEngine(tomcat.getEngine());
Engine engine = tomcat.getEngine();
if (!Strings.isNullOrEmpty(jvmRoute)) {
engine.setJvmRoute(jvmRoute);
}
configureEngine(engine);
for (Connector additionalConnector : getAdditionalTomcatConnectors()) {
tomcat.getService().addConnector(additionalConnector);
}
Expand All @@ -119,4 +125,8 @@ private void configureEngine(Engine engine) {
protected void postProcessContext(Context context) {
context.setResources(new ExtractingRoot());
}

public void setJvmRoute(String jvmRoute) {
this.jvmRoute = jvmRoute;
}
}

0 comments on commit f6f0574

Please sign in to comment.