12.07.2015 Views

Anyframe CXF Plugin

Anyframe CXF Plugin

Anyframe CXF Plugin

SHOW MORE
SHOW LESS
  • 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}public void setMovies(Collection movies) {this.movies = movies;}중략...다음은 JAXB를 사용하기 위해서 필요한 jaxb.index 파일이다. Movie와 Movies 클래스를 정의해 놓는다. 파일 위치는 Movie와 Movies 클래스의 패키지 위치와 동일하다. (예시:src/main/resources/anyframe/sample/domain/jaxb.index)MovieMovies• Test Case다음은 RESTful Web Services로 노출된 Movie Service에 접근하는 클라이언트 코드를 작성한Controller 클래스의 일부이다.메소드 내에서 Get/Post/Put/Delete Method 중 어느 것을 사용할 것인지 정하여 접근하고자 하는Web Serices 주소와 함께 정의하고, HttpClient 객체를 생성하여 위에서 정의한 Method를 실행시킨다. 이때 클라이언트는 서버의 Movie Service 인터페이스 클래스를 이용하지 않고 URL 정보를 이용하여 접근한다. RESTful WebService 실행 결과로 받은 XML 데이터를 JavaBeans 객체로 변경하여 메소드 동작이 올바른지 테스트해본다.@Controllerpublic class MovieController {@RequestMapping("/cxfAddMovie.do")public String add(@ModelAttribute("movie") Movie movie) throws Exception {PostMethod post = new PostMethod("http://localhost:8080/anyframe.sample.cxf.restful/ws/movieservice/movie/");String xmldata = ""+ movie.getMovieId() + ""+ "" + movie.getTitle() + ""+ ""+ movie.getDirector() + ""+ ""+ new SimpleDateFormat("yyyy-MM-dd").format(movie.getReleaseDate()) + ""+ "" + movie.getRank() + "";}RequestEntity entity = new StringRequestEntity(xmldata,"text/xml","ISO-8859-1");post.setRequestEntity(entity);try {new HttpClient().executeMethod(post);} finally {post.releaseConnection();}return "/cxfListMovie.do";@RequestMapping("/cxfGetMovie.do")public ModelAndView get(HttpServletRequest request) throws Exception {String movieId = request.getParameter("movieId");if (!StringUtils.isBlank(movieId)) {// call Restful movie serviceURL url = new URL("http://localhost:8080/anyframe.sample.cxf.restful/ws/movieservice/movie/"53

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

Saved successfully!

Ooh no, something went wrong!