Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jaxrs-dev] Integrating JAX-RS, CDI and bean validation



On Feb 28, 2018, at 3:01 AM, Niklas Mehner <niklas.mehner@xxxxxxxxx> wrote:

@Stateless
public class Hello {
  public String sayHello(@NotEmpty String name) {
    return "Hello " + name;
  }
}

this bean is being validated using the global message intercepter according to the CDI specification (if I understand the spec correctly).
If we now add a Path:

@Stateless
@Path("hello")
public class Hello {
  @GET
  public String sayHello(@NotEmpty String name) {
    return "Hello " + name;
  }
}

Then we suddenly get a validation using the "jax-rs"-Validation? Does this not violate the CDI specification since Hello is still a CDI bean? 

 This is the tricky part of combining specs. The moment you decorate the bean with @Path, then JAX-RS becomes the owner, so to speak. Clearly, the bean is not just CDI anymore as it includes a number of annotations and possibly injections (via @Context) that are JAX-RS specific. Backward compatibility has forced JAX-RS to continue to support its own injection via @Context even after CDI.

 Unfortunately, I’m not sure if there is an elegant way to support this use case at the moment (and I think the reason why this was brought up in the context of MVC), but we should definitely make this a high priority. 

 I’m not sure what’s the best solution yet, but if is using a ValidatorFactory, then perhaps a ContextResolver could be used just like for a JAXBContext as a way to configure the runtime.

— Santiago


 

Back to the top