12.07.2015 Views

Anyframe CXF Plugin

Anyframe CXF Plugin

Anyframe CXF Plugin

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

RESTful Services의하도록 한다. JAXB를 이용하여 서비스 결과 XML을 JavaBeans 객체로 변환 시 이 Annotation 정보를 이용한다. 특히 목록 조회 결과 시 사용되는 리턴 값은 내부 멤버 변수로 Collection 객체를 정의하여 새로운 Movies 객체를 작성함에 유의하도록 한다.import javax.xml.bind.annotation.XmlRootElement;@XmlRootElement(name = "Movies")public class Movies {private Collection movies;public Collection getMovie() {return movies;}public void setMovie(Collection movies) {this.movies = movies;}중략...다음은 JAXB를 사용하기 위해서 필요한 jaxb.index 파일이다. Movie와 Movies 클래스를 정의해 놓는다.MovieMovies• Test Case다음은 HttpClient 및 Dispatch 클래스를 사용하여 RESTful Web Services로 노출된 Movie Service에접근하는 클라이언트 코드 작성 예이다. 메소드 내에서 Get/Post/Put/Delete Method 중 어느 것을사용할 것인지 정하여 접근하고자 하는 Web Services 주소와 함께 정의하고, HttpClient 객체를 생성하여 위에서 정의한 Method를 실행시킨다. 이 중 testUpdateMovie() 메소드가 Dispatch API를 이용하여 작성된 클라이언트 코드이다. RESTful WebService 실행 결과로 받은 XML 데이터를 JavaBeans 객체로 변경하여 메소드 동작이 올바른지 테스트해본다./*** HttpClient를 이용하여* List 형태의 Movie 전체 목록을 조회한다.*/public void testFindMovieListAll() throws Exception {// 1. find movieGetMethod get=new GetMethod("http://localhost:9002/movieservice/movies");HttpClient httpclient = new HttpClient();String response = "";try {assertEquals(200, httpclient.executeMethod(get));response = get.getResponseBodyAsString();System.out.println("findMovieListAll : " + response);assertNotNull(response);} catch (Exception e) { fail();} finally { get.releaseConnection(); }JAXBContext jaxbContext =JAXBContext.newInstance("anyframe.sample.movie.restful.jaxrs");Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();Movies movies = (Movies) unmarshaller.unmarshal(new InputSource(new StringReader(response)));}// 2. check the movie informationassertEquals(2, movies.getMovie().size());69

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!