[펌글] jax-rs 어노테이션 목록

By | 1월 28, 2011

- 출처 : http://blog.daum.net/pieea/5565755 -

@Path – Path annotation value is a relative URI path to the resource. A resource class must have this annotation either at the class level or for the methods defined in the resource class. The annotation also provides the facility for embedding variables and creating URI path templates. 
=> URI와 서비스를 맵핑시켜서 원하는 서비스로 찾아가도록 한다. (필수)

@Consumes – This annotation specifies the media types that the methods of a resource class can accept. It’s an optional one and by default, the container assumes that any media type is acceptable. This annotation can be used to filter the requests sent by the client. On receiving request with wrong media type, sever throws an error to the client. 
=> 원하는 미디어타입의 요청만 수용하도록 필터링한다. (요청받는 미디어타입에 제한을 건다) (선택적)
     지정하지 않을 경우 모든 미디어타입의 요청을 수용할 수 있다.

@Produces
 – This annotation defines the media types that the methods of a resource class can produce. Like @Consumes annotation, this is also optional and by default the container assumes that any media type can be sent back to the client.
=> 원하는 미디어타입만 리턴하도록 제한한다. (선택적)
     지정하지 않을 경우 모든 미디어타입을 리턴할 수 있다.

Jersey also provides annotations to specify the request methods and supports 5 methods. They are:

@GET – This is request method designator corresponding to HTTP GET method. Any java method annotated with this will process HTTP GET requests.

@POST – This is request method designator corresponding to HTTP POST method. Any java method annotated with this will process HTTP POST requests.

@PUT – This is request method designator corresponding to HTTP PUT method. Any java method annotated with this will process HTTP PUT requests.

@DELETE – This is request method designator corresponding to HTTP DELETE method. Any java method annotated with this will process HTTP DELETE requests.

@HEAD – This is request method designator corresponding to HTTP HEAD method. Any java method annotated with this will process HTTP HEAD requests.

@HttpMethod – This annotation is another way of specifying HTTP request method. The annotation takes a value which can be any of supported HTTP request method.

Example:

HttpMethod(“GET”)
Public String getUserName() {
return username;
}

@DefaultValue – The DefaultValue annotation is used to define default values of request metadata. The annotation is bound to be used along with PathParam, QueryParam, MatrixParam, CookieParam, FormParam, or HeaderParam annotations. The defaultValue is used if corresponding metadata is not available with the request. 

@Context – The Context annotation is used to inject information into a variable or method parameter. Using this annotation, you will be able to inject information like Request, URI information etc.

To extract information from URL,request hearders etc, Jersey provide a set of annotations that make extracting data very simple. They are:

@PathParam – The PathParam annotation is used to extract parameters from the resource URL. URI path parameters are extracted from the request URI, and the parameter names correspond to the URI path template variable names specified in the @Path class-level annotation.

@QueryParam – This annotation is used to extract parameters from URL query parameters. It is mostly used in conjunction with HTTP GET method. When using GET method to send data, the parameters and values are encoded into the URL. QueryParam is used to extract these values and assign them to the appropriate variables.

@FormParam – This annotation is used to extract parameters from a form submission. It is used in conjunction with HTTP POST method.
=> request body 에 데이터를 실어보낼 경우 (payload) 사용한다.

@CookieParam – Like above mentioned parameter extraction annotations, CookieParam is used to extract values form a cookie.

@HeaderParam – This annotation is used to extract parameters from HTTP header.

@MatrixParam – This annotation is used to extract parameters from matrix URI. You can learn more about matrix URI here.

@Provider – This annotation is used to mark the implementation of an extension interface. 

@Encoded – This annotation is used to disable automatic decoding of parameter values. Is this annotation on a method will disable decoding for all parameters. 
=> 파라미터들이 자동으로 디코딩되는 것을 막는다.


Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments