2012-08-02 77 views
0

除了下面的方法之外,是否还有其他任何方式来验证查询参数值,即是否有通过映射到wadl的模式的Jersey方法。谢谢验证查询参数值球衣

@Path("smooth") 
@GET 
public Response smooth(
    @DefaultValue("blue") @QueryParam("min-color") ColorParam minColor, 

public class ColorParam extends Color { 
public ColorParam(String s) { 
    super(getRGB(s)); 
} 

private static int getRGB(String s) { 
    if (s.charAt(0) == '#') { 
     try { 
      Color c = Color.decode("0x" + s.substring(1)); 
      return c.getRGB(); 
     } catch (NumberFormatException e) { 
      throw new WebApplicationException(400); 

回答

1

不幸的是,当前JAX-RS版本的验证支持有限。但根据draft for JAX-RS 2.0,未来将有更好的验证处理。

您可以看到新功能here的示例。