0

I am creating a very basic controller using Kotlin with javax.ws and retrofit libraries.

I created a controller like this...

@POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    suspend fun sayHello(request: StudentRequest): StudentResponse {

that basically calls another service.

But when I run the app I get this error:

[FATAL] Method public final java.lang.Object MyResource.sayHello(StudentRequest,kotlin.coroutines.Continuation) on resource class MyResource contains multiple parameters with no annotation. Unable to resolve the injection source.;


handlerConstructors=[org.glassfish.jersey.server.model.HandlerConstructor@a0bf272]},
 definitionMethod=public final java.lang.Object my.org.package.MyResource(sayHello,k**otlin.coroutines.Continuation**), 

the weird part is that are couple of similar posts Jersey @PathParam : contains multiple parameters with no annotation

How can I pass multiple parameter to restful webservice using http post

https://github.com/dropwizard/dropwizard/issues/1115

but are not the same because my problem is with my ONLY parameter

There is no missing tag to my body request and I basically dont know what to look for at this point, any idea what could be wrong with this?

After debugging I noticed that there are two parameters, mine and one injected by Kotlin, when removing the "suspend" everything works fine, but then I am not able to make my async call.

jpganz18
  • 5,508
  • 17
  • 66
  • 115
  • I'm not sure that you will profit from making controller method suspendable (as it's called from the framework that doesn't know how to handle coroutines). What actual behavior are you trying to achieve? – Denys P. Jul 02 '19 at 09:57

1 Answers1

1

To use coroutines from blocking code you need to use coroutine builder (e.g. launch {} or runBlocking {}).

Unfortunately in this case you can't just mark your glassfish controller as a suspendable function because framework don't know how to deal with continuations.

Denys P.
  • 266
  • 4
  • 11