Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Oct 4, 2019
2 parents ccf4caa + 2eba48d commit 956a195
Showing 1 changed file with 36 additions and 6 deletions.
Expand Up @@ -12,6 +12,7 @@
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import org.apache.catalina.Context;
import org.apache.catalina.Manager;
import org.apache.catalina.Valve;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -31,10 +32,15 @@
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.boot.web.servlet.server.Session;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.Profile;
import org.springframework.http.HttpStatus;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
import org.springframework.stereotype.Component;

import java.lang.management.ManagementFactory;
Expand Down Expand Up @@ -73,11 +79,13 @@
@Profile("!test")
@SpringBootConfiguration
@ComponentScan(basePackages = {"com.evolveum.midpoint.gui","com.evolveum.midpoint.gui.api"}, basePackageClasses = {TextAreaPanelFactory.class, GuiComponentRegistryImpl.class})
@EnableScheduling
public class MidPointSpringApplication extends AbstractSpringBootApplication {

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

private static ConfigurableApplicationContext applicationContext = null;
private Context tomcatContext;

public static void main(String[] args) {
System.out.println("ClassPath: "+ System.getProperty("java.class.path"));
Expand Down Expand Up @@ -137,15 +145,37 @@ private static SpringApplicationBuilder configureApplication(SpringApplicationBu

return application.sources(MidPointSpringApplication.class);
}

private void setTomcatContext(Context context) {
this.tomcatContext = context;
}

@Bean
public TaskScheduler taskScheduler() {
return new ConcurrentTaskScheduler();
}

@Scheduled(fixedDelayString = "${server.tomcat.session-manager-delay:10000}", initialDelayString = "${server.tomcat.session-manager-delay:10000}")
public void invalidExpiredSessions() {
Context context = this.tomcatContext;
if (context != null) {
Manager manager = context.getManager();
if (manager != null) {
try {
manager.backgroundProcess();
} catch (Exception e) {
LOGGER.error("Couldn't execute backgroundProcess on session manager.", e);
}
}
}
}

@Component
@EnableConfigurationProperties(ServerProperties.class)
public class ServerCustomization implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {

@Value("${server.servlet.session.timeout}")
private int sessionTimeout;
@Value("${server.tomcat.background-processor-delay:10}")
private int backgroundProcessorDelay;
@Value("${server.servlet.context-path}")
private String servletPath;

Expand All @@ -172,19 +202,19 @@ public void customize(ConfigurableServletWebServerFactory serverFactory) {
customizeTomcat((TomcatServletWebServerFactory) serverFactory);
}
}

private void customizeTomcat(TomcatServletWebServerFactory tomcatFactory) {
// Set background-processor-delay property.
// set tomcat context.
TomcatContextCustomizer contextCustomizer = new TomcatContextCustomizer() {
@Override
public void customize(Context context) {
context.setBackgroundProcessorDelay(backgroundProcessorDelay);
setTomcatContext(context);
}
};
List<TomcatContextCustomizer> contextCustomizers = new ArrayList<TomcatContextCustomizer>();
contextCustomizers.add(contextCustomizer);
tomcatFactory.setTomcatContextCustomizers(contextCustomizers);

// Tomcat valve used to redirect root URL (/) to real application URL (/midpoint/).
// See comments in TomcatRootValve
Valve rootValve = new TomcatRootValve(servletPath);
Expand Down

0 comments on commit 956a195

Please sign in to comment.