Anyframe CXF Plugin
Anyframe CXF Plugin
Anyframe CXF Plugin
- No tags were found...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
RESTful Services* "resource class name" get+"resource class name"(Object id)** getMovie method를 RESTful한 Web Service로 노출하여 Client가 호출가능하도록 한다.* (ex. public Movie getMovie(String movieId) throws Exception;)*/public void testFindMovie() throws Exception {// 1. find movieGetMethod get=new GetMethod("http://localhost:9002/movieservice/movies/001");HttpClient httpclient = new HttpClient();String response = "";try {assertEquals(200, httpclient.executeMethod(get));response = get.getResponseBodyAsString();System.out.println("find: " + response);} catch (Exception e) {fail();} finally { get.releaseConnection();}JAXBContext jaxbContext = JAXBContext.newInstance("anyframe.sample.movie.restful.httpbinding.namingconvention");Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();GetMovieResponse movie = (GetMovieResponse) unmarshaller.unmarshal(new InputSource(new StringReader(response)));}// 2. check the movie informationassertEquals("The Sound Of Music", movie.getMovie().getTitle());assertEquals("Robert Wise", movie.getMovie().getDirector());/*** Post method로 Movie Id가 "003"인 신규 Movie를 생성하는 기능을 호출한다* Naming Convention 규칙:* void add or create + "resource class name"("resource class" obj)** addMovie method를 RESTful한 Web Service로 노출하여 Client가 호출가능하도록 한다.* (ex. public void addMovie(@WebParam(name = "Movie") Movie movie)*/public void testCreateMovie() throws Exception {// 1. create movieString inputFile = this.getClass().getClassLoader().getResource("webservices/restful/httpbinding/namingconvention/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 = "";try {assertEquals(200, httpclient.executeMethod(post));response = post.getResponseBodyAsString();System.out.println("create: " + response);} catch (Exception e) {fail();} finally {post.releaseConnection();}중략...66