View packaging still in progress

This commit is contained in:
Claude Brisson
2023-06-12 06:42:38 +02:00
parent a8d4649404
commit 3ff885a7c1
9 changed files with 53 additions and 20 deletions

View File

@@ -73,6 +73,16 @@
</classpathDependencyExcludes>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<webApp>
<contextPath>/api/</contextPath>
</webApp>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>

View File

@@ -51,7 +51,7 @@ class WebappManager : ServletContextListener, ServletContextAttributeListener, H
/* ServletContextListener interface */
override fun contextInitialized(sce: ServletContextEvent) {
context = sce.servletContext
logger.info("---------- Starting Web Application ----------")
logger.info("---------- Starting Pairgoth Server ----------")
context.setAttribute("manager", this)
webappRoot = context.getRealPath("/")
try {

View File

@@ -95,6 +95,20 @@
<!-- <includePath>${basedir}/src/main/sass/plugins/</includePath> -->
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<scan>0</scan>
<systemProperties>
<systemProperty>
<name>pairgoth.webapp.url</name>
<value>http://localhost:8080</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>

View File

@@ -1,6 +1,7 @@
# webapp
webapp.env = dev
env = dev
webapp.url = https://localhost:8080
api.url = https://localhost:8085
# store
store = file

View File

@@ -10,7 +10,7 @@ import okhttp3.internal.EMPTY_REQUEST
class ApiTool {
companion object {
const val JSON = "application/json"
val apiRoot = System.getProperty("pairgoth.webapp.url").let { base ->
val apiRoot = System.getProperty("pairgoth.api.url").let { base ->
if (base.endsWith('/')) "${base}api/"
else "${base}/api/"
}

View File

@@ -42,7 +42,7 @@ class LanguageFilter : Filter {
// the request must be redirected
val preferredLanguage = getPreferredLanguage(request)
val destination = if (lang != null) target else uri
response.sendRedirect("${preferredLanguage}${destination}")
response.sendRedirect("/${preferredLanguage}${destination}")
}
}
}

View File

@@ -51,7 +51,7 @@ class WebappManager : ServletContextListener, ServletContextAttributeListener, H
/* ServletContextListener interface */
override fun contextInitialized(sce: ServletContextEvent) {
context = sce.servletContext
logger.info("---------- Starting Web Application ----------")
logger.info("---------- Starting Pairgoth Web Client ----------")
context.setAttribute("manager", this)
webappRoot = context.getRealPath("/")
try {

View File

@@ -79,12 +79,25 @@ private fun getResourceProperty(key: String) = serverProps.getProperty(key)?.let
private fun launchServer() {
// create webapps contexts
val apiContext = createContext("api", "/api")
val viewContext = createContext("view", "/")
// read default properties and provided ones, if any
readProperties()
// handle properties
readProperties(apiContext, viewContext)
// create webapps contexts
val webAppContexts = mutableListOf<WebAppContext>()
val mode = serverProps["mode"] ?: throw Error("missing property: mode")
if (mode == "server" || mode == "standalone") webAppContexts.add(createContext("api", "/api"))
if (mode == "client" || mode == "standalone") webAppContexts.add(createContext("view", "/"))
// special handling for logger properties
serverProps.stringPropertyNames().asSequence().filter { propName ->
propName.startsWith("logger.")
}.forEach { propName ->
val key = "webapp-slf4j-logger.${propName.substring(7)}"
val value = serverProps.getProperty(propName)
webAppContexts.forEach { context ->
context.setInitParameter(key, value)
}
}
val webappUrl = serverProps.getProperty("webapp.url")?.let { URL(it) } ?: throw Error("missing property webapp.url")
val secure = webappUrl.protocol == "https"
@@ -96,7 +109,7 @@ private fun launchServer() {
server.apply {
// register webapps
handler = ContextHandlerCollection(apiContext, viewContext)
handler = ContextHandlerCollection(*webAppContexts.toTypedArray())
if (secure) {
val connector = buildSecureConnector(server, webappUrl.port)
addConnector(connector)
@@ -112,7 +125,7 @@ private fun createContext(webapp: String, contextPath: String) = WebAppContext()
context.contextPath = contextPath
}
private fun readProperties(vararg contexts: WebAppContext) {
private fun readProperties() {
val defaultProps = getResource("/server.default.properties") ?: throw Error("missing default server properties")
defaultProps.openStream().use {
serverProps.load(InputStreamReader(it, StandardCharsets.UTF_8))
@@ -123,13 +136,7 @@ private fun readProperties(vararg contexts: WebAppContext) {
serverProps.entries.forEach { entry ->
val property = entry.key as String
val value = entry.value as String
if (property.startsWith("logger.")) {
// special handling for logger properties
val webappLoggerPropKey = "webapp-slf4j-logger.${property.substring(7)}"
contexts.forEach { context ->
context.setInitParameter(webappLoggerPropKey, value)
}
} else if (property.startsWith("webapp.ssl.")) {
if (!property.startsWith("webapp.ssl.")) {
// do not propagate ssl properties further
} else {
System.setProperty("pairgoth.$property", value)

View File

@@ -1,4 +1,5 @@
webapp.url = https://localhost:8443
webapp.ssl.key = jar:file:$jar!/ssl/localhost.key
# webapp.ssl.pass = foobar (not supported for now)
webapp.ssl.pass =
webapp.ssl.cert = jar:file:$jar!/ssl/localhost.crt
mode = standalone