protected WebClient createWebClient(final String url, final String media) { final List< ? > providers = Arrays.asList(new JacksonJsonProvider()); final WebClient wc = WebClient .create("http://localhost:" + getPort() + url, providers) .accept(media); WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(8000L); return wc; }
protected WebClient createWebClient(final String url, final String mediaType) { final List< ? > providers = Arrays.asList(new JacksonJsonProvider()); final WebClient wc = WebClient .create("http://localhost:" + getPort() + url, providers) .accept(mediaType); WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000L); return wc; }
private void doTestGetBookISOXML(String charset, String pathSegment) throws Exception { String address = "http://localhost:" + PORT + "/the/bookstore/ISO-8859-1/" + pathSegment; WebClient wc = WebClient.create(address); WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000L); wc.accept("application/xml" + (charset == null ? "" : ";charset=ISO-8859-1")); byte[] iso88591bytes = wc.get(byte[].class); String helloStringISO88591 = new String(iso88591bytes, "ISO-8859-1"); String name = helloStringISO88591.substring( helloStringISO88591.indexOf("<name>") + "<name>".length(), helloStringISO88591.indexOf("</name>")); compareNames(name); }
private void doTestGetBookHTMLFromWelcomeList(String address) throws Exception { WebClient client = WebClient.create(address); client.accept("text/html"); WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(100000000); XMLSource source = client.accept("text/html").get(XMLSource.class); Map<String, String> namespaces = new HashMap<>(); namespaces.put("xhtml", "http://www.w3.org/1999/xhtml"); namespaces.put("books", "http://www.w3.org/books"); String value = source.getValue("xhtml:html/xhtml:body/xhtml:ul/books:bookTag", namespaces); assertEquals("Welcome to CXF", value); } }
@Test public void testGetGenericSuperBookInt2() throws Exception { String endpointAddress = "http://localhost:" + PORT + "/webapp/genericstoreInt2"; GenericBookServiceInterface proxy = JAXRSClientFactory.create(endpointAddress, GenericBookServiceInterface.class, Collections.singletonList(new JacksonJsonProvider())); WebClient.getConfig(proxy).getHttpConduit().getClient().setReceiveTimeout(1000000000L); List<SuperBook> books = proxy.getSuperBook(); assertEquals(1, books.size()); assertEquals(111L, books.get(0).getId()); }
protected WebClient createWebClient(final String url) { WebClient wc = WebClient.create("http://localhost:" + PORT + url) .accept(MediaType.APPLICATION_JSON); WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000L); return wc; }
@Test public void testPostAnd401WithText() throws Exception { String endpointAddress = "http://localhost:" + PORT + "/bookstore/post401"; WebClient wc = WebClient.create(endpointAddress); WebClient.getConfig(wc).getHttpConduit().getClient().setAllowChunking(false); Response r = wc.post(null); assertEquals(401, r.getStatus()); assertEquals("This is 401", getStringFromInputStream((InputStream)r.getEntity())); }
@Test public void testGetServicesPageNotFound() throws Exception { final String address = "http://localhost:" + PORT + "/the/services;a=b"; WebClient wc = WebClient.create(address).accept("text/*"); WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000); assertEquals(404, wc.get().getStatus()); } @Test
@Test public void testGetBookWithoutJsonpCallback() throws Exception { String url = "http://localhost:" + PORT + "/the/jsonp/books/123"; WebClient client = WebClient.create(url); client.accept("application/json, application/x-javascript"); WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(1000000L); Response r = client.get(); assertEquals("application/json", r.getMetadata().getFirst("Content-Type")); assertEquals("{\"Book\":{\"id\":123,\"name\":\"CXF in Action\"}}", IOUtils.readStringFromStream((InputStream)r.getEntity())); }
@Test public void testBookDepthExceededXMLSource() throws Exception { String endpointAddress = "http://localhost:" + PORT + "/the/thebooks9/depth-source"; WebClient wc = WebClient.create(endpointAddress); WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(1000000L); Response r = wc.type("application/xml").post(new Book("CXF", 123L)); assertEquals(413, r.getStatus()); }
@Test public void testMatchedUrisParam() throws Exception { WebClient wc = WebClient.create("http://localhost:" + PORT + "/match/my/resource/1/matched/uris/param"); WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(100000000L); wc.accept("text/plain"); String data = wc.get(String.class); assertEquals("my/resource/1/matched/uris/param,my/resource/1", data); } @Test
@Test public void testMatchedResources() throws Exception { WebClient wc = WebClient.create("http://localhost:" + PORT + "/match/my/resource/1/matched/resources"); WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(100000000L); wc.accept("text/plain"); String data = wc.get(String.class); assertEquals("class org.apache.cxf.systest.jaxrs.JAXRSUriInfoMatchTest$Resource", data); }
@Test public void testGetChapterFromBookSubObject() throws Exception { WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/booksubresourceobject/chaptersobject/sub/1"); WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(100000000L); Chapter c = wc.accept("application/xml").get(Chapter.class); assertNotNull(c); }
@Test public void testBookExistsServerAddressOverwriteWithQuery() throws Exception { String address = "http://localhost:" + PORT + "/bookstore/books/checkNQuery?a=b"; WebClient wc = WebClient.create(address); WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000); wc.accept("text/plain").type("text/plain"); assertTrue(wc.post("s", Boolean.class)); }
@Test public void testPostEmptyBook() { String address = "http://localhost:" + PORT + "/bookstore/bookheaders/simple"; WebClient wc = createWebClientPost(address); WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(1000000); Book book = wc.post(null, Book.class); assertEquals(124L, book.getId()); validatePostResponse(wc, false, true); }
@Test public void testGetBookXsiType() throws Exception { String address = "http://localhost:" + PORT + "/the/thebooksxsi/bookstore/books/xsitype"; WebClient wc = WebClient.create(address); WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000); wc.accept("application/xml"); Book book = wc.get(Book.class); assertEquals("SuperBook", book.getName()); }
private void doTestGetBookAsPlainContent(String address) throws Exception { WebClient wc = WebClient.create(address); WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000); wc.accept("multipart/mixed"); MultipartBody book = wc.get(MultipartBody.class); Book b = book.getRootAttachment().getObject(Book.class); assertEquals(888L, b.getId()); }
@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 testUseProxyToAddBookAndSimpleParts() throws Exception { MultipartStore store = JAXRSClientFactory.create("http://localhost:" + PORT, MultipartStore.class); HTTPConduit conduit = WebClient.getConfig(store).getHttpConduit(); conduit.getClient().setReceiveTimeout(1000000); Book b = store.testAddBookAndSimpleParts(new Book("CXF in Action", 124L), "1", 2); assertEquals(124L, b.getId()); assertEquals("CXF in Action - 12", b.getName()); }