Search in sources :

Example 6 with BookStore

use of org.apache.cxf.systest.jaxrs.BookStore in project cxf by apache.

the class JAXRSHttpsBookTest method testGetBook123WebClientToProxy.

@Test
public void testGetBook123WebClientToProxy() throws Exception {
    WebClient wc = WebClient.create("https://localhost:" + PORT, CLIENT_CONFIG_FILE1);
    wc.path("/bookstore/securebooks/123").accept(MediaType.APPLICATION_XML_TYPE);
    Book b = wc.get(Book.class);
    assertEquals(123, b.getId());
    wc.back(true);
    BookStore bs = JAXRSClientFactory.fromClient(wc, BookStore.class);
    Book b2 = bs.getSecureBook("123");
    assertEquals(b2.getId(), 123);
}
Also used : BookStore(org.apache.cxf.systest.jaxrs.BookStore) Book(org.apache.cxf.systest.jaxrs.Book) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 7 with BookStore

use of org.apache.cxf.systest.jaxrs.BookStore in project cxf by apache.

the class JAXRSHttpsBookTest method testGetBook123ProxyToWebClient.

@Test
public void testGetBook123ProxyToWebClient() throws Exception {
    BookStore bs = JAXRSClientFactory.create("https://localhost:" + PORT, BookStore.class, CLIENT_CONFIG_FILE1);
    Book b = bs.getSecureBook("123");
    assertEquals(b.getId(), 123);
    WebClient wc = WebClient.fromClient(WebClient.client(bs));
    wc.path("/bookstore/securebooks/123").accept(MediaType.APPLICATION_XML_TYPE);
    Book b2 = wc.get(Book.class);
    assertEquals(123, b2.getId());
}
Also used : BookStore(org.apache.cxf.systest.jaxrs.BookStore) Book(org.apache.cxf.systest.jaxrs.Book) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 8 with BookStore

use of org.apache.cxf.systest.jaxrs.BookStore in project cxf by apache.

the class JAXRSHttpsBookTest method doTestGetBook123Proxy.

private void doTestGetBook123Proxy(String configFile) throws Exception {
    BookStore bs = JAXRSClientFactory.create("https://localhost:" + PORT, BookStore.class, configFile);
    // just to verify the interface call goes through CGLIB proxy too
    assertEquals("https://localhost:" + PORT, WebClient.client(bs).getBaseURI().toString());
    Book b = bs.getSecureBook("123");
    assertEquals(b.getId(), 123);
    b = bs.getSecureBook("123");
    assertEquals(b.getId(), 123);
}
Also used : BookStore(org.apache.cxf.systest.jaxrs.BookStore) Book(org.apache.cxf.systest.jaxrs.Book)

Example 9 with BookStore

use of org.apache.cxf.systest.jaxrs.BookStore in project cxf by apache.

the class JAXRSHttpsBookTest method testGetBook123ProxyFromSpringWildcard.

@Test
public void testGetBook123ProxyFromSpringWildcard() throws Exception {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { CLIENT_CONFIG_FILE4 });
    Object bean = ctx.getBean("bookService.proxyFactory");
    assertNotNull(bean);
    JAXRSClientFactoryBean cfb = (JAXRSClientFactoryBean) bean;
    BookStore bs = cfb.create(BookStore.class);
    assertEquals("https://localhost:" + PORT, WebClient.client(bs).getBaseURI().toString());
    WebClient wc = WebClient.fromClient(WebClient.client(bs));
    assertEquals("https://localhost:" + PORT, WebClient.client(bs).getBaseURI().toString());
    wc.accept("application/xml");
    wc.path("bookstore/securebooks/123");
    TheBook b = wc.get(TheBook.class);
    assertEquals(b.getId(), 123);
    b = wc.get(TheBook.class);
    assertEquals(b.getId(), 123);
    ctx.close();
}
Also used : BookStore(org.apache.cxf.systest.jaxrs.BookStore) JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 10 with BookStore

use of org.apache.cxf.systest.jaxrs.BookStore in project cxf by apache.

the class CircuitBreakerFailoverTest method testSequentialStrategyUnavailableAlternatives.

@Test(expected = FailoverFailedException.class)
public void testSequentialStrategyUnavailableAlternatives() throws Exception {
    FailoverFeature feature = getFeature(false, "http://localhost:" + NON_PORT + "/non-existent", "http://localhost:" + NON_PORT + "/non-existent2");
    final BookStore bookStore = getBookStore("http://localhost:" + NON_PORT + "/non-existent", feature);
    // Second iteration should not call any URL as all targets are not available.
    for (int i = 0; i < 2; ++i) {
        try {
            bookStore.getBook(1);
            fail("Exception expected");
        } catch (ProcessingException ex) {
            if (ex.getCause() instanceof FailoverFailedException) {
                throw (FailoverFailedException) ex.getCause();
            }
        }
    }
}
Also used : BookStore(org.apache.cxf.systest.jaxrs.BookStore) FailoverFeature(org.apache.cxf.clustering.FailoverFeature) CircuitBreakerFailoverFeature(org.apache.cxf.clustering.circuitbreaker.CircuitBreakerFailoverFeature) FailoverFailedException(org.apache.cxf.clustering.FailoverFailedException) ProcessingException(javax.ws.rs.ProcessingException) Test(org.junit.Test)

Aggregations

BookStore (org.apache.cxf.systest.jaxrs.BookStore)14 Book (org.apache.cxf.systest.jaxrs.Book)8 Test (org.junit.Test)8 ProcessingException (javax.ws.rs.ProcessingException)4 FailoverFeature (org.apache.cxf.clustering.FailoverFeature)3 JAXRSClientFactoryBean (org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean)3 WebClient (org.apache.cxf.jaxrs.client.WebClient)3 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)3 ArrayList (java.util.ArrayList)2 SequentialStrategy (org.apache.cxf.clustering.SequentialStrategy)2 CircuitBreakerFailoverFeature (org.apache.cxf.clustering.circuitbreaker.CircuitBreakerFailoverFeature)2 JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)2 SingletonResourceProvider (org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)2 IOException (java.io.IOException)1 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)1 Bus (org.apache.cxf.Bus)1 FailoverFailedException (org.apache.cxf.clustering.FailoverFailedException)1 LoadDistributorFeature (org.apache.cxf.clustering.LoadDistributorFeature)1 RandomStrategy (org.apache.cxf.clustering.RandomStrategy)1 ClientLifeCycleManager (org.apache.cxf.endpoint.ClientLifeCycleManager)1