Skip to content

Commit 4357833

Browse files
committed
Polish
1 parent 9acdca4 commit 4357833

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

router-protobuf/src/main/kotlin/com/github/mduesterhoeft/router/proto/ProtoDeserializationHandler.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import com.github.mduesterhoeft.router.contentType
66
import com.google.common.net.MediaType
77
import com.google.protobuf.Parser
88
import java.util.Base64
9+
import kotlin.reflect.KClass
910
import kotlin.reflect.KType
11+
import kotlin.reflect.full.staticFunctions
1012

1113
class ProtoDeserializationHandler : DeserializationHandler {
1214
private val proto = MediaType.parse("application/x-protobuf")
@@ -16,7 +18,7 @@ class ProtoDeserializationHandler : DeserializationHandler {
1618

1719
override fun deserialize(input: APIGatewayProxyRequestEvent, target: KType?): Any {
1820
val bytes = Base64.getDecoder().decode(input.body)
19-
val parser = target.staticFunctions.first { it.name == "parser" }.call() as Parser<*>
21+
val parser = (target?.classifier as KClass<*>).staticFunctions.first { it.name == "parser" }.call() as Parser<*>
2022
return parser.parseFrom(bytes)
2123
}
2224
}

router/src/main/kotlin/com/github/mduesterhoeft/router/RequestHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ abstract class RequestHandler : RequestHandler<APIGatewayProxyRequestEvent, APIG
2222
private val deserializationHandlerChain by lazy { DeserializationHandlerChain(deserializationHandlers()) }
2323

2424
@Suppress("UNCHECKED_CAST")
25-
override fun handleRequest(input: APIGatewayProxyRequestEvent, context: Context): APIGatewayProxyResponseEvent? {
25+
override fun handleRequest(input: APIGatewayProxyRequestEvent, context: Context): APIGatewayProxyResponseEvent {
2626
log.debug("handling request with method '${input.httpMethod}' and path '${input.path}' - Accept:${input.acceptHeader()} Content-Type:${input.contentType()} $input")
2727
val routes = router.routes as List<RouterFunction<Any, Any>>
2828
val matchResults: List<RequestMatchResult> = routes.map { routerFunction: RouterFunction<Any, Any> ->

router/src/test/kotlin/com/github/mduesterhoeft/router/RequestHandlerTest.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class RequestHandlerTest {
1919
.withPath("/some")
2020
.withHttpMethod("GET")
2121
.withHeaders(mapOf("Accept" to "application/json")), mockk()
22-
)!!
22+
)
2323

2424
assert(response.statusCode).isEqualTo(200)
2525
assert(response.body).isEqualTo("""{"greeting":"Hello"}""")
@@ -33,7 +33,7 @@ class RequestHandlerTest {
3333
.withPath("/some/me")
3434
.withHttpMethod("GET")
3535
.withHeaders(mapOf("Accept" to "application/json")), mockk()
36-
)!!
36+
)
3737

3838
assert(response.statusCode).isEqualTo(200)
3939
assert(response.body).isEqualTo("""{"greeting":"Hello me"}""")
@@ -47,7 +47,7 @@ class RequestHandlerTest {
4747
.withPath("/some")
4848
.withHttpMethod("GET")
4949
.withHeaders(mapOf("Accept" to "img/jpg")), mockk()
50-
)!!
50+
)
5151

5252
assert(response.statusCode).isEqualTo(406)
5353
}
@@ -63,7 +63,7 @@ class RequestHandlerTest {
6363
"Accept" to "application/json",
6464
"Content-Type" to "image/jpg"
6565
)), mockk()
66-
)!!
66+
)
6767

6868
assert(response.statusCode).isEqualTo(415)
6969
}
@@ -78,7 +78,7 @@ class RequestHandlerTest {
7878
"Content-Type" to "application/json"
7979
))
8080
.withBody("""{ "greeting": "some" }"""), mockk()
81-
)!!
81+
)
8282

8383
assert(response.statusCode).isEqualTo(200)
8484
assert(response.body).isEqualTo("""{"greeting":"some"}""")
@@ -94,7 +94,7 @@ class RequestHandlerTest {
9494
"Content-Type" to "application/json"
9595
))
9696
.withBody("""[{ "greeting": "some" },{ "greeting": "some1" }]""".trimMargin()), mockk()
97-
)!!
97+
)
9898

9999
assert(response.statusCode).isEqualTo(200)
100100
assert(response.body).isEqualTo("""[{"greeting":"some"},{"greeting":"some1"}]""")
@@ -111,7 +111,7 @@ class RequestHandlerTest {
111111
"Accept" to "application/json",
112112
"Content-Type" to "image/jpg"
113113
)), mockk()
114-
)!!
114+
)
115115

116116
assert(response.statusCode).isEqualTo(405)
117117
}
@@ -124,7 +124,7 @@ class RequestHandlerTest {
124124
.withPath("/some-other")
125125
.withHttpMethod("GET")
126126
.withHeaders(mapOf("Accept" to "application/json")), mockk()
127-
)!!
127+
)
128128

129129
assert(response.statusCode).isEqualTo(404)
130130
}
@@ -138,7 +138,7 @@ class RequestHandlerTest {
138138
.withPath("/some")
139139
.withHttpMethod("GET")
140140
.withHeaders(mapOf("Accept" to "application/json")), mockk()
141-
)!!
141+
)
142142

143143
assert(response.statusCode).isEqualTo(200)
144144
assert(handler.filterInvocations).isEqualTo(2)
@@ -156,7 +156,7 @@ class RequestHandlerTest {
156156
)
157157
)
158158
.withBody("{}"), mockk()
159-
)!!
159+
)
160160
assert(response.statusCode).isEqualTo(422)
161161
}
162162

@@ -168,7 +168,7 @@ class RequestHandlerTest {
168168
.withPath("/some-api-exception")
169169
.withHttpMethod("GET")
170170
.withHeaders(mapOf("Accept" to "application/json")), mockk()
171-
)!!
171+
)
172172

173173
assert(response.statusCode).isEqualTo(400)
174174
}
@@ -181,7 +181,7 @@ class RequestHandlerTest {
181181
.withPath("/some-internal-server-error")
182182
.withHttpMethod("GET")
183183
.withHeaders(mapOf("Accept" to "application/json")), mockk()
184-
)!!
184+
)
185185

186186
assert(response.statusCode).isEqualTo(500)
187187
}

0 commit comments

Comments
 (0)