Updated to vaadin 14.7.6, added more trace logging for http requests. Startup will exit early if the stats.json file does not exist.

This commit is contained in:
Robinson 2021-12-03 07:12:40 -07:00
parent af4c56d1ee
commit 0c50cb8251
No known key found for this signature in database
GPG Key ID: 8E7DB78588BD6F5C
3 changed files with 41 additions and 14 deletions

View File

@ -39,7 +39,7 @@ object Extras {
const val group = "com.dorkbox"
const val name = "VaadinUndertow"
const val id = "VaadinUndertow"
const val version = "14.7"
const val version = "14.7.1"
const val vendor = "Dorkbox LLC"
const val vendorUrl = "https://dorkbox.com"
@ -50,7 +50,7 @@ object Extras {
const val coroutineVer = "1.4.3"
// this must match the version information in the VaadinConfig.kt file (this is automatically passed into the plugin)
const val vaadinVer = "14.7.1"
const val vaadinVer = "14.7.6"
const val undertowVer = "2.2.10.Final"
}

View File

@ -41,6 +41,7 @@ import mu.KotlinLogging
import org.xnio.Xnio
import org.xnio.XnioWorker
import java.io.File
import java.io.IOException
import java.net.URL
import java.util.*
import java.util.concurrent.CountDownLatch
@ -72,6 +73,7 @@ class VaadinApplication : ExceptionHandler {
}
private val logger = KotlinLogging.logger {}
private val httpLogger = KotlinLogging.logger(logger.name + ".http")
val runningAsJar: Boolean
val tempDir: File = File(System.getProperty("java.io.tmpdir", "tmpDir"), "undertow").absoluteFile
@ -359,15 +361,17 @@ class VaadinApplication : ExceptionHandler {
// so we can use the undertow cache to serve resources, instead of the vaadin servlet (which doesn't cache, and is really slow)
// NOTE: this will load the stats.json file!
val debug = vaadinConfig.debug
// for our classloader, we have to make sure that we are BY DIRECTORY, not by file, for the resource array!
val toTypedArray = jarLocations.map { it.resourceDir }.toSet().toTypedArray()
this.trieClassLoader = TrieClassLoader(diskTrie, jarStringTrie, toTypedArray, this.javaClass.classLoader, vaadinConfig.debug)
this.trieClassLoader = TrieClassLoader(diskTrie, jarStringTrie, toTypedArray, this.javaClass.classLoader, debug)
// we want to start ALL aspects of the application using our NEW classloader (instead of the "current" classloader)
Thread.currentThread().contextClassLoader = this.trieClassLoader
val strictFileResourceManager = StrictFileResourceManager("Static Files", diskTrie, vaadinConfig.debug)
val jarResourceManager = JarResourceManager("Jar Files", jarUrlTrie, vaadinConfig.debug)
val strictFileResourceManager = StrictFileResourceManager("Static Files", diskTrie, debug)
val jarResourceManager = JarResourceManager("Jar Files", jarUrlTrie, debug)
// val jarResources = ArrayList<JarResourceManager>()
// jarLocations.forEach { (requestPath, resourcePath, relativeResourcePath) ->
@ -744,8 +748,23 @@ class VaadinApplication : ExceptionHandler {
return undertowServer?.listenerInfo ?: throw UndertowMessages.MESSAGES.serverNotStarted()
}
@Throws(IOException::class)
fun start() {
// make sure that the stats.json file is accessible
// the request will come in as 'VAADIN/config/stats.json' or '/VAADIN/config/stats.json'
//
// If stats.json DOES NOT EXIST, there will be infinite recursive lookups for this file.
val statsFile = "VAADIN/config/stats.json"
// our resource manager ONLY manages disk + jars!
if (diskTrie[statsFile] == null && jarStringTrie[statsFile] == null) {
throw IOException("Unable to startup the VAADIN webserver. The 'stats.json' definition file is not available. (Usually at '$statsFile'')" )
}
val statsUrl = "$baseUrl/$statsFile"
logger.info("Setting up stats file http location as: $statsUrl")
vaadinConfig.setupStatsJsonUrl(servlet, baseUrl)
undertowServer = serverBuilder.build()
/////////////////////////////////////////////////////////////////
@ -841,13 +860,16 @@ class VaadinApplication : ExceptionHandler {
fun handleRequest(exchange: HttpServerExchange) {
// dev-mode : incoming requests USUALLY start with a '/'
val path = exchange.relativePath
val debug = vaadinConfig.debug
val isTraceEnabled = httpLogger.isTraceEnabled
if (debug) {
println("REQUEST undertow: $path")
if (isTraceEnabled) {
httpLogger.trace("REQUEST undertow: $path")
}
if (path.length == 1) {
if (isTraceEnabled) {
httpLogger.trace("REQUEST of length 1: $path")
}
servletHttpHandler.handleRequest(exchange)
return
}
@ -859,23 +881,28 @@ class VaadinApplication : ExceptionHandler {
// our resource manager ONLY manages disk + jars!
val diskResourcePath: URL? = diskTrie[path]
if (diskResourcePath != null) {
if (debug) {
println("URL TRIE: $diskResourcePath")
if (isTraceEnabled) {
httpLogger.trace("URL DISK TRIE: $diskResourcePath")
}
cacheHandler.handleRequest(exchange)
return
}
val jarResourcePath: String? = jarStringTrie[path]
if (jarResourcePath != null) {
if (debug) {
println("URL TRIE: $jarResourcePath")
if (isTraceEnabled) {
httpLogger.trace("URL JAR TRIE: $jarResourcePath")
}
cacheHandler.handleRequest(exchange)
return
}
// this is the default, and will use the servlet to handle the request
if (isTraceEnabled) {
httpLogger.trace("Forwarding request to servlet")
}
servletHttpHandler.handleRequest(exchange)
}

View File

@ -29,7 +29,7 @@ import java.io.File
class VaadinConfig(runningAsJar: Boolean, tempDir: File) {
companion object {
// this must match the version information in the build.gradle.kts file
const val VAADIN_VERSION = "14.7.1"
const val VAADIN_VERSION = "14.7.6"
val EXTRACT_JAR = "extract.jar"
val EXTRACT_JAR_OVERWRITE = "extract.jar.overwrite"
@ -131,6 +131,6 @@ class VaadinConfig(runningAsJar: Boolean, tempDir: File) {
// the stats.json http request will be coming from the local box (so everything is local. Only when on a specific IP should that specific IP be used)
servlet
.addInitParam(InitParameters.EXTERNAL_STATS_FILE, "true")
.addInitParam(InitParameters.EXTERNAL_STATS_URL, "$url/VAADIN/config/stats.json")
.addInitParam(InitParameters.EXTERNAL_STATS_URL, "$url")
}
}