2012-08-02 3 views
0

아래에 다른 방법 외에 쿼리 매개 변수 값의 유효성을 검사하는 방법이 있습니까? 즉, wadl을 통해 스키마에 매핑하여 저지 방법이 있습니까? 고맙습니다.queryparam 값 저지의 유효성 검사

@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의 예를 볼 수 있습니다.