Search in sources :

Example 16 with BookStoreJaxrsJaxws

use of org.apache.cxf.systest.jaxrs.jaxws.BookStoreJaxrsJaxws in project cxf by apache.

the class JAXRSSoapBookTest method testGetBookSubresourceParamExtensions.

@Test
public void testGetBookSubresourceParamExtensions() throws Exception {
    String baseAddress = "http://localhost:" + PORT + "/test/services/rest";
    BookStoreJaxrsJaxws proxy = JAXRSClientFactory.create(baseAddress, BookStoreJaxrsJaxws.class);
    WebClient.getConfig(proxy).getOutInterceptors().add(new LoggingOutInterceptor());
    BookSubresource bs = proxy.getBookSubresource("139");
    Book bean = new Book("CXF Rocks", 139L);
    Book b = bs.getTheBook4(bean, bean, bean, bean);
    assertEquals(139, b.getId());
    assertEquals("CXF Rocks", b.getName());
}
Also used : BookStoreJaxrsJaxws(org.apache.cxf.systest.jaxrs.jaxws.BookStoreJaxrsJaxws) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) Test(org.junit.Test)

Example 17 with BookStoreJaxrsJaxws

use of org.apache.cxf.systest.jaxrs.jaxws.BookStoreJaxrsJaxws in project cxf by apache.

the class JAXRSSoapBookTest method serverFaultInInterceptorTest.

private void serverFaultInInterceptorTest(String param) {
    String baseAddress = "http://localhost:" + PORT + "/test/services/rest";
    JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
    bean.setAddress(baseAddress);
    bean.setResourceClass(BookStoreJaxrsJaxws.class);
    TestFeature testFeature = new TestFeature();
    List<AbstractFeature> features = new ArrayList<>();
    features.add(testFeature);
    bean.setFeatures(features);
    BookStoreJaxrsJaxws proxy = (BookStoreJaxrsJaxws) bean.create();
    WebClient.getConfig(proxy).getRequestContext().put("org.apache.cxf.transport.no_io_exceptions", false);
    try {
        // 321 is special case - causes error code of 525
        proxy.getBook(new Long(param));
        fail("Method should have thrown an exception");
    } catch (Exception e) {
        assertTrue("Out Interceptor not invoked", testFeature.handleMessageOnOutInterceptorCalled());
        if ("322".equals(param)) {
            // In interceptors not called when checked exception thrown from server
            assertTrue("In Interceptor not invoked", testFeature.handleMessageOnInInterceptorCalled());
        } else {
            assertTrue("In Interceptor not invoked", !testFeature.handleMessageOnInInterceptorCalled());
        }
        assertTrue("Client In Fault In Interceptor not invoked", testFeature.faultInInterceptorCalled());
    }
}
Also used : BookStoreJaxrsJaxws(org.apache.cxf.systest.jaxrs.jaxws.BookStoreJaxrsJaxws) JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) ArrayList(java.util.ArrayList) AbstractFeature(org.apache.cxf.feature.AbstractFeature) NotFoundException(javax.ws.rs.NotFoundException) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 18 with BookStoreJaxrsJaxws

use of org.apache.cxf.systest.jaxrs.jaxws.BookStoreJaxrsJaxws in project cxf by apache.

the class JAXRSSoapBookTest method testGetBookSubresourceClient.

@Test
public void testGetBookSubresourceClient() throws Exception {
    String baseAddress = "http://localhost:" + PORT + "/test/services/rest";
    BookStoreJaxrsJaxws proxy = JAXRSClientFactory.create(baseAddress, BookStoreJaxrsJaxws.class);
    BookSubresource bs = proxy.getBookSubresource("125");
    Book b = bs.getTheBook();
    assertEquals(125, b.getId());
    assertEquals("CXF in Action", b.getName());
}
Also used : BookStoreJaxrsJaxws(org.apache.cxf.systest.jaxrs.jaxws.BookStoreJaxrsJaxws) Test(org.junit.Test)

Example 19 with BookStoreJaxrsJaxws

use of org.apache.cxf.systest.jaxrs.jaxws.BookStoreJaxrsJaxws in project cxf by apache.

the class JAXRSSoapBookTest method testGetBook356ClientException.

@Test
public void testGetBook356ClientException() throws Exception {
    String baseAddress = "http://localhost:" + PORT + "/test/services/rest";
    BookStoreJaxrsJaxws proxy = JAXRSClientFactory.create(baseAddress, BookStoreJaxrsJaxws.class, Collections.singletonList(new TestResponseExceptionMapper()));
    try {
        proxy.getBook(356L);
        fail();
    } catch (BookNotFoundFault ex) {
        assertEquals("No Book with id 356 is available", ex.getMessage());
    }
}
Also used : BookStoreJaxrsJaxws(org.apache.cxf.systest.jaxrs.jaxws.BookStoreJaxrsJaxws) Test(org.junit.Test)

Example 20 with BookStoreJaxrsJaxws

use of org.apache.cxf.systest.jaxrs.jaxws.BookStoreJaxrsJaxws in project cxf by apache.

the class JAXRSSoapBookTest method testCheckBookClientErrorResponse.

@Test
public void testCheckBookClientErrorResponse() {
    String baseAddress = "http://localhost:" + PORT + "/test/services/rest";
    BookStoreJaxrsJaxws proxy = JAXRSClientFactory.create(baseAddress, BookStoreJaxrsJaxws.class, Collections.singletonList(new DummyResponseExceptionMapper()));
    Response response = proxy.checkBook(100L);
    assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) BookStoreJaxrsJaxws(org.apache.cxf.systest.jaxrs.jaxws.BookStoreJaxrsJaxws) Test(org.junit.Test)

Aggregations

BookStoreJaxrsJaxws (org.apache.cxf.systest.jaxrs.jaxws.BookStoreJaxrsJaxws)22 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)4 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)3 AbstractFeature (org.apache.cxf.feature.AbstractFeature)3 JAXRSClientFactoryBean (org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean)3 URL (java.net.URL)2 NotFoundException (javax.ws.rs.NotFoundException)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 QName (javax.xml.namespace.QName)2 WebClient (org.apache.cxf.jaxrs.client.WebClient)2 JAXBElementProvider (org.apache.cxf.jaxrs.provider.JAXBElementProvider)2 BookSoapService (org.apache.cxf.systest.jaxrs.jaxws.BookSoapService)2 HashMap (java.util.HashMap)1 Response (javax.ws.rs.core.Response)1 Client (org.apache.cxf.endpoint.Client)1 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)1 TransformInInterceptor (org.apache.cxf.interceptor.transform.TransformInInterceptor)1 TransformOutInterceptor (org.apache.cxf.interceptor.transform.TransformOutInterceptor)1 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)1