I would like to enable validation parameters in JAX-RS
web service. I'm using JavaEE 6
, RestEasy 3.0.6.Final
and JBoss 7.1 Final
as Application Server.
I wrote this simple WS:
@Path("/accounts")
public interface MyWS {
@PUT
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ValidateRequest
public Response createUser(@Valid User request);
}
public class MyWsImpl implements MyWS {
private static Logger LOG = LogManager.getLogger(MyWsImpl.class);
@Override
public Response createUser(User request) {
LOG.info("doing");
return Response.status(200).build();
}
}
public class User {
@NotNull
@Size(min=4, max=50)
private String name;
@NotNull
private String surname;
...
}
Doing the request, server logs are:
17:21:05,324 INFO [stdout] (http--0.0.0.0-8080-2) 17:21:05.324 [http--0.0.0.0-8080-2] DEBUG [RS-WS-Invoke] - PUT (/accounts) - 127.0.0.1
17:21:05,355 INFO [stdout] (http--0.0.0.0-8080-2) annotation[0]: @javax.ws.rs.Path(value=/accounts)
17:21:05,373 INFO [stdout] (http--0.0.0.0-8080-2) 17:21:05.373 [http--0.0.0.0-8080-2] INFO it.prisma.businesslayer.bizws.paas.services.smsaas.MyWsImpl - doing
17:21:05,374 INFO [stdout] (http--0.0.0.0-8080-2) declaring class: interface it.prisma.businesslayer.bizws.paas.services.smsaas.MyWS
17:21:05,374 INFO [stdout] (http--0.0.0.0-8080-2) annotation[0]: @javax.ws.rs.Path(value=/accounts)
17:21:05,379 INFO [stdout] (http--0.0.0.0-8080-2) 17:21:05.379 [http--0.0.0.0-8080-2] DEBUG [RS-WS-Invoke-Response] - PUT (/accounts) - 127.0.0.1 - RESPONSE[Status:400, Time:55ms]
but I expect that a ValidationException
raise and that the code will be not executed.
What's wrong?
Thanks
Aucun commentaire:
Enregistrer un commentaire