Search in sources :

Example 6 with BookStoreJaxrsJaxws

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

the class JAXRSSoapBookTest method testClientFaultOutInterceptor.

@Test
public void testClientFaultOutInterceptor() throws Exception {
    // testing faults created by client out interceptor chain handled correctly
    String baseAddress = "http://localhost:" + PORT + "/test/services/rest";
    JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
    bean.setAddress(baseAddress);
    bean.setResourceClass(BookStoreJaxrsJaxws.class);
    final boolean addBadOutInterceptor = true;
    TestFeature testFeature = new TestFeature(addBadOutInterceptor);
    List<AbstractFeature> features = new ArrayList<>();
    features.add(testFeature);
    bean.setFeatures(features);
    BookStoreJaxrsJaxws proxy = (BookStoreJaxrsJaxws) bean.create();
    try {
        // 321 is special case - causes error code of 525
        proxy.getBook(new Long("123"));
        fail("Method should have thrown an exception");
    } catch (Exception e) {
        assertTrue("Out Interceptor not invoked", testFeature.handleMessageOnOutInterceptorCalled());
        assertTrue("In Interceptor not invoked", !testFeature.handleMessageOnInInterceptorCalled());
        assertTrue("Wrong exception caught", "fault from bad interceptor".equals(e.getCause().getMessage()));
        assertTrue("Client In Fault In Interceptor was 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) Test(org.junit.Test)

Example 7 with BookStoreJaxrsJaxws

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

the class JAXRSSoapBookTest method testAddGetBook123Client.

@Test
public void testAddGetBook123Client() throws Exception {
    String baseAddress = "http://localhost:" + PORT + "/test/services/rest";
    BookStoreJaxrsJaxws proxy = JAXRSClientFactory.create(baseAddress, BookStoreJaxrsJaxws.class);
    Book b = new Book();
    b.setId(124);
    b.setName("CXF in Action - 2");
    Book b2 = proxy.addBook(b);
    assertNotSame(b, b2);
    assertEquals(124, b2.getId());
    assertEquals("CXF in Action - 2", b2.getName());
}
Also used : BookStoreJaxrsJaxws(org.apache.cxf.systest.jaxrs.jaxws.BookStoreJaxrsJaxws) Test(org.junit.Test)

Example 8 with BookStoreJaxrsJaxws

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

the class JAXRSSoapBookTest method testGetBookSubresourceParamOrder.

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

Example 9 with BookStoreJaxrsJaxws

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

the class JAXRSSoapBookTest method testGetBook123Client.

@Test
public void testGetBook123Client() throws Exception {
    String baseAddress = "http://localhost:" + PORT + "/test/services/rest";
    BookStoreJaxrsJaxws proxy = JAXRSClientFactory.create(baseAddress, BookStoreJaxrsJaxws.class);
    HTTPConduit conduit = (HTTPConduit) WebClient.getConfig(proxy).getConduit();
    Book b = proxy.getBook(new Long("123"));
    assertEquals(123, b.getId());
    assertEquals("CXF in Action", b.getName());
    HTTPConduit conduit2 = (HTTPConduit) WebClient.getConfig(proxy).getConduit();
    assertSame(conduit, conduit2);
    conduit.getClient().setAutoRedirect(true);
    b = proxy.getBook(new Long("123"));
    assertEquals(123, b.getId());
    assertEquals("CXF in Action", b.getName());
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) BookStoreJaxrsJaxws(org.apache.cxf.systest.jaxrs.jaxws.BookStoreJaxrsJaxws) Test(org.junit.Test)

Example 10 with BookStoreJaxrsJaxws

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

the class JAXRSSoapBookTest method testAddOrderFormBean.

@Test
public void testAddOrderFormBean() throws Exception {
    String baseAddress = "http://localhost:" + PORT + "/test/services/rest";
    BookStoreJaxrsJaxws proxy = JAXRSClientFactory.create(baseAddress, BookStoreJaxrsJaxws.class);
    WebClient.getConfig(proxy).getOutInterceptors().add(new LoggingOutInterceptor());
    WebClient.getConfig(proxy).getInInterceptors().add(new LoggingInInterceptor());
    BookSubresource bs = proxy.getBookSubresource("139");
    OrderBean order = new OrderBean();
    order.setId(123L);
    order.setWeight(100);
    order.setCustomerTitle(OrderBean.Title.MS);
    OrderBean order2 = bs.addOrder(order);
    assertEquals(Long.valueOf(123L), Long.valueOf(order2.getId()));
    assertEquals(OrderBean.Title.MS, order2.getCustomerTitle());
}
Also used : BookStoreJaxrsJaxws(org.apache.cxf.systest.jaxrs.jaxws.BookStoreJaxrsJaxws) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) 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