/** * Creates WebClient, baseURI will be set to Client currentURI * @param object existing client object */ public static WebClient fromClientObject(Object object) { Client client = client(object); return client == null ? null : fromClient(client, false); }
@PostConstruct public void verifyWebClient() { if (!ignoreJaxrsClient) { if (webClient == null) { throw new RuntimeException(); } WebClient.client(webClient).accept("application/xml"); } }
@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 testOnewayProxy() throws Exception { BookStore proxy = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class); proxy.onewayRequest(); assertEquals(202, WebClient.client(proxy).getResponse().getStatus()); }
@Test(expected = BadRequestException.class) public void testJwsJwkPlainTextHMacHttpHeadersModified() throws Exception { String address = "https://localhost:" + PORT + "/jwsjwkhmacHttpHeaders"; BookStore bs = createJwsBookStore(address, null, true, true); WebClient.client(bs).header("Modify", "true"); bs.echoText("book"); } @Test
@Test public void testProxyEmtpyResponse() throws Exception { BookStore localProxy = JAXRSClientFactory.create("local://books", BookStore.class); assertNull(localProxy.getEmptyBook()); assertEquals(204, WebClient.client(localProxy).getResponse().getStatus()); }
@Test public void testEchoGenericSuperBookCollectionProxy2JsonType() throws Exception { String endpointAddress = "http://localhost:" + PORT + "/webapp/genericstore2type"; GenericBookStoreSpring2 proxy = JAXRSClientFactory.create(endpointAddress, GenericBookStoreSpring2.class, Collections.singletonList(new JacksonJsonProvider())); WebClient.client(proxy).type("application/json").accept("application/json"); List<SuperBook2> books = proxy.echoSuperBookTypeCollection(Collections.singletonList(new SuperBook2("Super", 124L, true))); assertEquals(124L, books.get(0).getId()); assertTrue(books.get(0).isSuperBook()); }
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 testEchoGenericSuperBookCollectionProxy2Json() throws Exception { String endpointAddress = "http://localhost:" + PORT + "/webapp/genericstore2"; GenericBookStoreSpring2 proxy = JAXRSClientFactory.create(endpointAddress, GenericBookStoreSpring2.class, Collections.singletonList(new JacksonJsonProvider())); WebClient.client(proxy).type("application/json").accept("application/json"); List<SuperBook> books = proxy.echoSuperBookCollection(Collections.singletonList(new SuperBook("Super", 124L, true))); assertEquals(124L, books.get(0).getId()); assertTrue(books.get(0).isSuperBook()); }
@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 testThatClientDiscoversServiceProperly() throws Exception { BookStore bs = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class, "org/apache/cxf/systest/jaxrs/discovery/jaxrs-http-client.xml"); assertEquals("http://localhost:" + PORT, WebClient.client(bs).getBaseURI().toString()); BookWithValidation book = bs.getBook("123"); assertEquals(book.getId(), "123"); }
@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()); }
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); }
@Test public void testGetBookSubresourceWebClientProxyBean() throws Exception { WebClient client = WebClient.create("http://localhost:" + PORT + "/test/services/rest"); client.type(MediaType.TEXT_PLAIN_TYPE) .accept(MediaType.APPLICATION_XML_TYPE, MediaType.TEXT_XML_TYPE); BookStoreJaxrsJaxws proxy = JAXRSClientFactory.fromClient(client, BookStoreJaxrsJaxws.class, true); doTestSubresource(proxy); BookStoreJaxrsJaxws proxy2 = JAXRSClientFactory.fromClient( WebClient.client(proxy), BookStoreJaxrsJaxws.class); doTestSubresource(proxy2); }
@Test public void testEchoGenericSuperBookProxy2Json() throws Exception { String endpointAddress = "http://localhost:" + PORT + "/webapp/genericstore2"; GenericBookStoreSpring2 proxy = JAXRSClientFactory.create(endpointAddress, GenericBookStoreSpring2.class, Collections.singletonList(new JacksonJsonProvider())); WebClient.getConfig(proxy).getHttpConduit().getClient().setReceiveTimeout(1000000000L); WebClient.client(proxy).type("application/json").accept("application/json"); SuperBook book = proxy.echoSuperBook(new SuperBook("Super", 124L, true)); assertEquals(124L, book.getId()); assertTrue(book.isSuperBook()); }
@Test public void testEchoGenericSuperBookProxy2JsonType() throws Exception { String endpointAddress = "http://localhost:" + PORT + "/webapp/genericstore2type"; GenericBookStoreSpring2 proxy = JAXRSClientFactory.create(endpointAddress, GenericBookStoreSpring2.class, Collections.singletonList(new JacksonJsonProvider())); WebClient.getConfig(proxy).getHttpConduit().getClient().setReceiveTimeout(1000000000L); WebClient.client(proxy).type("application/json").accept("application/json"); SuperBook2 book = proxy.echoSuperBookType(new SuperBook2("Super", 124L, true)); assertEquals(124L, book.getId()); assertTrue(book.isSuperBook()); }
@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()); }