Please can someone with JAX-RS and Kotlin have a l...
# server
h
Please can someone with JAX-RS and Kotlin have a look at this question: https://stackoverflow.com/q/54674096/9506917
s
first thing that comes to mind, maybe try adding a leading slash to your
@Path
argument on the get endpoint?
also I’d annotate the class itself with `@Produces(MediaType.APPLICATION_JSON)`if all your endpoints return JSON, but that’s a side observation not related to your path problems
oh, wait, I misread what you wrote
your
POST
endpoint is likely being called but 500ing because you probably don’t have anything set up to deserialize the json blob to
String
h
okay
ohh
so i may have to use jacksonmapper??
s
or something similar, yes
what’s the stack trace on the server side look like?
h
there's no stack trace as I can't run it in debug mode
it just says
Copy code
> Task :run 
Feb 13, 2019 4:02:25 PM org.glassfish.grizzly.http.server.NetworkListener start
INFO: Started listener bound to [0.0.0.0:8080]
Feb 13, 2019 4:02:25 PM org.glassfish.grizzly.http.server.HttpServer start
INFO: [HttpServer] Started.
Press any key to shutdown
<==========---> 80% EXECUTING [27s]
> :run
s
Well, there should still be something in the logs, I think
also why can’t you run it in debug mode?
weird
h
when I call the GET
i get this
Copy code
Feb 13, 2019 4:03:16 PM org.glassfish.jersey.logging.LoggingInterceptor log
INFO: 2 * Server has received a request on thread grizzly-http-server-1
2 > GET <http://localhost:8080/myresource/test123>
2 > accept: */*
2 > host: localhost:8080
2 > user-agent: curl/7.54.0

Feb 13, 2019 4:03:16 PM org.glassfish.jersey.logging.LoggingInterceptor log
INFO: 2 * Server responded with a response on thread grizzly-http-server-1
2 < 200
2 < Content-Type: application/json
hello
so it seems like POST does not even reach my server???
s
No, this seems like a failure of the logging configuration.
do you have logback or anything configured? or maybe you could run your application without using gradle?
It doesn’t seem useful to you to suppress stack traces
h
wait a sec
maybe i need to create a data class to represent this json?
Copy code
{"message": "foo"}'
s
that is what most folks do, yes
h
would
Message(message: String)
do??
s
if you’re using Jackson, the kotlin mapper can automagically deserialize data classes for you
t
while you’re testing, just accept a
Map<Any, Any>
Jackson also has a
KotlinModule
you will need to register
It’s in
jackson-module-kotlin
h
did you mean change my function to
fun createMessage(testPost: Map<Any, Any>)
?
that didnt worked
just tried it
let me try jacksonmapper
j
also you seem to be accepting/producing raw strings right now, does it work with MediaType.PLAIN_TEXT? -- jersey doesn't particularly support raw strings as json, so either label strings as plain text or return json-able entity classes is best
h
not working still, even with Plain text
I was just following this exact same repo and changed just this class: https://github.com/baens/blog-step-by-step-jaxrs/blob/master/src/jaxrs/resources/HelloWorld.kt
problem still the same even after i simplified my POST function to this @Joe
Copy code
@POST
    @Consumes(MediaType.TEXT_PLAIN)
    @Produces(MediaType.TEXT_PLAIN)
    fun createMessage(message: String): Response {
        return Response.status(200).entity("test").build()
    }
it just seems like its not reaching my server at all
okay I got a 200 after sending a POST with no data like this
Copy code
curl -v -X POST \
  <http://localhost:8080/messages> \
  -H 'Content-Type: application/json'
decided to moved to spring in the end. much easier
s
shrug
fwiw I’ve been pretty happy using Dropwizard and Kotlin together
👆 1
j
yeah, i keep meaning to look @ ktor, but having much success w/ dropwizard already
t
Yeah, we use DW + kotlin extensively