Skip to content

Commit

Permalink
DOCKER-450
Browse files Browse the repository at this point in the history
  * [Update] JSON-logging V0.0.8
  * [Update] Changelog
  • Loading branch information
codingBenVdS committed May 24, 2024
1 parent b8bb035 commit d0c815c
Show file tree
Hide file tree
Showing 7 changed files with 312 additions and 14 deletions.
1 change: 0 additions & 1 deletion 2share/23.1/community-23.1.0/overload.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ ext {

dependencies {
baseShareWar 'org.alfresco:share:23.1.1.2@war'
// baseShareWar 'org.alfresco:share:23.2.0.72@war'
}

2 changes: 1 addition & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
* [PR #110](https://github.com/xenit-eu/docker-alfresco/pull/110) XM2C-81 fix alfresco environment and default system properties

### Added

* [PR #208](https://xenitsupport.jira.com/browse/DOCKER-450) DOCKER-450 Add Alfresco V23.1 & V23.2 support
* [PR #98](https://github.com/xenit-eu/docker-alfresco/pull/98) XM2C-43 Merge docker-share into docker-alfresco
* [PR #88](https://github.com/xenit-eu/docker-alfresco/pull/88) DOCKER-415 Add a healthcheck for Alfresco
* [PR #86](https://github.com/xenit-eu/docker-alfresco/pull/86) DOCKER-414 Fix alf_data content store permissions
Expand Down
12 changes: 3 additions & 9 deletions tomcat-base/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ subprojects {
apply plugin: 'eu.xenit.docker'
apply plugin: 'java'
apply plugin: "maven-publish"

apply from: "${rootProject.projectDir}/jacoco.gradle"

if (new File("${project.projectDir}/overload.gradle").exists()) {
Expand All @@ -23,20 +22,14 @@ subprojects {
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
// Caused by: java.lang.UnsupportedClassVersionError: org/springframework/web/SpringServletContainerInitializer has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0 (unable to load class [org.springframework.web.SpringServletContainerInitializer])\
if (tomcatVersion.contains("10")){
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}
ext {
jsonLoggingVersion = '0.0.7'
jsonLoggingVersion = '0.0.8'
}
dependencies {

compileOnly "org.projectlombok:lombok:1.18.32"
annotationProcessor "org.projectlombok:lombok:1.18.32"

implementation "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}"
implementation "org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}"
implementation "org.apache.tomcat:tomcat-jasper:${tomcatVersion}"
Expand Down Expand Up @@ -67,6 +60,7 @@ subprojects {
main {
java {
srcDir file("$project.parent.projectDir/src/shared/main/java")
srcDir file("$project.projectDir/src/shared/main/java")
}
}
test {
Expand All @@ -89,7 +83,7 @@ subprojects {
}

createDockerFile {
from 'docker.io/eclipse-temurin:11'
from 'docker.io/eclipse-temurin:17-jre'
smartCopy configurations.sharedLibs, '/usr/local/tomcat/shared/lib/'
smartCopy "${project.parent.projectDir}/src/shared/main/resources/keystore", '/keystore'
smartCopy configurations.runtimeClasspath, '/app/tomcat-embedded/lib'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import eu.xenit.alfresco.tomcat.embedded.config.TomcatConfiguration;
import eu.xenit.alfresco.tomcat.embedded.tomcat.TomcatCustomizer;
import org.apache.catalina.startup.Tomcat;

public class AlfrescoTomcatCustomizer implements TomcatCustomizer {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package eu.xenit.alfresco.tomcat.embedded.tomcat;

import eu.xenit.alfresco.tomcat.embedded.config.TomcatConfiguration;
import eu.xenit.logging.json.valve.JsonAccessLogValve;
import eu.xenit.logging.json.valve.JsonAccessLogValve10;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.Service;
Expand Down Expand Up @@ -108,7 +108,7 @@ private void addWebapp(Tomcat tomcat, Path path) {
ctx.addLifecycleListener(lifecycleListener);

if (getConfiguration().isAccessLogging()) {
JsonAccessLogValve valve = new JsonAccessLogValve();
JsonAccessLogValve10 valve = new JsonAccessLogValve10();
ctx.addValve(valve);
ctx.getAccessLog();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package eu.xenit.alfresco.tomcat.embedded.tomcat;

import eu.xenit.alfresco.tomcat.embedded.config.TomcatConfiguration;
import eu.xenit.logging.json.valve.JsonAccessLogValve85;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.Service;
import org.apache.catalina.WebResourceRoot;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.startup.Tomcat;
import org.apache.catalina.webresources.DirResourceSet;
import org.apache.catalina.webresources.StandardRoot;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;

import static eu.xenit.alfresco.tomcat.embedded.utils.Utils.redirectLog4j;

public class TomcatFactory {

private final TomcatConfiguration configuration;

public TomcatFactory(TomcatConfiguration configuration) {
this.configuration = configuration;
}

public static Connector getConnector(Tomcat tomcat, String protocol, int port, boolean sslEnabled, String scheme, int maxThreads, int maxHttpHeaderSize, String relaxedPathChars, String relaxedQueryChars) {
Connector connector = new Connector(protocol);
connector.setPort(port);
connector.setProperty("connectionTimeout", "240000");
connector.setURIEncoding(StandardCharsets.UTF_8.name());
connector.setProperty("SSLEnabled", String.valueOf(sslEnabled));
connector.setProperty("maxThreads", String.valueOf(maxThreads));
connector.setProperty("maxHttpHeaderSize", String.valueOf(maxHttpHeaderSize));
connector.setProperty("relaxedPathChars", relaxedPathChars);
connector.setProperty("relaxedQueryChars", relaxedQueryChars);
connector.setScheme(scheme);
Service service = tomcat.getService();
service.setContainer(tomcat.getEngine());
connector.setService(service);
return connector;
}

private TomcatConfiguration getConfiguration() {
return configuration;
}

public Tomcat getTomcat() throws IOException {
Tomcat tomcat = new Tomcat();
tomcat.setBaseDir(getConfiguration().getTomcatBaseDir());
tomcat.setPort(getConfiguration().getTomcatPort());
tomcat.getServer().setPort(getConfiguration().getTomcatServerPort());
createDefaultConnector(tomcat);
addUserWithRole(tomcat, "CN=Alfresco Repository Client, OU=Unknown, O=Alfresco Software Ltd., L=Maidenhead, ST=UK, C=GB", null, "repoclient");
addUserWithRole(tomcat, "CN=Alfresco Repository, OU=Unknown, O=Alfresco Software Ltd., L=Maidenhead, ST=UK, C=GB", null, "repository");
Path webapps = Paths.get(getConfiguration().getWebappsPath());
if (Files.exists(webapps)) {
try (var directoryStream = Files.newDirectoryStream(webapps)) {
directoryStream.forEach(path -> addWebapp(tomcat, path));
}
}
return tomcat;
}

protected boolean isEmptyDir(Path path) {
if (Files.isDirectory(path)) {
try (Stream<Path> entries = Files.list(path)) {
return entries.findFirst().isEmpty();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

return false;
}

private void addWebapp(Tomcat tomcat, Path path) {
if (isEmptyDir(path)) {
// Our gradle plugin adds a share directory, even when baseShareWar is not configured
return;
}
if (Files.isDirectory(path)) {
String contextPath = "/" + path.getFileName().toString();
String absolutePath = path.toAbsolutePath().toString();
StandardContext ctx = (StandardContext) tomcat.addWebapp(contextPath, absolutePath);
ctx.setParentClassLoader(Thread.currentThread().getContextClassLoader());
LifecycleListener lifecycleListener = event -> {
if (event.getType().equals("before_start")) {
WebResourceRoot resources = new StandardRoot(ctx);
resources.setCacheMaxSize(getConfiguration().getTomcatCacheMaxSize());
resources.addPostResources(new DirResourceSet(resources, "/WEB-INF/classes", getConfiguration().getSharedClasspathDir(), "/"));
resources.addPostResources(new DirResourceSet(resources, "/WEB-INF/classes", getConfiguration().getGeneratedClasspathDir(), "/"));
resources.addJarResources(new DirResourceSet(resources, "/WEB-INF/lib", getConfiguration().getSharedLibDir(), "/"));
if (getConfiguration().isJsonLogging()) {
redirectLog4j(path, Paths.get(configuration.getGeneratedClasspathDir()));
}
ctx.setResources(resources);
}
if (getConfiguration().isExitOnFailure() && event.getType().equals("after_stop")) {
stopTomcat(tomcat);
}
};
ctx.addLifecycleListener(lifecycleListener);

if (getConfiguration().isAccessLogging()) {
JsonAccessLogValve85 valve = new JsonAccessLogValve85();
ctx.addValve(valve);
ctx.getAccessLog();
}
}
}

private void createDefaultConnector(Tomcat tomcat) {
Connector connector = getConnector(tomcat,
"HTTP/1.1",
getConfiguration().getTomcatPort(),
false,
"http",
getConfiguration().getTomcatMaxThreads(),
getConfiguration().getTomcatMaxHttpHeaderSize(),
getConfiguration().getTomcatRelaxedPathChars(),
getConfiguration().getTomcatRelaxedQueryChars()
);
connector.setRedirectPort(getConfiguration().getTomcatSslPort());
tomcat.setConnector(connector);
}

private void addUserWithRole(Tomcat tomcat, String username, String password, String role) {
tomcat.addUser(username, password);
tomcat.addRole(username, role);
}


private void stopTomcat(Tomcat tomcat) {
Thread thread = new Thread(() -> {
try {
tomcat.stop();
tomcat.destroy();
} catch (LifecycleException e) {
e.printStackTrace();
}
});
thread.start();

}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package eu.xenit.alfresco.tomcat.embedded.tomcat;

import eu.xenit.alfresco.tomcat.embedded.config.TomcatConfiguration;
import eu.xenit.logging.json.valve.JsonAccessLogValve85;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.Service;
import org.apache.catalina.WebResourceRoot;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.startup.Tomcat;
import org.apache.catalina.webresources.DirResourceSet;
import org.apache.catalina.webresources.StandardRoot;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;

import static eu.xenit.alfresco.tomcat.embedded.utils.Utils.redirectLog4j;

public class TomcatFactory {

private final TomcatConfiguration configuration;

public TomcatFactory(TomcatConfiguration configuration) {
this.configuration = configuration;
}

public static Connector getConnector(Tomcat tomcat, String protocol, int port, boolean sslEnabled, String scheme, int maxThreads, int maxHttpHeaderSize, String relaxedPathChars, String relaxedQueryChars) {
Connector connector = new Connector(protocol);
connector.setPort(port);
connector.setProperty("connectionTimeout", "240000");
connector.setURIEncoding(StandardCharsets.UTF_8.name());
connector.setProperty("SSLEnabled", String.valueOf(sslEnabled));
connector.setProperty("maxThreads", String.valueOf(maxThreads));
connector.setProperty("maxHttpHeaderSize", String.valueOf(maxHttpHeaderSize));
connector.setProperty("relaxedPathChars", relaxedPathChars);
connector.setProperty("relaxedQueryChars", relaxedQueryChars);
connector.setScheme(scheme);
Service service = tomcat.getService();
service.setContainer(tomcat.getEngine());
connector.setService(service);
return connector;
}

private TomcatConfiguration getConfiguration() {
return configuration;
}

public Tomcat getTomcat() throws IOException {
Tomcat tomcat = new Tomcat();
tomcat.setBaseDir(getConfiguration().getTomcatBaseDir());
tomcat.setPort(getConfiguration().getTomcatPort());
tomcat.getServer().setPort(getConfiguration().getTomcatServerPort());
createDefaultConnector(tomcat);
addUserWithRole(tomcat, "CN=Alfresco Repository Client, OU=Unknown, O=Alfresco Software Ltd., L=Maidenhead, ST=UK, C=GB", null, "repoclient");
addUserWithRole(tomcat, "CN=Alfresco Repository, OU=Unknown, O=Alfresco Software Ltd., L=Maidenhead, ST=UK, C=GB", null, "repository");
Path webapps = Paths.get(getConfiguration().getWebappsPath());
if (Files.exists(webapps)) {
try (var directoryStream = Files.newDirectoryStream(webapps)) {
directoryStream.forEach(path -> addWebapp(tomcat, path));
}
}
return tomcat;
}

protected boolean isEmptyDir(Path path) {
if (Files.isDirectory(path)) {
try (Stream<Path> entries = Files.list(path)) {
return entries.findFirst().isEmpty();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

return false;
}

private void addWebapp(Tomcat tomcat, Path path) {
if (isEmptyDir(path)) {
// Our gradle plugin adds a share directory, even when baseShareWar is not configured
return;
}
if (Files.isDirectory(path)) {
String contextPath = "/" + path.getFileName().toString();
String absolutePath = path.toAbsolutePath().toString();
StandardContext ctx = (StandardContext) tomcat.addWebapp(contextPath, absolutePath);
ctx.setParentClassLoader(Thread.currentThread().getContextClassLoader());
LifecycleListener lifecycleListener = event -> {
if (event.getType().equals("before_start")) {
WebResourceRoot resources = new StandardRoot(ctx);
resources.setCacheMaxSize(getConfiguration().getTomcatCacheMaxSize());
resources.addPostResources(new DirResourceSet(resources, "/WEB-INF/classes", getConfiguration().getSharedClasspathDir(), "/"));
resources.addPostResources(new DirResourceSet(resources, "/WEB-INF/classes", getConfiguration().getGeneratedClasspathDir(), "/"));
resources.addJarResources(new DirResourceSet(resources, "/WEB-INF/lib", getConfiguration().getSharedLibDir(), "/"));
if (getConfiguration().isJsonLogging()) {
redirectLog4j(path, Paths.get(configuration.getGeneratedClasspathDir()));
}
ctx.setResources(resources);
}
if (getConfiguration().isExitOnFailure() && event.getType().equals("after_stop")) {
stopTomcat(tomcat);
}
};
ctx.addLifecycleListener(lifecycleListener);

if (getConfiguration().isAccessLogging()) {
JsonAccessLogValve85 valve = new JsonAccessLogValve85();
ctx.addValve(valve);
ctx.getAccessLog();
}
}
}

private void createDefaultConnector(Tomcat tomcat) {
Connector connector = getConnector(tomcat,
"HTTP/1.1",
getConfiguration().getTomcatPort(),
false,
"http",
getConfiguration().getTomcatMaxThreads(),
getConfiguration().getTomcatMaxHttpHeaderSize(),
getConfiguration().getTomcatRelaxedPathChars(),
getConfiguration().getTomcatRelaxedQueryChars()
);
connector.setRedirectPort(getConfiguration().getTomcatSslPort());
tomcat.setConnector(connector);
}

private void addUserWithRole(Tomcat tomcat, String username, String password, String role) {
tomcat.addUser(username, password);
tomcat.addRole(username, role);
}


private void stopTomcat(Tomcat tomcat) {
Thread thread = new Thread(() -> {
try {
tomcat.stop();
tomcat.destroy();
} catch (LifecycleException e) {
e.printStackTrace();
}
});
thread.start();

}


}

0 comments on commit d0c815c

Please sign in to comment.