Skip to content

Commit

Permalink
Merge pull request #46 from RADAR-base/release-0.6.1
Browse files Browse the repository at this point in the history
Release 0.6.1
  • Loading branch information
blootsvoets authored May 20, 2021
2 parents 02aa09c + 3c7b4e6 commit a6fdb46
Show file tree
Hide file tree
Showing 24 changed files with 251 additions and 120 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ jobs:
java-version: 11

- name: Cache
uses: actions/cache@v2.0.0
uses: actions/cache@v2
with:
# Cache gradle directories
path: |
~/.gradle/caches
~/.gradle/wrapper
# Key for restoring and saving the cache
key: ${{ runner.os }}-gradle
key: ${{ runner.os }}-gradle-${{ hashFiles("**/*.gradle.kts", "gradle.properties" }}
restore-keys: |
${{ runner.os }}-gradle-
# Compile the code
- name: Compile code
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/publish_snapshots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,23 @@ jobs:

- name: Has SNAPSHOT version
id: is-snapshot
run: grep "version =\\? \\?'.*-SNAPSHOT'" build.gradle
run: grep 'version = ".*-SNAPSHOT"' build.gradle.kts

- uses: actions/setup-java@v1
with:
java-version: 11

- name: Cache
uses: actions/cache@v2.0.0
uses: actions/cache@v2
with:
# Cache gradle directories
path: |
~/.gradle/caches
~/.gradle/wrapper
# Key for restoring and saving the cache
key: ${{ runner.os }}-gradle
key: ${{ runner.os }}-gradle-${{ hashFiles("**/*.gradle.kts", "gradle.properties" }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Install gpg secret key
run: |
Expand Down
16 changes: 9 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ jobs:
java-version: 11

- name: Cache
uses: actions/cache@v2.0.0
uses: actions/cache@v2
with:
# A list of files, directories, and wildcard patterns to cache and restore
path: |
~/.gradle/caches
~/.gradle/wrapper
# An explicit key for restoring and saving the cache
key: ${{ runner.os }}-gradle
# Cache gradle directories
path: |
~/.gradle/caches
~/.gradle/wrapper
# Key for restoring and saving the cache
key: ${{ runner.os }}-gradle-${{ hashFiles("**/*.gradle.kts", "gradle.properties" }}
restore-keys: |
${{ runner.os }}-gradle-
# Compile code
- name: Compile code
Expand Down
41 changes: 39 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ Library to facilitate using with a Jersey-based REST API. This includes OAuth 2.
Add this library to your project using the following Gradle configuration:
```gradle
repositories {
maven { url "https://dl.bintray.com/radar-base/org.radarbase" }
mavenCentral()
}
dependencies {
api("org.radarbase:radar-jersey:0.5.0")
api("org.radarbase:radar-jersey:0.6.1")
}
```

Expand Down Expand Up @@ -110,3 +110,40 @@ fun main(args: Array<String>) {
This package adds some error handling. Specifically, `org.radarbase.jersey.exception.HttpApplicationException` and its subclasses can be used and extended to serve detailed error messages with customized logging and HTML templating. They can be thrown from any resource.

To serve custom HTML error messages for error codes 400 to 599, add a Mustache template to the classpath in directory `org/radarbase/jersey/exception/mapper/<code>.html`. You can use special cases `4xx.html` and `5xx.html` as a catch-all template. The templates can use variables `status` for the HTTP status code, `code` for short-hand code for the specific error, and an optional `detailedMessage` for a human-readable message.

## Logging

To enable logging with radar-jersey, please set the following configurations. For new projects, the default should be Log4j 2. A configuration file is included in the classpath. First include the following dependencies:

```kotlin
dependencies {
// To enable logging either use log4j
val log4j2Version: String by project
runtimeOnly("org.apache.logging.log4j:log4j-slf4j-impl:$log4j2Version")
runtimeOnly("org.apache.logging.log4j:log4j-api:$log4j2Version")
runtimeOnly("org.apache.logging.log4j:log4j-jul:$log4j2Version")

}
```

Then before any other command is made, set:
```kotlin
// Initialize logging with log4j2
System.setProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager")
```
Execute this statement before ANY logging or logging initialization code has been called, for example in the `init` of a companion object of the main class. Alternatively, set it as a Java system property in the command line, i.e. `-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager`.

If Logback is used instead, import the following dependencies to gradle:

```kotlin
dependencies {
runtimeOnly("ch.qos.logback:logback-classic:1.2.3")
implementation("org.slf4j:jul-to-slf4j:1.7.30")
}
```

Then before any logging code has been called, set:
```kotlin
SLF4JBridgeHandler.removeHandlersForRootLogger()
SLF4JBridgeHandler.install()
```
44 changes: 27 additions & 17 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,32 @@ plugins {
`maven-publish`
signing
id("org.jetbrains.dokka") apply false
id("com.github.ben-manes.versions") version "0.36.0" apply false
id("io.github.gradle-nexus.publish-plugin") version "1.0.0"
id("com.github.ben-manes.versions") version "0.38.0"
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
}

fun isNonStable(version: String): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.toUpperCase().contains(it) }
val regex = "^[0-9,.v-]+(-r)?$".toRegex()
val isStable = stableKeyword || regex.matches(version)
return isStable.not()
}

allprojects {
group = "org.radarbase"
version = "0.6.0"
version = "0.6.1"

afterEvaluate {
tasks.withType<DependencyUpdatesTask> {
rejectVersionIf {
isNonStable(candidate.version)
}
}
}
}

subprojects {
apply(plugin = "kotlin")
apply(plugin = "maven-publish")
apply(plugin = "signing")
apply(plugin = "com.github.ben-manes.versions")
Expand All @@ -34,19 +50,6 @@ subprojects {
set("githubIssueUrl", githubIssueUrl)
}

fun isNonStable(version: String): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.toUpperCase().contains(it) }
val regex = "^[0-9,.v-]+(-r)?$".toRegex()
val isStable = stableKeyword || regex.matches(version)
return isStable.not()
}

tasks.named<DependencyUpdatesTask>("dependencyUpdates").configure {
rejectVersionIf {
isNonStable(candidate.version)
}
}

repositories {
mavenCentral()
// Temporary until Dokka is fully published on maven central.
Expand All @@ -57,6 +60,12 @@ subprojects {
dependencies {
val dokkaVersion: String by project
configurations["dokkaHtmlPlugin"]("org.jetbrains.dokka:kotlin-as-java-plugin:$dokkaVersion")

val log4j2Version: String by project
val testRuntimeOnly by configurations
testRuntimeOnly("org.apache.logging.log4j:log4j-slf4j-impl:$log4j2Version")
testRuntimeOnly("org.apache.logging.log4j:log4j-api:$log4j2Version")
testRuntimeOnly("org.apache.logging.log4j:log4j-jul:$log4j2Version")
}

val sourcesJar by tasks.registering(Jar::class) {
Expand Down Expand Up @@ -89,6 +98,7 @@ subprojects {
exceptionFormat = FULL
}
useJUnitPlatform()
systemProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager")
}

tasks.withType<Tar> {
Expand Down Expand Up @@ -191,5 +201,5 @@ nexusPublishing {
}

tasks.wrapper {
gradleVersion = "7.0"
gradleVersion = "7.0.2"
}
27 changes: 14 additions & 13 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,29 @@ org.gradle.jvmargs=-Xmx2000m
org.gradle.vfs.watch=true
kotlin.code.style=official

kotlinVersion=1.4.32
dokkaVersion=1.4.30
kotlinVersion=1.5.0
dokkaVersion=1.4.32

jerseyVersion=3.0.1
jerseyVersion=3.0.2
grizzlyVersion=3.0.0
okhttpVersion=4.9.1
junitVersion=5.7.1
junitVersion=5.7.2

hk2Version=2.6.1
managementPortalVersion=0.7.0
javaJwtVersion=3.12.0
managementPortalVersion=0.7.1
javaJwtVersion=3.16.0
jakartaWsRsVersion=3.0.0
jakartaAnnotationVersion=2.0.0
jacksonVersion=2.12.3
slf4jVersion=1.7.30
jakartaXmlBindVersion=3.0.0
jakartaJaxbCoreVersion=3.0.0
jakartaJaxbRuntimeVersion=3.0.0
log4j2Version=2.14.1
jakartaXmlBindVersion=3.0.1
jakartaJaxbCoreVersion=3.0.1
jakartaJaxbRuntimeVersion=3.0.1
jakartaActivation=2.0.1
swaggerVersion=2.1.7
swaggerVersion=2.1.9

hibernateVersion=5.4.30.Final
liquibaseVersion=4.3.3
postgresVersion=42.2.19
hibernateVersion=5.4.31.Final
liquibaseVersion=4.3.5
postgresVersion=42.2.20
h2Version=1.4.200
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 0 additions & 2 deletions radar-jersey-hibernate/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,4 @@ dependencies {
testImplementation("org.hamcrest:hamcrest-all:1.3")
val okhttpVersion: String by project
testImplementation("com.squareup.okhttp3:okhttp:$okhttpVersion")

testRuntimeOnly("ch.qos.logback:logback-classic:1.2.3")
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ import jakarta.ws.rs.ext.Provider

@Provider
class DatabaseInitialization(
@Context private val entityManagerFactory: jakarta.inject.Provider<EntityManagerFactory>,
@Context private val dbConfig: DatabaseConfig,
@Context private val entityManagerFactory: jakarta.inject.Provider<EntityManagerFactory>,
@Context private val dbConfig: DatabaseConfig,
) : ApplicationEventListener {

override fun onEvent(event: ApplicationEvent) {
logger.info("Application state: {}", event.type)
if (event.type != ApplicationEvent.Type.INITIALIZATION_APP_FINISHED) return
try {
entityManagerFactory.get().useEntityManager {
// make first connection
it.connection().use { connection ->
if (dbConfig.liquibase.enable) {
initializeLiquibase(connection)
}
// make first connection
it.connection().use { connection ->
if (dbConfig.liquibase.enable) {
initializeLiquibase(connection)
}
}
}
} catch (ex: Throwable) {
throw IllegalStateException("Cannot initialize database.", ex)
Expand All @@ -43,11 +43,13 @@ class DatabaseInitialization(
private fun initializeLiquibase(connection: Connection) {
logger.info("Initializing Liquibase")
val database = DatabaseFactory.getInstance()
.findCorrectDatabaseImplementation(
JdbcConnection(connection))
Liquibase(dbConfig.liquibase.changelogs, ClassLoaderResourceAccessor(), database).use {
it.update(null as Contexts?)
}
.findCorrectDatabaseImplementation(JdbcConnection(connection))

Liquibase(
dbConfig.liquibase.changelogs,
ClassLoaderResourceAccessor(),
database,
).use { it.update(null as Contexts?) }
}

override fun onRequest(requestEvent: RequestEvent?): RequestEventListener? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ internal class HibernateTest {
override fun writeTo(sink: BufferedSink) {
sink.writeUtf8("{\"name\": \"a\"}")
}

})
.url("http://localhost:9091/projects")
.build()).execute().use { response ->
Expand Down
2 changes: 0 additions & 2 deletions radar-jersey/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ dependencies {
val junitVersion: String by project
testImplementation("org.junit.jupiter:junit-jupiter:$junitVersion")
testImplementation("org.hamcrest:hamcrest-all:1.3")

testRuntimeOnly("ch.qos.logback:logback-classic:1.2.3")
}

tasks.processResources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ interface Auth {
get() = startsWith("logPermission")
|| startsWith("checkPermission")
|| startsWith("invoke")
|| startsWith("internal")

private val Class<*>.isAuthClass: Boolean
get() = isInstance(Auth::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import jakarta.ws.rs.ext.Provider
@Priority(Priorities.AUTHENTICATION)
@Singleton
class AuthenticationFilter(
@Context private val validator: AuthValidator
@Context private val validator: AuthValidator,
) : ContainerRequestFilter {

override fun filter(requestContext: ContainerRequestContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
import com.fasterxml.jackson.module.kotlin.KotlinModule
import io.swagger.v3.oas.models.OpenAPI
import io.swagger.v3.oas.models.info.Info
import org.glassfish.jersey.internal.inject.AbstractBinder
import org.glassfish.jersey.server.ResourceConfig
import org.radarbase.jersey.auth.AuthConfig
Expand Down Expand Up @@ -118,6 +117,7 @@ object ConfigLoader {
val health = HealthResourceEnhancer()
val httpException = HttpExceptionResourceEnhancer()
val generalException = GeneralExceptionResourceEnhancer()
val utility = UtilityResourceEnhancer()
fun swagger(openApi: OpenAPI, resourcePackages: Set<String>? = null) = SwaggerResourceEnhancer(openApi, resourcePackages)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import jakarta.inject.Singleton
class DisabledAuthorizationResourceEnhancer : JerseyResourceEnhancer {
override fun AbstractBinder.enhance() {
bind(DisabledAuthValidator::class.java)
.to(AuthValidator::class.java)
.`in`(Singleton::class.java)
.to(AuthValidator::class.java)
.`in`(Singleton::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import jakarta.inject.Singleton
class EcdsaResourceEnhancer : JerseyResourceEnhancer {
override fun AbstractBinder.enhance() {
bind(EcdsaJwtTokenValidator::class.java)
.to(AuthValidator::class.java)
.`in`(Singleton::class.java)
.to(AuthValidator::class.java)
.`in`(Singleton::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.radarbase.jersey.exception.mapper.WebApplicationExceptionMapper
/** Add WebApplicationException and any exception handling. */
class GeneralExceptionResourceEnhancer: JerseyResourceEnhancer {
override val classes: Array<Class<*>> = arrayOf(
UnhandledExceptionMapper::class.java,
WebApplicationExceptionMapper::class.java)
UnhandledExceptionMapper::class.java,
WebApplicationExceptionMapper::class.java,
)
}
Loading

0 comments on commit a6fdb46

Please sign in to comment.