/** * Updates the current URI path with path segment which may contain template variables * @param path new relative path segment * @param values template variable values * @return updated WebClient */ public WebClient path(String path, Object... values) { URI u = new UriBuilderImpl().uri(URI.create("http://tempuri")).path(path).buildFromEncoded(values); getState().setTemplates(getTemplateParametersMap(new URITemplate(path), Arrays.asList(values))); return path(u.getRawPath()); }
@Test public void testGetIntroChapterFromSelectedBook2() { String address = "http://localhost:" + PORT + "/bookstore/"; WebClient wc = WebClient.create(address); wc.path("books[id=le=123]").path("chapter"); wc.accept("application/xml"); Chapter chapter = wc.get(Chapter.class); assertEquals("chapter 1", chapter.getTitle()); }
@org.junit.Test public void testGetKeys() throws Exception { URL busFile = OIDCFlowTest.class.getResource("client.xml"); String address = "https://localhost:" + port + "/services/"; WebClient client = WebClient.create(address, OAuth2TestUtils.setupProviders(), "alice", "security", busFile.toString()); client.accept("application/json"); client.path("keys/"); Response response = client.get(); JsonWebKeys jsonWebKeys = response.readEntity(JsonWebKeys.class); assertEquals(1, jsonWebKeys.getKeys().size()); }
@Test(expected = InternalServerErrorException.class) public void testUnknownParameter() throws Exception { WebClient wc = WebClient.create("http://localhost:" + PORT); wc.path("users/search/name==alice%3Bage==40").get(User.class); }
@Test public void testResponseHasBeenReceivedWhenQueringBook() { Response r = createWebClient("/bookstore/books").path("1").get(); assertEquals(Status.OK.getStatusCode(), r.getStatus()); Book book = r.readEntity(Book.class); assertEquals("1", book.getId()); }
@Test public void testGetBookAsyncStageAsyncResponse() throws Exception { String address = "http://localhost:" + PORT + "/completable/booksAsync"; WebClient wc = createWebClient(address); CompletionStage<Book> stage = wc.path("123").rx().get(Book.class); Book book = stage.toCompletableFuture().join(); assertEquals(123L, book.getId()); } @Test
protected WebClient createWebClient(final String url) { final List< ? > providers = Arrays.asList(new JacksonJsonProvider()); final WebClient wc = WebClient .create("http://localhost:" + getPort(), providers) .path(getContextPath()) .path(url) .accept(MediaType.APPLICATION_JSON); WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000L); return wc; }
@Test public void testBookWithSpace() throws Exception { WebClient client = WebClient.create("http://localhost:" + PORT + "/bookstore/").path("the books/123"); Book book = client.get(Book.class); assertEquals(123L, book.getId()); }
@Test public void testWebClientDirectDispatch() throws Exception { WebClient localClient = WebClient.create("local://books"); WebClient.getConfig(localClient).getRequestContext().put(LocalConduit.DIRECT_DISPATCH, Boolean.TRUE); localClient.path("bookstore/books/123"); Book book = localClient.get(Book.class); assertEquals(123L, book.getId()); }
private void doTestGetBook123WebClient(String configFile) throws Exception { WebClient client = WebClient.create("https://localhost:" + PORT, configFile); assertEquals("https://localhost:" + PORT, client.getBaseURI().toString()); client.path("/bookstore/securebooks/123").accept(MediaType.APPLICATION_XML_TYPE); Book b = client.get(Book.class); assertEquals(123, b.getId()); }
@Test public void testWebClientUnwrapBookWithXslt() throws Exception { XSLTJaxbProvider<Book> provider = new XSLTJaxbProvider<>(); provider.setInTemplate("classpath:/org/apache/cxf/systest/jaxrs/resources/unwrapbook.xsl"); WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/books/wrapper", Collections.singletonList(provider)); wc.path("{id}", 123); Book book = wc.get(Book.class); assertNotNull(book); assertEquals(123L, book.getId()); }
@Test public void testGetBook123WebClientResponse() throws Exception { String baseAddress = "http://localhost:" + PORT + "/test/services/rest"; WebClient client = WebClient.create(baseAddress); client.path("/bookstore/123").accept(MediaType.APPLICATION_XML_TYPE); Book b = readBook((InputStream)client.get().getEntity()); assertEquals(123, b.getId()); assertEquals("CXF in Action", b.getName()); }
private void doTestUseParamBeanWebClient(String address) { WebClient wc = WebClient.create(address); wc.path("100").query("id_2", "20").query("id3", "3").query("id4", "123"); Book book = wc.get(Book.class); assertEquals(123L, book.getId()); }
@Test public void testSearchUser() throws Exception { WebClient wc = WebClient.create("http://localhost:" + PORT); User user = wc.path("users/search/name==alice").get(User.class); Assert.assertEquals("alice", user.getName()); Assert.assertEquals("smith", user.getSurname()); }
@Test public void testSearchUserWildcardAllowed() throws Exception { WebClient wc = WebClient.create("http://localhost:" + PORT2); User user = wc.path("users/search/name==a*").get(User.class); Assert.assertEquals("alice", user.getName()); Assert.assertEquals("smith", user.getSurname()); } }
@Test public void testGetBook123WebClient() throws Exception { String baseAddress = "http://localhost:" + PORT + "/test/services/rest"; WebClient client = WebClient.create(baseAddress); client.path("/bookstore/123").accept(MediaType.APPLICATION_XML_TYPE); Book b = client.get(Book.class); assertEquals(123, b.getId()); assertEquals("CXF in Action", b.getName()); }
@Test public void testWebClientPipedDispatch() throws Exception { WebClient localClient = WebClient.create("local://books"); localClient.accept("text/xml"); localClient.path("bookstore/books"); Book book = localClient.type("application/xml").post(new Book("New", 124L), Book.class); assertEquals(124L, book.getId()); }
@Test public void testGetBookSubresourceWebClientParamExtensions() throws Exception { WebClient client = WebClient.create("http://localhost:" + PORT + "/test/services/rest"); client.type(MediaType.TEXT_PLAIN_TYPE).accept(MediaType.APPLICATION_XML_TYPE); client.path("/bookstore/books/139/subresource4/139/CXF Rocks"); Book bean = new Book("CXF Rocks", 139L); Form form = new Form(); form.param("name", "CXF Rocks").param("id", Long.toString(139L)); Book b = readBook((InputStream)client.matrix("", bean).query("", bean).form(form).getEntity()); assertEquals(139, b.getId()); assertEquals("CXF Rocks", b.getName()); }
@Test public void testGetBookXSLTXml() throws Exception { String endpointAddress = "http://localhost:" + PORT + "/the/thebooks5/bookstore/books/xslt"; WebClient wc = WebClient.create(endpointAddress); wc.accept("application/xml").path(666).matrix("name2", 2).query("name", "Action - "); Book b = wc.get(Book.class); assertEquals(666, b.getId()); assertEquals("CXF in Action - 2", b.getName()); }
@Test public void testGetBookSubresourceWebClientProxy2() throws Exception { WebClient client = WebClient.create("http://localhost:" + PORT + "/test/services/rest/bookstore") .path("/books/378"); client.type(MediaType.TEXT_PLAIN_TYPE).accept(MediaType.APPLICATION_XML_TYPE); BookSubresource proxy = JAXRSClientFactory.fromClient(client, BookSubresource.class); Book b = proxy.getTheBook2("CXF ", "in ", "Acti", "on ", "- 3", "7", "8"); assertEquals(378, b.getId()); assertEquals("CXF in Action - 378", b.getName()); }