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= "http://anyframe.sample.movie.restful.httpbinding.namingconvention")와 같이 작성해주도록 한다. 그리고 anyframe.sample.movie.restful.httpbinding.namingconvention 패키지 하위에 packageinfo.java파일을 작성해놓음으로써 클라이언트 사이드에서 JAXB를 통해 바이딩할 때 Namespace"http://anyframe.sample.movie.restful.httpbinding.namingconvention"를 인식시키도록 한다.@javax.xml.bind.annotation.XmlSchema(namespace = "http://anyframe.sample.movie.restful.httpbinding.namingconvention",elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)package anyframe.sample.movie.restful.httpbinding.namingconvention;• Test Case다음은 HttpClient 클래스를 사용하여 RESTful Web Services로 노출된 Movie Service에 접근하는 클라이언트 코드 작성 예이다. 메소드 내에서 Get/Post/Put/Delete Method 중 어느 것을 사용할 것인지 정하여 접근하고자 하는 Web Services 주소와 함께 정의하고, HttpClient 객체를 생성하여 위에서 정의한 Method를 실행시킨다. 이때 클라이언트는 서버의 Movie Service 인터페이스 클래스를 이용하지 않고 URL 정보를 이용하여 접근한다. RESTful WebService 실행 결과로 받은 XML 데이터를JavaBeans 객체로 변경하여 메소드 동작이 올바른지 테스트해본다./*** Get method로 Movie Service의 전체 목록 조회 기능을 호출하여* XML data를 리턴받고 JAXB를 사용하여 GetMoviesResponse 객체로 전환하여 사용한다.* Naming Convention 규칙:* Collection get+"The plural of resource class name"()** getMovies method를 RESTful한 Web Service로 노출하여 Client가 호출가능하도록 한다.* (ex. public Collection getMovies() throws Exception; )*/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(response);} catch (Exception e) {fail();} finally {get.releaseConnection();}JAXBContext jaxbContext =JAXBContext.newInstance("anyframe.sample.movie.restful.httpbinding.namingconvention");Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();GetMoviesResponse movies = (GetMoviesResponse) unmarshaller.unmarshal(new InputSource(new StringReader(response)));}// 2. check the movie informationassertEquals(2, movies.getMovie().size());/*** Get method로 Movie Id가 "001"인 Movie를 조회하는 기능을 호출하여* XML data를 리턴받고 JAXB를 사용하여 GetMovieResponse 객체로 전환하여 사용한다.* Naming Convention 규칙:65

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

Saved successfully!

Ooh no, something went wrong!