2014-12-03 3 views
3

다음 URL을 사용하십시오.JAX-RS로 전체 하위 경로를 얻으려면 어떻게해야합니까?

http://doma.in/context/resource/some/.../undefined 

나는 /some/.../undefined

@Path("/resource") 
class Response Resource { 
    final String path; // "/some/.../undefined" 
} 

감사 인 ../resource 후 경로 이름을 싶어.

UPDATE

대답 등의 방법이있다 할 것입니다. 내가

http://.../context/resource/paths/a/b/c 

를 호출 할 때

@Path("/resource") 
class class Resource { 

    @Path("/{paths: .+}") 
    public String readPaths() { 
     final String paths 
      = uriInfo.getPathParameters().getFirst("paths"); 
    } 

    @Context 
    private UriInfo uriInfo; 
} 

나는

a/b/c 

를 얻을.

답변

3

모든 URI 정보는 UriInfo에서 가져올 수 있습니다.이 정보는 @Context 주석을 사용하여 필드 또는 메소드 매개 변수로 삽입 할 수 있습니다.

public Response getResponse(@Context UriInfo uriInfo) { 
} 

-- OR -- 

@Context 
private UriInfo uriInfo; 
  • 당신은 당신은 UriInfo.getPath()에서 기본 URI에 상대 경로를 얻을 수 있습니다 UriInfo.getAbsoultePath()

    http://doma.in/context/resource/some/somthingelse/undefined 
    
  • 으로 절대 요청 경로를 얻을 수 있습니다.

    /resource/some/somthingelse/undefined 
    
  • UriInfo.getPathSegments() 패스 세그먼트 목록 (슬래쉬 사이의 각 부분이 경로 세그먼트) 얻을 수있다. 다음은 example usage입니다.

URI를 읽는 데 사용할 수있는 여러 가지 방법이 있습니다. 위에 링크 된 API를 살펴보십시오.

관련 문제