Search in sources :

Example 16 with Book

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

the class JAXRS20HttpsBookTest method testGetBook.

@Test
public void testGetBook() throws Exception {
    ClientBuilder builder = ClientBuilder.newBuilder();
    try (InputStream keystore = ClassLoaderUtils.getResourceAsStream("keys/Truststore.jks", this.getClass())) {
        KeyStore trustStore = loadStore(keystore, "password");
        builder.trustStore(trustStore);
    }
    builder.hostnameVerifier(new AllowAllHostnameVerifier());
    try (InputStream keystore = ClassLoaderUtils.getResourceAsStream("keys/Morpit.jks", this.getClass())) {
        KeyStore keyStore = loadStore(keystore, "password");
        builder.keyStore(keyStore, "password");
    }
    Client client = builder.build();
    client.register(new LoggingFeature());
    WebTarget target = client.target("https://localhost:" + PORT + "/bookstore/securebooks/123");
    Book b = target.request().accept(MediaType.APPLICATION_XML_TYPE).get(Book.class);
    assertEquals(123, b.getId());
}
Also used : InputStream(java.io.InputStream) Book(org.apache.cxf.systest.jaxrs.Book) LoggingFeature(org.apache.cxf.ext.logging.LoggingFeature) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) KeyStore(java.security.KeyStore) ClientBuilder(javax.ws.rs.client.ClientBuilder) Test(org.junit.Test)

Example 17 with Book

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

the class JAXRS20HttpsBookTest method testGetBookSslContext.

@Test
public void testGetBookSslContext() throws Exception {
    ClientBuilder builder = ClientBuilder.newBuilder();
    SSLContext sslContext = createSSLContext();
    builder.sslContext(sslContext);
    builder.hostnameVerifier(new AllowAllHostnameVerifier());
    Client client = builder.build();
    WebTarget target = client.target("https://localhost:" + PORT + "/bookstore/securebooks/123");
    Book b = target.request().accept(MediaType.APPLICATION_XML_TYPE).get(Book.class);
    assertEquals(123, b.getId());
}
Also used : Book(org.apache.cxf.systest.jaxrs.Book) SSLContext(javax.net.ssl.SSLContext) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) ClientBuilder(javax.ws.rs.client.ClientBuilder) Test(org.junit.Test)

Example 18 with Book

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

the class JAXRSHttpsBookTest method doTestGetBook123ProxyFromSpring.

private void doTestGetBook123ProxyFromSpring(String cfgFile) throws Exception {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { cfgFile });
    Object bean = ctx.getBean("bookService.proxyFactory");
    assertNotNull(bean);
    JAXRSClientFactoryBean cfb = (JAXRSClientFactoryBean) bean;
    Bus bus = cfb.getBus();
    ClientLifeCycleManager manager = bus.getExtension(ClientLifeCycleManager.class);
    TestClientLifeCycleListener listener = new TestClientLifeCycleListener();
    manager.registerListener(listener);
    BookStore bs = cfb.create(BookStore.class);
    assertNotNull(listener.getEp());
    assertEquals("{http://service.rs}BookService", listener.getEp().getEndpointInfo().getName().toString());
    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);
    ctx.close();
}
Also used : Bus(org.apache.cxf.Bus) BookStore(org.apache.cxf.systest.jaxrs.BookStore) JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Book(org.apache.cxf.systest.jaxrs.Book) ClientLifeCycleManager(org.apache.cxf.endpoint.ClientLifeCycleManager)

Example 19 with Book

use of org.apache.cxf.systest.jaxrs.Book 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 20 with Book

use of org.apache.cxf.systest.jaxrs.Book 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)

Aggregations

Book (org.apache.cxf.systest.jaxrs.Book)46 Test (org.junit.Test)31 WebClient (org.apache.cxf.jaxrs.client.WebClient)22 BookStore (org.apache.cxf.systest.jaxrs.BookStore)8 JMSBookStore (org.apache.cxf.systest.jaxrs.JMSBookStore)6 SequentialStrategy (org.apache.cxf.clustering.SequentialStrategy)5 Response (javax.ws.rs.core.Response)4 ArrayList (java.util.ArrayList)3 BytesMessage (javax.jms.BytesMessage)3 JAXBContext (javax.xml.bind.JAXBContext)3 InputStream (java.io.InputStream)2 ExecutionException (java.util.concurrent.ExecutionException)2 MessageProducer (javax.jms.MessageProducer)2 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)2 NotFoundException (javax.ws.rs.NotFoundException)2 ProcessingException (javax.ws.rs.ProcessingException)2 Client (javax.ws.rs.client.Client)2 ClientBuilder (javax.ws.rs.client.ClientBuilder)2 WebTarget (javax.ws.rs.client.WebTarget)2 Form (javax.ws.rs.core.Form)2