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/*** HttpClient를 이용하여 Movie Id가 "001"인 Movie를 조회한다.*/public void testFindMovie() throws Exception {// 1. find movieGetMethod get =new GetMethod("http://localhost:9002/movieservice/movies?movieId=001");HttpClient httpclient = new HttpClient();String response = "";try {assertEquals(200, httpclient.executeMethod(get));response = get.getResponseBodyAsString();System.out.println("find: " + response);assertNotNull(response);} catch (Exception e) {fail();} finally {get.releaseConnection();}JAXBContext jaxbContext =JAXBContext.newInstance("anyframe.sample.movie.restful.jaxrs");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());/*** Dispatch를 이용하여 Movie Id가 "002"인 기존 Movie 정보를 변경한다.*/public void testUpdateMovie() throws Exception {QName serviceName = new QName("movieservice");QName portName = new QName("MovieServicePayloadProviderPort");Service service = Service.create(serviceName);service.addPort(portName, HTTPBinding.HTTP_BINDING,"http://localhost:9002/movieservice/movies");Dispatch dispatcher=service.createDispatch(portName, DOMSource.class,Service.Mode.PAYLOAD);Map requestContext = dispatcher.getRequestContext();InputStream is = getClass().getClassLoader().getResourceAsStream("webservices/restful/dispatch/client/Movie-movieId=002Req.xml");Document doc = XMLUtils.parse(is);DOMSource reqMsg = new DOMSource(doc);requestContext.put(MessageContext.HTTP_REQUEST_METHOD, "POST");DOMSource result = dispatcher.invoke(reqMsg);printSource(result);JAXBContext jaxbContext=JAXBContext.newInstance("anyframe.sample.movie.restful.jaxrs");Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();Movie movie = (Movie) unmarshaller.unmarshal(result);// 3. check the new movie informationassertEquals("Life Is Wonderful", movie.getTitle());70

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

Saved successfully!

Ooh no, something went wrong!