1

I want to be able to do something like this:

@GET
@Path("test")
public Response someMethod(@Context MyCustomContext myCustomContext) {
 ...
}

I found this old stack overflow post that describes different methods for doing this here: Using @Context, @Provider and ContextResolver in JAX-RS. I implemented the top answer (which is implementation agnostic) and got it to work, but it didn't do exactly what I want. Instead it looked this:

@GET
@Path("test")
public Response someMethod(@Context Providers providers) {
        ContextResolver<MyCustomContext> p = providers.getContextResolver(MyCustomContext.class, MediaType.WILDCARD_TYPE);
        MyCustomContext myCustomContext = p.getContext(null);
       ... 
}

There were some other solutions on that post, but they were implementation dependent. I noticed in the quarkus docs that there was a section on custom contexts that can be found here: https://quarkus.io/guides/cdi-reference#synthetic-beans, but this is specific for extensions. Does anyone have ideas on how to do this in a quarkus project?

jsolum
  • 196
  • 2
  • 15
  • Any solution is going to be (JAX-RS) implementation specific. – Paul Samsotha Jun 13 '19 at 09:50
  • You're right. I think I came up with a solution I like though. I ended up using `ResteasyContext`. So what I did was put `ResteasyContext.pushContext(User.class, currentUser);` into a jaxrs filter, which allowed me to do `@Context User currentUser`. – jsolum Jun 15 '19 at 03:52

0 Answers0