Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![Build Status](https://travis-ci.org/tyntec/ktor-problem.svg?branch=master)](https://travis-ci.org/tyntec/ktor-problem)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://raw.githubusercontent.com/zalando/problem/master/LICENSE)

Feature for [Ktor](https://ktor.io) implementing [Rfc7807](https://tools.ietf.org/html/rfc7807)
Plugin for [Ktor](https://ktor.io) implementing [Rfc7807](https://tools.ietf.org/html/rfc7807)

It is inspired by Zalando's [Problem](https://github.com/zalando/problem) library.

Expand Down
29 changes: 16 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
plugins {
kotlin("jvm") version "1.4.21"
id("org.jetbrains.dokka") version "0.9.18"
id("io.gitlab.arturbosch.detekt") version "1.15.0"
kotlin("jvm") version "1.8.0"
id("org.jetbrains.dokka") version "1.7.20"
id("io.gitlab.arturbosch.detekt") version "1.22.0"
`maven-publish`
signing
}

group = "com.tyntec"
version = "0.8"
version = "0.8.1"

val ktorVersion = "1.5.0"
val ktorVersion = "2.2.2"
val jacksonVersion = "2.12.0"
val junitVersion = "5.4.2"
val ossUsername: String? by project
val ossPassword: String? by project

detekt {
input = files("src/main/kotlin")
source = files("src/main/kotlin")
config = files("config/detekt/config.yml")
}

repositories {
jcenter()
mavenCentral()
mavenLocal()
}

dependencies {
implementation(ktor("jackson"))
implementation(ktor("gson"))
implementation(ktor("serialization-jackson"))
implementation(ktor("serialization-gson"))
implementation(ktor("client-content-negotiation"))
implementation(kotlin("stdlib-jdk8"))

detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.22.0")

api(ktorServer("core"))
testImplementation(ktorServer("tests"))
testImplementation("com.willowtreeapps.assertk:assertk-jvm:0.17")
testImplementation(junit("api"))
testImplementation(junit("params"))
testRuntime(junit("engine", "5.3.2"))
testImplementation(junit("engine", "5.3.2"))
}

fun DependencyHandler.ktor(module: String, version: String = ktorVersion): Any =
Expand Down Expand Up @@ -62,8 +65,8 @@ tasks.register<Jar>("sourcesJar") {
}

tasks.register<Jar>("javadocJar") {
dependsOn("dokka")
from(tasks["dokka"])
dependsOn("dokkaHtml")
from(tasks["dokkaHtml"])
archiveClassifier.set("javadoc")
}

Expand Down
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
kotlin.code.style=official
ktorVersion=1.5.0
kotlin_version=1.3.41
ktorVersion=2.2.2
kotlin_version=1.8.0
org.gradle.jvmargs=-XX:MaxMetaspaceSize=512m
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
Binary file not shown.
Binary file removed out/test/classes/META-INF/ktor-problem.kotlin_module
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main/kotlin/com/tyntec/ktor/problem/ProblemContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.tyntec.ktor.problem

import io.ktor.application.ApplicationCall
import io.ktor.server.application.ApplicationCall

/**
* Container class available when exception based configuration is used.
Expand Down
24 changes: 12 additions & 12 deletions src/main/kotlin/com/tyntec/ktor/problem/RFC7807Problems.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
package com.tyntec.ktor.problem

import com.tyntec.ktor.problem.ExceptionLogLevel.*
import io.ktor.application.*

import io.ktor.content.TextContent
import io.ktor.http.ContentType
import io.ktor.http.HttpStatusCode
import io.ktor.http.content.OutgoingContent
import io.ktor.request.httpMethod
import io.ktor.request.path
import io.ktor.response.ApplicationSendPipeline
import io.ktor.response.respond
import io.ktor.server.application.*
import io.ktor.server.request.*
import io.ktor.server.response.*

import io.ktor.util.AttributeKey
import io.ktor.util.pipeline.PipelineContext

Expand Down Expand Up @@ -98,31 +98,31 @@ class RFC7807Problems(configuration: Configuration) {
}
}

companion object Feature : ApplicationFeature<ApplicationCallPipeline, Configuration, RFC7807Problems> {
companion object Plugin : BaseApplicationPlugin<ApplicationCallPipeline, Configuration, RFC7807Problems> {
override val key = AttributeKey<RFC7807Problems>("Problems")

override fun install(pipeline: ApplicationCallPipeline, configure: Configuration.() -> Unit): RFC7807Problems {

val configuration = Configuration().apply(configure)

val feature = RFC7807Problems(configuration)
val plugin = RFC7807Problems(configuration)

if (feature.enableAutomaticResponseConversion)
if (plugin.enableAutomaticResponseConversion)
pipeline.sendPipeline.intercept(ApplicationSendPipeline.After) { message ->
feature.interceptResponse(this, message)
plugin.interceptResponse(this, message)
}

pipeline.intercept(ApplicationCallPipeline.Monitoring) {
try {
proceed()
} catch (e: Throwable) {
feature.interceptExceptions(this, call, e)
plugin.interceptExceptions(this, call, e)
}
}
pipeline.intercept(ApplicationCallPipeline.Fallback) {
feature.notFound(call)
plugin.notFound(call)
}
return feature
return plugin
}
}

Expand Down
Loading