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

Hi Christian,


So what I'd like to achieve is to implement a validation message interpolator that uses the locale from the JAX-RS Headers (HelloResource.java). But since the message interpolator is global in the application it has to work for servlet requests and outside of request processing as well (TestServlet.java / SomeSingleton.java).

Why is the message interpolator global? Basically it would be possible for JAX-RS implementations or application developers to build a custom ValidatorFactory.

Well that exactly is my question: Can we actually use a different validator? Probably I haven't stated the problem I am seeing in an understandable way:

If we have a session bean:

@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?

And if we decide to separate my validation from the resource:

@Path("hello")
public class HelloResource {

  @Inject
  private Hello hello;

  @GET
  public String sayHello(String name) {
    return hello.sayHello(name);
  }
}

then we suddenly get a validation messages in a different language since the CDI validation is active again?
As a developer I'd find this change in behavior quite unexpected.

Best regards,
  Niklas


Back to the top