Cleaned up logging
parent
f1c97a983c
commit
7572d4f407
|
@ -18,6 +18,7 @@
|
|||
|
||||
package dorkbox.vaadin.undertow
|
||||
|
||||
import dorkbox.vaadin.util.logger
|
||||
import io.undertow.UndertowLogger
|
||||
import io.undertow.io.IoCallback
|
||||
import io.undertow.predicate.Predicate
|
||||
|
@ -31,12 +32,12 @@ import io.undertow.server.handlers.cache.ResponseCache
|
|||
import io.undertow.server.handlers.encoding.ContentEncodedResourceManager
|
||||
import io.undertow.server.handlers.resource.*
|
||||
import io.undertow.util.*
|
||||
import org.slf4j.Logger
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.nio.file.Paths
|
||||
import java.util.*
|
||||
import java.util.concurrent.CopyOnWriteArrayList
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.*
|
||||
|
||||
@Suppress("unused")
|
||||
/**
|
||||
|
@ -49,6 +50,7 @@ import java.util.concurrent.TimeUnit
|
|||
*/
|
||||
class DirectResourceHandler(@Volatile private var resourceManager: ResourceManager?,
|
||||
@Volatile private var resourceSupplier: ResourceSupplier = DefaultResourceSupplier(resourceManager),
|
||||
val logger: Logger,
|
||||
private val next: HttpHandler = ResponseCodeHandler.HANDLE_404) : HttpHandler {
|
||||
|
||||
private val welcomeFiles = CopyOnWriteArrayList(arrayOf("index.html", "index.htm", "default.html", "default.htm"))
|
||||
|
@ -451,12 +453,13 @@ class DirectResourceHandler(@Volatile private var resourceManager: ResourceManag
|
|||
|
||||
}
|
||||
|
||||
private class Wrapper internal constructor(private val location: String,
|
||||
private val allowDirectoryListing: Boolean) : HandlerWrapper {
|
||||
private class Wrapper(private val location: String,
|
||||
private val allowDirectoryListing: Boolean) : HandlerWrapper {
|
||||
|
||||
override fun wrap(handler: HttpHandler): HttpHandler {
|
||||
val rm = PathResourceManager(Paths.get(location), 1024)
|
||||
val resourceHandler = DirectResourceHandler(rm)
|
||||
val resourceManager = PathResourceManager(Paths.get(location), 1024)
|
||||
// use a default logger
|
||||
val resourceHandler = DirectResourceHandler(resourceManager, DefaultResourceSupplier(resourceManager), logger())
|
||||
resourceHandler.setDirectoryListingEnabled(allowDirectoryListing)
|
||||
return resourceHandler
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2023 dorkbox, llc
|
||||
* Copyright 2024 dorkbox, llc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -37,7 +37,7 @@ import io.undertow.server.handlers.resource.Resource
|
|||
import io.undertow.server.handlers.resource.ResourceChangeListener
|
||||
import io.undertow.server.handlers.resource.ResourceManager
|
||||
import io.undertow.server.handlers.resource.URLResource
|
||||
import mu.KLogger
|
||||
import org.slf4j.Logger
|
||||
import java.io.IOException
|
||||
import java.net.URL
|
||||
|
||||
|
@ -48,20 +48,25 @@ import java.net.URL
|
|||
* @author Andy Wilkinson
|
||||
* @author Dorkbox LLC
|
||||
*/
|
||||
internal class JarResourceManager(val name: String, val trie: DoubleArrayStringTrie<URL>, val logger: KLogger) : ResourceManager {
|
||||
internal class JarResourceManager(val name: String,
|
||||
private val trie: DoubleArrayStringTrie<URL>,
|
||||
private val logger: Logger) : ResourceManager {
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun getResource(path: String): Resource? {
|
||||
logger.trace { "REQUEST jar: $path" }
|
||||
|
||||
val url = trie[path] ?: return null
|
||||
logger.trace { "TRIE: $url" }
|
||||
|
||||
val resource = URLResource(url, path)
|
||||
if (path.isNotBlank() && path != "/" && resource.contentLength < 0) {
|
||||
val url = trie[path]
|
||||
if (url === null) {
|
||||
logger.trace("REQUEST not found for PATH: {}", path)
|
||||
return null
|
||||
}
|
||||
|
||||
val resource = URLResource(url, path)
|
||||
if (path.isNotBlank() && path != "/" && resource.contentLength < 0) {
|
||||
logger.trace("REQUEST file not found for PATH: {}, {}", path, url)
|
||||
return null
|
||||
}
|
||||
|
||||
logger.debug("REQUEST found: {}, {}", path, url)
|
||||
return resource
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2020 Dorkbox LLC
|
||||
* Copyright 2024 dorkbox, llc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,14 +16,14 @@
|
|||
|
||||
package dorkbox.vaadin.undertow
|
||||
|
||||
import dorkbox.vaadin.util.logger
|
||||
import io.undertow.UndertowMessages
|
||||
import io.undertow.server.handlers.resource.Resource
|
||||
import io.undertow.server.handlers.resource.ResourceChangeListener
|
||||
import io.undertow.server.handlers.resource.ResourceManager
|
||||
import mu.KotlinLogging
|
||||
|
||||
class ResourceCollectionManager(private val resources: List<ResourceManager>) : ResourceManager {
|
||||
private val logger = KotlinLogging.logger {}
|
||||
private val logger = logger()
|
||||
|
||||
private val changeListenerSupported : Boolean by lazy {
|
||||
var supported = true
|
||||
|
@ -77,7 +77,7 @@ class ResourceCollectionManager(private val resources: List<ResourceManager>) :
|
|||
try {
|
||||
it.close()
|
||||
} catch (e: Exception) {
|
||||
logger.error(e) { "Error closing resourceManager" }
|
||||
logger.error("Error closing resourceManager", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue