Skip to content

Commit

Permalink
Merge pull request #10 from RADAR-base/release-0.2.3
Browse files Browse the repository at this point in the history
Release 0.2.3
  • Loading branch information
blootsvoets authored Apr 7, 2020
2 parents 7d65201 + ef798e2 commit 958076f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repositories {
}
dependencies {
api("org.radarbase:radar-jersey:0.2.2.4")
api("org.radarbase:radar-jersey:0.2.3")
}
```

Expand Down
23 changes: 13 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {

description = 'Library for Jersey authorization, exception handling and configuration with the RADAR platform'
group = 'org.radarbase'
version = '0.2.2.4'
version = '0.2.3'

ext {
githubRepoName = 'RADAR-base/radar-jersey'
Expand All @@ -17,11 +17,14 @@ ext {
managementPortalVersion = "0.5.8"
jakartaWsRsVersion = "2.1.6"
jakartaAnnotationVersion = "1.3.5"
jerseyVersion = "2.29.1"
jerseyVersion = "2.30.1"
grizzlyVersion = "2.4.4"
jacksonVersion = "2.9.10.1"
jacksonModuleVersion = "2.9.10"
okhttpVersion = "4.2.0"
jacksonVersion = "2.10.3"
jacksonModuleVersion = "2.10.3"
okhttpVersion = "4.5.0"
slf4jVersion = "1.7.30"
javaxXmlBind = "2.2.11"
javaxActivation = "1.1.1"
}

repositories {
Expand All @@ -47,7 +50,7 @@ dependencies {
implementation 'com.github.spullara.mustache.java:compiler:0.9.6'

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.slf4j:slf4j-api:1.7.26"
implementation "org.slf4j:slf4j-api:$slf4jVersion"

implementation("org.glassfish.jersey.inject:jersey-hk2:$jerseyVersion")

Expand All @@ -57,10 +60,10 @@ dependencies {
runtimeOnly("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonModuleVersion")
runtimeOnly("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:$jacksonModuleVersion")

runtimeOnly 'javax.xml.bind:jaxb-api:2.2.11'
runtimeOnly 'com.sun.xml.bind:jaxb-core:2.2.11'
runtimeOnly 'com.sun.xml.bind:jaxb-impl:2.2.11'
runtimeOnly 'javax.activation:activation:1.1.1'
runtimeOnly "javax.xml.bind:jaxb-api:$javaxXmlBind"
runtimeOnly "com.sun.xml.bind:jaxb-core:$javaxXmlBind"
runtimeOnly "com.sun.xml.bind:jaxb-impl:$javaxXmlBind"
runtimeOnly "javax.activation:activation:$javaxActivation"

testRuntimeOnly("org.glassfish.grizzly:grizzly-http-server:$grizzlyVersion")
testRuntimeOnly("org.glassfish.jersey.containers:jersey-container-grizzly2-servlet:$jerseyVersion")
Expand Down
39 changes: 26 additions & 13 deletions src/main/kotlin/org/radarbase/jersey/config/ConfigLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.radarbase.jersey.filter.CorsFilter
import org.radarbase.jersey.filter.ResponseLoggerFilter
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.io.File
import java.io.BufferedInputStream
import java.io.IOException
import java.nio.file.Files
import java.nio.file.Paths
Expand All @@ -35,22 +35,26 @@ object ConfigLoader {
}

@JvmOverloads
fun <T> loadConfig(fileName: String, args: Array<String>, clazz: Class<T>, mapper: ObjectMapper? = null): T {
val configFileName = when {
args.size == 1 -> args[0]
Files.exists(Paths.get(fileName)) -> fileName
else -> null
}
requireNotNull(configFileName) { "Configuration not provided." }
fun <T> loadConfig(fileName: String, args: Array<String>, clazz: Class<T>, mapper: ObjectMapper? = null): T =
loadConfig(listOf(fileName), args, clazz, mapper)

@JvmOverloads
fun <T> loadConfig(fileNames: List<String>, args: Array<String>, clazz: Class<T>, mapper: ObjectMapper? = null): T {
val configFile = if (args.size == 1) Paths.get(args[0])
else fileNames.map { Paths.get(it) }.find { Files.exists(it) }
requireNotNull(configFile) { "Configuration not provided." }

val configFile = File(configFileName)
logger.info("Reading configuration from ${configFile.absolutePath}")
logger.info("Reading configuration from {}", configFile.toAbsolutePath())
try {
val localMapper = mapper ?: ObjectMapper(YAMLFactory())
.registerModule(KotlinModule())
return localMapper.readValue(configFile, clazz)
return Files.newInputStream(configFile).use { input ->
BufferedInputStream(input).use { bufInput ->
localMapper.readValue(bufInput, clazz)
}
}
} catch (ex: IOException) {
logger.error("Usage: <command> [$fileName]")
logger.error("Usage: <command> [$configFile]")
logger.error("Failed to read config file $configFile: ${ex.message}")
exitProcess(1)
}
Expand All @@ -63,7 +67,16 @@ object ConfigLoader {
* @throws IllegalArgumentException if a file matching configFileName cannot be found
*/
inline fun <reified T> loadConfig(fileName: String, args: Array<String>, mapper: ObjectMapper? = null): T =
loadConfig(fileName, args, T::class.java, mapper)
loadConfig(listOf(fileName), args, T::class.java, mapper)

/**
* Load a configuration from YAML file. The filename is searched in the current working
* directory. This exits with a usage information message if the file cannot be loaded.
*
* @throws IllegalArgumentException if a file matching configFileName cannot be found
*/
inline fun <reified T> loadConfig(fileNames: List<String>, args: Array<String>, mapper: ObjectMapper? = null): T =
loadConfig(fileNames, args, T::class.java, mapper)

/**
* Create a resourceConfig based on the provided resource enhancers. This method also disables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

package org.radarbase.jersey.exception.mapper

import com.fasterxml.jackson.core.util.BufferRecyclers
import com.fasterxml.jackson.core.io.JsonStringEncoder
import org.radarbase.jersey.exception.HttpApplicationException

/**
* Render an exception using a Mustache HTML document.
*/
class DefaultJsonExceptionRenderer: ExceptionRenderer {
override fun render(exception: HttpApplicationException): String {
val stringEncoder = BufferRecyclers.getJsonStringEncoder()
val stringEncoder = JsonStringEncoder.getInstance()
val quotedError = stringEncoder.quoteAsUTF8(exception.code).toString(Charsets.UTF_8)
val quotedDescription = exception.detailedMessage?.let {
'"' + stringEncoder.quoteAsUTF8(it).toString(Charsets.UTF_8) + '"'
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>
%-4relative [%thread] %-5level - %msg
%-4relative [%thread] %-5level - %msg%n
</pattern>
</encoder>
</appender>
Expand Down

0 comments on commit 958076f

Please sign in to comment.