2012-08-02 76 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的示例。