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 ServicesJAXBContext.newInstance("anyframe.sample.movie.restful.httpbinding.jra");Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();Movie movie =(Movie) unmarshaller.unmarshal(new InputSource(new StringReader(response)));}// 2. check the movie informationassertEquals("The Sound Of Music", movie.getTitle());assertEquals("Robert Wise", movie.getDirector());/*** [Flow #3] Positive Case : Post method로 Movie Id가 "003"인 신규 Movie를* 생성하는 기능을 호출한다.* @Post, @HttpResource annotation을 이용하여* createMovie method를 RESTful한 Web Service로 노출하여 Client가* 호출가능하도록 한다.* (ex. @Post* @HttpResource(location = "/movies")* public void createMovie(@WebParam(name = "Movie") Movie movie)* throws Exception;* )*/public void testCreateMovie() throws Exception {// 1. create movieString inputFile =this.getClass().getClassLoader().getResource("webservices/restful/httpbinding/jra/create_movie.txt").getFile();File input = new File(inputFile);PostMethod post =new PostMethod("http://localhost:9002/movieservice/movies");RequestEntity entity =new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");post.setRequestEntity(entity);HttpClient httpclient = new HttpClient();String response = "";7.2.3.유의 사항try {assertEquals(200, httpclient.executeMethod(post));response = post.getResponseBodyAsString();System.out.println("create: " + response);} catch (Exception e) {fail();} finally {post.releaseConnection();}중략...위에서 단일항목을 Post Method 방식으로 생성하는 방법과 유사하게 Collection 항목을 Post Method방식으로 보내어 생성해 낼 수 있다.7.2.3.1.SamplesPost 방식으로 보내고자 하는 Collection 항목을 다음과 같이 작성한다. 이때 Movie를 소문자로 시작하여 작성함에 유의하도록 한다. 왜냐하면 기본적으로 RESTful Web Service 사용 시 Collection 데이터 내부 항목에 대해서 소문자로 XML 내용이 채워지게 되기 때문이다.59

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

Saved successfully!

Ooh no, something went wrong!