/** * Fetches {@code ETag} header value from latest service run (if available). * * @param <T> any service class * @param service service class instance * @return {@code ETag} header value from latest service run (if available) */ public <T> EntityTag getLatestEntityTag(final T service) { return WebClient.client(service).getResponse().getEntityTag(); }
/** * Fetches {@code ETag} header value from latest service run (if available). * * @param <T> any service class * @param service service class instance * @return {@code ETag} header value from latest service run (if available) */ public <T> EntityTag getLatestEntityTag(final T service) { return WebClient.client(service).getResponse().getEntityTag(); }
@Test public void testOnewayProxy() throws Exception { BookStore proxy = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class); proxy.onewayRequest(); assertEquals(202, WebClient.client(proxy).getResponse().getStatus()); }
@Test public void testUserModelInterfaceOneWay() throws Exception { BookStoreNoAnnotationsInterface proxy = JAXRSClientFactory.createFromModel("http://localhost:" + PORT + "/usermodel2", BookStoreNoAnnotationsInterface.class, "classpath:org/apache/cxf/systest/jaxrs/resources/resources2.xml", null); proxy.pingBookStore(); assertEquals(202, WebClient.client(proxy).getResponse().getStatus()); }
@Test public void testEmptyPostProxy() throws Exception { BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class); store.emptypost(); assertEquals(204, WebClient.client(store).getResponse().getStatus()); }
@Test public void testEmptyPutProxy() throws Exception { BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class); store.emptyput(); assertEquals(204, WebClient.client(store).getResponse().getStatus()); }
@Test public void testBookWithSpaceProxyWithBufferedStream() throws Exception { BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class); WebClient.getConfig(store).getResponseContext().put("buffer.proxy.response", "true"); Book book = store.getBookWithSpace("123"); assertEquals(123L, book.getId()); assertTrue(WebClient.client(store).getResponse().readEntity(String.class).contains("<Book")); }
@Test public void testProxyEmtpyResponse() throws Exception { BookStore localProxy = JAXRSClientFactory.create("local://books", BookStore.class); assertNull(localProxy.getEmptyBook()); assertEquals(204, WebClient.client(localProxy).getResponse().getStatus()); }
private void doGetBookProxyClient(String address, String username, String password, int expectedStatus) throws BookNotFoundFault { SecureBookInterface books = JAXRSClientFactory.create(address, SecureBookInterface.class, username, password, null); Book b = books.getThatBook(); assertEquals(123, b.getId()); Response r = WebClient.client(books).getResponse(); assertEquals(expectedStatus, r.getStatus()); }
@Test public void testProxyEmptyResponseDirectDispatch() throws Exception { BookStore localProxy = JAXRSClientFactory.create("local://books", BookStore.class); WebClient.getConfig(localProxy).getRequestContext().put(LocalConduit.DIRECT_DISPATCH, "true"); assertNull(localProxy.getEmptyBook()); assertEquals(204, WebClient.client(localProxy).getResponse().getStatus()); }
@Test public void testUpdateWithProxy() throws Exception { BookStore bs = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class); Book book = new Book(); book.setId(888); bs.updateBook(book); assertEquals(304, WebClient.client(bs).getResponse().getStatus()); }
@Test public void testGetBookFromProxyClientWithQuery() throws Exception { // setup the the client String endpointAddressUrlEncoded = "jms:jndi:dynamicQueues/test.jmstransport.text" + "?jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory" + "&replyToName=dynamicQueues/test.jmstransport.response" + "&jndiURL=tcp://localhost:" + JMS_PORT + "&jndiConnectionFactoryName=ConnectionFactory"; JMSBookStore client = JAXRSClientFactory.create(endpointAddressUrlEncoded, JMSBookStore.class); Book book = client.getBookByURLQuery(new String[] {"1", "2", "3"}); assertEquals("Get a wrong response code.", 200, WebClient.client(client).getResponse().getStatus()); assertEquals("Get a wrong book id.", 123, book.getId()); }
@Test public void testGetBookFromProxyClient() throws Exception { // setup the the client String endpointAddressUrlEncoded = "jms:jndi:dynamicQueues/test.jmstransport.text" + "?jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory" + "&replyToName=dynamicQueues/test.jmstransport.response" + "&jndiURL=tcp://localhost:" + JMS_PORT + "&jndiConnectionFactoryName=ConnectionFactory"; JMSBookStore client = JAXRSClientFactory.create(endpointAddressUrlEncoded, JMSBookStore.class); Book book = client.getBook("123"); assertEquals("Get a wrong response code.", 200, WebClient.client(client).getResponse().getStatus()); assertEquals("Get a wrong book id.", 123, book.getId()); }
@Test public void testGetBookJsonProxy() throws Exception { String address = "http://localhost:" + PORT; MultipartStore client = JAXRSClientFactory.create(address, MultipartStore.class); Map<String, Book> map = client.getBookJson(); List<Book> result = new ArrayList<>(map.values()); assertEquals(1, result.size()); Book json = result.get(0); assertEquals("json", json.getName()); assertEquals(1L, json.getId()); String contentType = WebClient.client(client).getResponse().getMetadata().getFirst("Content-Type").toString(); MediaType mt = MediaType.valueOf(contentType); assertEquals("multipart", mt.getType()); assertEquals("mixed", mt.getSubtype()); }
@Test public void testGetBookFromProxyClientWithQueryWithTextJMSMessage() throws Exception { // setup the the client String endpointAddressUrlEncoded = "jms:jndi:dynamicQueues/test.jmstransport.text" + "?jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory" + "&replyToName=dynamicQueues/test.jmstransport.response" + "&jndiURL=tcp://localhost:" + JMS_PORT + "&jndiConnectionFactoryName=ConnectionFactory" + "&messageType=text"; JMSBookStore client = JAXRSClientFactory.create(endpointAddressUrlEncoded, JMSBookStore.class); Book book = client.getBookByURLQuery(new String[] {"1", "2", "3"}); assertEquals("Get a wrong response code.", 200, WebClient.client(client).getResponse().getStatus()); assertEquals("Get a wrong book id.", 123, book.getId()); }
@Test public void testGetBookFromProxyClientWithTextJMSMessage() throws Exception { // setup the the client String endpointAddressUrlEncoded = "jms:jndi:dynamicQueues/test.jmstransport.text" + "?jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory" + "&replyToName=dynamicQueues/test.jmstransport.response" + "&jndiURL=tcp://localhost:" + JMS_PORT + "&jndiConnectionFactoryName=ConnectionFactory" + "&messageType=text"; JMSBookStore client = JAXRSClientFactory.create(endpointAddressUrlEncoded, JMSBookStore.class); Book book = client.getBook("123"); assertEquals("Get a wrong response code.", 200, WebClient.client(client).getResponse().getStatus()); assertEquals("Get a wrong book id.", 123, book.getId()); }
private void invoke(int ind) throws Exception { String actualHeaderName = bookHeader + ind; String actualBookName = bookName + ind; if (stateCanBeChanged) { Client c = WebClient.client(proxy); MultivaluedMap<String, String> map = c.getHeaders(); map.putSingle("CustomHeader", actualHeaderName); c.headers(map); proxy.echoBookNameAndHeader2(actualBookName); verifyResponse(c.getResponse(), actualBookName, actualHeaderName); } else { verifyResponse(proxy.echoBookNameAndHeader(actualHeaderName, actualBookName), actualBookName, actualHeaderName); } }
@Test public void testEmptyPostProxy2() throws Exception { String address = "http://localhost:" + PORT; JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(address); bean.setResourceClass(BookStore.class); BookStore store = bean.create(BookStore.class); store.emptypostNoPath(); assertEquals(204, WebClient.client(store).getResponse().getStatus()); }
@Test public void testGetBookFromSubresourceProxyClient() throws Exception { // setup the the client String endpointAddressUrlEncoded = "jms:jndi:dynamicQueues/test.jmstransport.text" + "?jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory" + "&replyToName=dynamicQueues/test.jmstransport.response" + "&jndiURL=tcp://localhost:" + JMS_PORT + "&jndiConnectionFactoryName=ConnectionFactory"; JMSBookStore client = JAXRSClientFactory.create(endpointAddressUrlEncoded, JMSBookStore.class); Book bookProxy = client.getBookSubResource("123"); Book book = bookProxy.retrieveState(); assertEquals("Get a wrong response code.", 200, WebClient.client(bookProxy).getResponse().getStatus()); assertEquals("Get a wrong book id.", 123, book.getId()); }
@Test public void testGetBookFromSubresourceProxyClientWithTextJMSMessage() throws Exception { // setup the the client String endpointAddressUrlEncoded = "jms:jndi:dynamicQueues/test.jmstransport.text" + "?jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory" + "&replyToName=dynamicQueues/test.jmstransport.response" + "&jndiURL=tcp://localhost:" + JMS_PORT + "&jndiConnectionFactoryName=ConnectionFactory" + "&messageType=text"; JMSBookStore client = JAXRSClientFactory.create(endpointAddressUrlEncoded, JMSBookStore.class); Book bookProxy = client.getBookSubResource("123"); Book book = bookProxy.retrieveState(); assertEquals("Get a wrong response code.", 200, WebClient.client(bookProxy).getResponse().getStatus()); assertEquals("Get a wrong book id.", 123, book.getId()); }