tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ChrisChristo <>
Subject Re: JAX-RS + Bean Validation
Date Thu, 06 Feb 2014 13:18:24 GMT
Wow, that actually worked. Thanks.

So for anyone else wanting to use the @Valid on their method params simply
add the following property to your system properties.

org.apache.openejb.default.system.interceptors =

And then your jax-rs methods can be of the following (note that you don’t
need the @ValidateRequest):

public Coffee bounce(@Valid Coffee coffee) {
	return coffee;

If the Coffee bean sent has any violations (such as a field within being
null when a @NotNull annotation is brandished) then a
javax.validation.ConstraintViolationException will be thrown.

Simply pick that up by your exception mapper and do what you want with it,
so something along the lines of:

public class MyExceptionMapper implements ExceptionMapper<Exception> {
	if (ex instanceof ConstraintViolationException) { 
		// return back nice json

(here ExceptionResponse is my own custom class for representing exceptions
in a nice format back to the caller).

Remember to add your MyExceptionMapper to your system properties also:

"cxf.jaxrs.providers": “my.package.MyExceptionMapper”

If you use openejb.json (in conf/openejb.json) or resources.json (in
project’s resources/META-INF/resources.json) then you can add the two
properties like so:

resources.json/open.json :

	"system-properties": {
		"cxf.jaxrs.providers": “my.package.MyExceptionMapper",
	// other stuff….

(The LoggingFeature is to log the requests and responses in a pretty format,
thank me later :P)

Hope this helps someone in the future.

Thanks again Romain,


View this message in context:
Sent from the OpenEJB User mailing list archive at

View raw message