Reenginering to prepare view webapp

This commit is contained in:
Claude Brisson
2023-06-07 09:34:44 +02:00
parent 231b7d68dd
commit 478c1e1f9d
64 changed files with 48 additions and 24 deletions

1
.gitignore vendored
View File

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

View File

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

View File

@@ -9,7 +9,7 @@
<artifactId>engine-parent</artifactId> <artifactId>engine-parent</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
</parent> </parent>
<artifactId>webapp</artifactId> <artifactId>api-webapp</artifactId>
<packaging>war</packaging> <packaging>war</packaging>
<name>${project.groupId}:${project.artifactId}</name> <name>${project.groupId}:${project.artifactId}</name>

View File

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

View File

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

View File

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

View File

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

View File

@@ -21,4 +21,4 @@ curl -s --header "Accept: application/json" http://localhost:8080/api/tour/1/par
echo echo
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> </properties>
<modules> <modules>
<module>webapp</module> <module>api-webapp</module>
<!-- <module>view-webapp</module> in progress -->
<module>container</module> <module>container</module>
<module>bootstrap</module> <module>bootstrap</module>
<module>application</module> <module>application</module>