我想在JAX-RS
网络服务中启用验证参数。我使用JavaEE 6
,RestEasy 3.0.6.Final
和JBoss 7.1 Final
作为Application Server。
我写了这个简单的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;
...
}
执行请求时,服务器日志为:
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]
但我希望ValidationException
加注并且代码不会被执行。
出了什么问题?
由于