This commit is contained in:
Theo Barollet
2023-06-07 10:31:05 +02:00
64 changed files with 48 additions and 168 deletions

1
.gitignore vendored
View File

@@ -5,3 +5,4 @@ target
/pairgoth.properties
*.err
/tournamentfiles
*.iml

View File

@@ -16,7 +16,7 @@
├── docker .................................... Docker packaging
│   ├── pairgoth.properties.example ........... Docker property file to instanciate
│   └── run.sh ................................ Docker launch script
└── webapp .................................... Engine web application
└── api-webapp ................................ Engine web application
└── src
├── main
│   ├── kotlin ........................ Engine kotlin sources (the real meat is here!)
@@ -26,10 +26,10 @@
└── kotlin ........................ Engine webapp API unit tests
```
## Webapp sources structure
## API Webapp sources structure
```
webapp/src/main/kotlin/org/jeudego/pairgoth
api-webapp/src/main/kotlin/org/jeudego/pairgoth
├── api .................................... API handlers
├── ext .................................... External: import/export features
├── model .................................. Domain logic model

View File

@@ -9,7 +9,7 @@
<artifactId>engine-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>webapp</artifactId>
<artifactId>api-webapp</artifactId>
<packaging>war</packaging>
<name>${project.groupId}:${project.artifactId}</name>
@@ -51,25 +51,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>enforce-properties-file-exists</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireFilesExist>
<message>Missing pairgoth.properties file</message>
<files>
<file>${project.parent.basedir}/pairgoth.properties</file>
</files>
</requireFilesExist>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>

View File

@@ -41,7 +41,7 @@
<!-- servlet mappings -->
<servlet-mapping>
<servlet-name>api</servlet-name>
<url-pattern>/api/*</url-pattern>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>sse</servlet-name>

View File

@@ -15,7 +15,7 @@
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>webapp</artifactId>
<artifactId>api-webapp</artifactId>
<version>${project.version}</version>
<type>war</type>
</dependency>

View File

@@ -20,7 +20,7 @@
<unpack>true</unpack>
<useTransitiveDependencies>false</useTransitiveDependencies>
<includes>
<include>${project.groupId}:webapp</include>
<include>${project.groupId}:api-webapp</include>
<include>${project.groupId}:bootstrap</include>
</includes>
</dependencySet>

View File

@@ -25,11 +25,11 @@ import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.util.resource.PathResource;
import org.eclipse.jetty.webapp.WebAppContext;
@@ -41,7 +41,8 @@ public class ServerMain
PROD
}
private Path basePath;
private Path apiBasePath = null;
private Path viewBasePath = null;
public static void main(String[] args)
{
@@ -59,14 +60,24 @@ public class ServerMain
{
// create server and web context
Server server = new Server(8080);
WebAppContext context = new WebAppContext() {
WebAppContext apiContext = new WebAppContext() {
@Override
public boolean isServerResource(String name, URL url)
{
return super.isServerResource(name, url) || url.getFile().contains("/WEB-INF/jetty-server/");
}
};
context.setContextPath("/");
apiContext.setContextPath("/api");
WebAppContext viewContext = new WebAppContext() {
@Override
public boolean isServerResource(String name, URL url)
{
return super.isServerResource(name, url) || url.getFile().contains("/WEB-INF/jetty-server/");
}
};
viewContext.setContextPath("/");
// pairgoth runtime properties
File properties = new File("./pairgoth.properties");
@@ -77,7 +88,7 @@ public class ServerMain
String property = (String)entry.getKey();
String value = (String)entry.getValue();
if (property.startsWith("logger.")) {
context.setInitParameter("webapp-slf4j-logger." + property.substring(7), value);
apiContext.setInitParameter("webapp-slf4j-logger." + property.substring(7), value);
} else {
System.setProperty("pairgoth." + property, value);
}
@@ -88,21 +99,29 @@ public class ServerMain
{
case PROD:
// Configure as WAR
context.setWar(basePath.toString());
apiContext.setWar(apiBasePath.toString());
viewContext.setWar(viewBasePath.toString());
break;
case DEV:
// Configuring from Development Base
context.setBaseResource(new PathResource(basePath.resolve("src/main/webapp")));
apiContext.setBaseResource(new PathResource(apiBasePath.resolve("src/main/webapp")));
// Add webapp compiled classes & resources (copied into place from src/main/resources)
Path classesPath = basePath.resolve("target/webapp/WEB-INF/classes");
context.setExtraClasspath(classesPath.toAbsolutePath().toString());
Path apiClassesPath = apiBasePath.resolve("target/webapp/WEB-INF/classes");
apiContext.setExtraClasspath(apiClassesPath.toAbsolutePath().toString());
viewContext.setBaseResource(new PathResource(viewBasePath.resolve("src/main/webapp")));
// Add webapp compiled classes & resources (copied into place from src/main/resources)
Path viewClassesPath = viewBasePath.resolve("target/webapp/WEB-INF/classes");
viewContext.setExtraClasspath(viewClassesPath.toAbsolutePath().toString());
server.setDumpAfterStart(true);
break;
default:
throw new FileNotFoundException("Unable to configure WebAppContext base resource undefined");
}
server.setHandler(context);
server.setHandler(new ContextHandlerCollection(apiContext, viewContext));
server.start();
server.join();
@@ -117,16 +136,19 @@ public class ServerMain
Path warPath = new File(warLocation).toPath().toRealPath();
if (Files.exists(warPath) && Files.isRegularFile(warPath))
{
this.basePath = warPath;
this.apiBasePath = warPath;
this.viewBasePath = warPath;
return OperationalMode.PROD;
}
}
// We are in development mode, likely building and testing from an IDE.
Path devPath = new File("../webapp").toPath().toRealPath();
if (Files.exists(devPath) && Files.isDirectory(devPath))
Path apiDevPath = new File("../api-webapp").toPath().toRealPath();
Path viewDevPath = new File("../view-webapp").toPath().toRealPath();
if (Files.exists(apiDevPath) && Files.isDirectory(apiDevPath) && Files.exists(viewDevPath) && Files.isDirectory(viewDevPath))
{
this.basePath = devPath;
this.apiBasePath = apiDevPath;
this.viewBasePath = viewDevPath;
return OperationalMode.DEV;
}

View File

@@ -21,4 +21,4 @@ curl -s --header "Accept: application/json" http://localhost:8080/api/tour/1/par
echo
echo
curl -s --header "Last-Event-Id: 0" http://localhost:8080/events
curl -s --header "Last-Event-Id: 0" http://localhost:8080/api/events

View File

@@ -59,7 +59,8 @@
</properties>
<modules>
<module>webapp</module>
<module>api-webapp</module>
<!-- <module>view-webapp</module> in progress -->
<module>container</module>
<module>bootstrap</module>
<module>application</module>

View File

@@ -1,5 +0,0 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="wac" class="org.eclipse.jetty.webapp.WebAppContext">
</Configure>

View File

@@ -1,26 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.ServerConnector">
<Arg name="server">
<Ref refid="Server"/>
</Arg>
<Arg name="factories">
<Array type="org.eclipse.jetty.server.ConnectionFactory">
<Item>
<New class="org.eclipse.jetty.server.HttpConnectionFactory">
<Arg name="config">
<New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
</New>
</Arg>
</New>
</Item>
</Array>
</Arg>
<Set name="port"><Property name="jetty.http.port" deprecated="jetty.port" default="${jetty.port}"/></Set>
</New>
</Arg>
</Call>
</Configure>

View File

@@ -1,24 +0,0 @@
<?xml version="1.0"?><!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<!-- ============================================================= --><!-- Configure an HTTPS connector. --><!-- This configuration must be used in conjunction with jetty.xml --><!-- and jetty-ssl.xml. --><!-- ============================================================= -->
<Configure id="sslConnector" class="org.eclipse.jetty.server.ServerConnector">
<Call name="addIfAbsentConnectionFactory">
<Arg>
<New class="org.eclipse.jetty.server.SslConnectionFactory">
<Arg name="next">http/1.1</Arg>
<Arg name="sslContextFactory"><Ref refid="sslContextFactory"/></Arg>
</New>
</Arg>
</Call>
<Call name="addConnectionFactory">
<Arg>
<New class="org.eclipse.jetty.server.HttpConnectionFactory">
<Arg name="config"><Ref refid="sslHttpConfig" /></Arg>
<Arg name="compliance"><Call class="org.eclipse.jetty.http.HttpCompliance" name="valueOf"><Arg><Property name="jetty.http.compliance" default="RFC7230"/></Arg></Call></Arg>
</New>
</Arg>
</Call>
</Configure>

View File

@@ -1,16 +0,0 @@
<?xml version="1.0"?><!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory$Server">
<Set name="TrustAll">true</Set>
<Set name="KeyStorePath"><Property name="jetty.base" default="." />/<Property name="jetty.keystore" default="src/test/resources/jetty.keystore"/></Set>
<Set name="KeyStorePassword"><Property name="jetty.keystore.password" default="secret"/></Set>
<Set name="KeyManagerPassword"><Property name="jetty.keymanager.password" default="secret"/></Set>
<Set name="TrustStorePath"><Property name="jetty.base" default="." />/<Property name="jetty.truststore" default="src/test/resources/jetty.keystore"/></Set>
<Set name="TrustStorePassword"><Property name="jetty.truststore.password" default="secret"/></Set>
<Set name="EndpointIdentificationAlgorithm"></Set>
<New id="sslHttpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
<Arg><Ref refid="httpConfig"/></Arg>
<Call name="addCustomizer">
<Arg><New class="org.eclipse.jetty.server.SecureRequestCustomizer"/></Arg>
</Call>
</New>
</Configure>

View File

@@ -1,46 +0,0 @@
<?xml version="1.0"?><!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Call name="addConnector">
<Arg>
<New id="sslConnector" class="org.eclipse.jetty.server.ServerConnector">
<Arg name="server"><Ref refid="Server" /></Arg>
<Arg name="acceptors" type="int"><Property name="jetty.ssl.acceptors" deprecated="ssl.acceptors" default="-1"/></Arg>
<Arg name="selectors" type="int"><Property name="jetty.ssl.selectors" deprecated="ssl.selectors" default="-1"/></Arg>
<Arg name="factories">
<Array type="org.eclipse.jetty.server.ConnectionFactory">
</Array>
</Arg>
<Set name="host"><Property name="jetty.ssl.host" deprecated="jetty.host" /></Set>
<Set name="port"><Property name="jetty.ssl.port" deprecated="ssl.port" default="${jetty.ssl.port}" /></Set>
<Set name="idleTimeout"><Property name="jetty.ssl.idleTimeout" deprecated="ssl.timeout" default="30000"/></Set>
<Set name="acceptorPriorityDelta"><Property name="jetty.ssl.acceptorPriorityDelta" deprecated="ssl.acceptorPriorityDelta" default="0"/></Set>
<Set name="acceptQueueSize"><Property name="jetty.ssl.acceptQueueSize" deprecated="ssl.acceptQueueSize" default="0"/></Set>
<Set name="reuseAddress"><Property name="jetty.ssl.reuseAddress" default="true"/></Set>
<Set name="acceptedTcpNoDelay"><Property name="jetty.ssl.acceptedTcpNoDelay" default="true"/></Set>
<Set name="acceptedReceiveBufferSize"><Property name="jetty.ssl.acceptedReceiveBufferSize" default="-1"/></Set>
<Set name="acceptedSendBufferSize"><Property name="jetty.ssl.acceptedSendBufferSize" default="-1"/></Set>
<Get name="SelectorManager">
<Set name="connectTimeout"><Property name="jetty.ssl.connectTimeout" default="15000"/></Set>
</Get>
</New>
</Arg>
</Call>
<New id="sslHttpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
<Arg><Ref refid="httpConfig"/></Arg>
<Call name="addCustomizer">
<Arg>
<New class="org.eclipse.jetty.server.SecureRequestCustomizer">
<Arg name="sniRequired" type="boolean"><Property name="jetty.ssl.sniRequired" default="false"/></Arg>
<Arg name="sniHostCheck" type="boolean"><Property name="jetty.ssl.sniHostCheck" default="true"/></Arg>
<Arg name="stsMaxAgeSeconds" type="int"><Property name="jetty.ssl.stsMaxAgeSeconds" default="-1"/></Arg>
<Arg name="stsIncludeSubdomains" type="boolean"><Property name="jetty.ssl.stsIncludeSubdomains" default="false"/></Arg>
</New>
</Arg>
</Call>
</New>
</Configure>

View File

@@ -1,8 +0,0 @@
# webapp
webapp.env = ${webapp.env}
webapp.url = ${webapp.url}
# smtp
# Logging
logger.level = ${logger.level}