Web Service 9

Jersey의 JSON Support

Jersey에서 JSON을 지원하는 방법은 두가지가 있다. * JAXB Based JSON support * Low-Level JSON support 일단, JAXB 기반의 JSON 지원하는 방법을 알아보면, JSON하고 XML data format을 쉽게 produce/consume하면 시간절약을 할 수 있다. 왜냐면 Java model, JAXB를 이용한 annotated된 POJO를 쓰기때문에 쉽게 핸들링할 수 있다. 자바 모델에 @XmlRootElement 어노테이션을 붙여주고 간단한 몇가지 작업을 해주면~ 큰 노력하지 않고 JSON을 지원할 수 있다. 단점은 매우 특별한 JSON format을 처리할 때 좀 어렵다는거.옵션을 줘야한다. 참고 : Jersey 1.0에서 RESTful 웹 서비스용 ..

backend 2009.06.08

Jersey의 Exception Handling

Jersey에서는 WebApplicationException 클래스를 이용하여 Exception Handling한다. WebApplicationException을 잡아야 하고, 예외를 Response로 매핑한다. 예외를 위한 response가 null이 아니면 응답을 생성, null이면 서버 오류 응답을 생성 런타임 예외나 미리감지되는 예외(checked exception) 기호에 따라 사용 미리 감지되지 않는 예외나 오류는 컨테이너 안쪽까지 전파가 되도록 예외를 다시 던져야(re-thrown) 한다. 미리 감지되는 예외나 throwable 은 직접 예외를 던지지 말고, 서블릿인 경우은 ServletException으로, JAX-WS Provider 기반인 경우는 WebServiceException으로 ..

backend 2009.06.05

Jersey의 Return Type

Jersey에서 사용할 수 있는 Return Type에는 void Response GenericEntity Java Type 네가지 타입이 있다. void : 204 status code (성공. message body가 empty) Response : null 리턴 값은 204 status code. GenericEntity / Other : 리턴값이 null이 아니면 200 status code를 사용하고 null이면 204 status code를 사용한다. Response의 instance에 어떤 metadata를 추가적으로 제공하고 싶으면 ResponseBuilder를 쓰면 된다. (ResponseBuilder는 빌더 패턴을 사용해 Response 인스턴스를 생성 한다.)

backend 2009.06.04

Jersey의 MessageBodyReader/Writer

JAX-RS는 MessageBodyReader와 MessageBodyWriter를 통해 HTTP 메세지 바디와 자바 타입간의 마샬링과 언마샬링을 해준다. MessageBodyReader의 생긴 모습을 보면, (이 인터페이스를 구현하여 원하는 모습의 자바타입 객체로 변신시킬 수 있다.) public interface MessageBodyReader { boolean isReadable(Class type, Type genericType, Annotation annotations[], MediaType mediaType); T readFrom(Class type, Type genericType, Annotation annotations[], MediaType mediaType, MultivaluedMap h..

backend 2009.06.03

JAX-RS의 구성

1. Root Resource Classes * 웹 리소스을 구현하기 위해 JAX-RS 어노테이션을 사용하는 자바 클래스 적어도 하나의 메소드에 @Path을 사용한 POJO Root resource class들은 JAX-RS runtime에 인스턴스화된다. @Path 어노테이션이 달린 Resource 클래스 @Path("/hi") public class HiResource { @GET @Produces("text/plain") public String getAsText() { return "Hi! buri. Show Text."; } 2. Resource Methods @GET @POST @PUT @DELETE @HEAD * URI Templates @Path annotation의 값은 상대 경로 URI..

backend 2009.06.01

What is Jersey?

구글에서 "Jersey"를 치면 제일 처음으로 Map에서 저지섬이 나오고 두번째 링크로는 역시 위키피디아의 저지섬이 나온다. 세번째 링크가 되어서야 내가 원하는 jersey 공식 홈페이지가 나온다. Jersey는 SUN에서 개발하는 REST 방식의 웹 어플리케이션을 지원하는 JAX-RS의 구현체의 이름이다. Jersey is the open source (under dual CDDL+GPL license), production quality, JAX-RS (JSR 311) Reference Implementation for building RESTful Web services. But, it is also more than the Reference Implementation. Jersey provides..

backend 2009.06.01

What is JAX-RS?

JAX-RS(Java™ API for RESTful Web Services)는 자바 플랫폼에서 경량화된 REST 방식의 웹 애플리케이션 구현을 지원하는 자바 API이다. SOAP기반의 SOA 연동은 자바 애플리케이션을 무겁게 한다는 비판과 함께, 최근 웹 애플리케이션의 경향인 AJAX기반으로 JSON이나 RSS와 같이 간결한 프로토콜을 사용한 연동이 보편화되면서 쉽게 구현할 수 있도록 Java EE에 JAX-RS 라는 사양이 포함되고 있다. (출처 : http://ko.wikipedia.org/wiki/JAX-RS) 2008년 10월에 JSR 311 1.0 released 되었고 2009년 5월 현재는 JSR 311 1.1 draft 상태이다. Open source 구현체로는 Jersey Restlets..

backend 2009.05.29

What is REST?

REST는 2000년도에 Roy Fielding의 박사학위 논문에서 네트워크 시스템의 구조적 형식(architecture style)을 설명하기 위해 만들어진 용어이다. 최근도 아니고 이미 뜰만큼 뜬 REST에 대해 정리해보자. 정의 REST stands for "REpresentational State Transfer" REST is an architecture style not a standard : REST는 비표준 아키텍쳐 스타일 Data and Service are represented by unique URI : unique한 URI를 통해 Data와 Service를 표현한다. 특징 Addressable Resources Every "thing" should have a URI Stateles..

backend 2009.05.27

SOA와 Web Service

아직은 아키텍쳐에 관심이 많이는 없었지만 특별한 기회에 접하게 되었다. SOA란 말, SOAP, REST, WEB SERVICE에 대해 세미나에서 듣기만 해보았고, 정확히 어떤 말인지 잘은 몰랐지만, 한번 정리해보려고 한다. 1) SOA의 기본 개념 표준화, 공용화, 재사용성 강화(One Build, Many Use) Business Agility SOA => Design Paradiam SOA의 기대효과 Loosely Coupled, Re-Usable, Interoperable, composited. 2) Service란? 기업의 업무를 표현한 SW Component. 규약을 받은 후에 service consumer와 service provider사이에서 메세지 교환 서비스의 종류 - Business ..

backend 2007.03.25