org.apache.cxf.jaxrs.client.WebClient.close()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(133)

本文整理了Java中org.apache.cxf.jaxrs.client.WebClient.close()方法的一些代码示例,展示了WebClient.close()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebClient.close()方法的具体详情如下:
包路径:org.apache.cxf.jaxrs.client.WebClient
类名称:WebClient
方法名:close

WebClient.close介绍

暂无

代码示例

代码示例来源:origin: apache/tika

/**
 * Load the supported languages from the <a href="https://developer.lingo24.com/premium-machine-translation-api">Premium MT API</a>.
 * Support is continually expanding.
 * @return <code>Set<String></code> of supported languages.
 */
private Set<String> getAllLanguages() {
  Set<String> languages = new HashSet<>();
  if (!isAvailable) {
    return languages;
  }
  WebClient _client = null;
  try {
    _client = WebClient.create(LINGO24_TRANSLATE_URL_BASE + LINGO24_SOURCELANG_ACTION);
    Response response = _client.accept(MediaType.APPLICATION_JSON)
        .query("user_key", userKey).get();
    String json = response.readEntity(String.class);
    JsonArray jsonArray = new JsonParser().parse(json).getAsJsonObject().get("source_langs").getAsJsonArray();
    for (JsonElement jsonElement : jsonArray) {
      languages.add(jsonElement.getAsJsonArray().get(0).getAsString());
    }
  } catch (Throwable e) {
    LOG.warn("problem detecting", e);
  } finally {
    if (_client != null) {
      _client.close();
    }
  }
  return languages;
}

代码示例来源:origin: apache/cxf

@Override
public void close() {
  if (!closed) {
    synchronized (baseClients) {
      for (WebClient wc : baseClients) {
        wc.close();
      }
    }
    baseClients = null;
    closed = true;
  }
}

代码示例来源:origin: org.apache.cxf/cxf-rt-rs-client

@Override
public void close() {
  if (!closed) {
    synchronized (baseClients) {
      for (WebClient wc : baseClients) {
        wc.close();
      }
    }
    baseClients = null;
    closed = true;
  }
}

代码示例来源:origin: stackoverflow.com

// load page using HTML Unit and fire scripts
WebClient webClient = new WebClient();
HtmlPage myPage = webClient.getPage(myURL);

// convert page to generated HTML and convert to document
doc = Jsoup.parse(myPage.asXml());

// do something with html content
System.out.println(doc.html());

// clean up resources        
webClient.close();

代码示例来源:origin: stackoverflow.com

// capture rendered page
WebClient webClient = new WebClient();
HtmlPage myPage = webClient.getPage("https://pokevision.com");

// convert to jsoup dom
Document doc = Jsoup.parse(myPage.asXml());

// extract data using jsoup selectors
Elements images = doc.select("img[src~=(?i)\\.(png|jpe?g|gif)]");
for (Element image : images) {
  System.out.println("src : " + image.attr("src"));
}

// clean up resources
webClient.close();

代码示例来源:origin: stackoverflow.com

// load page using HTML Unit and fire scripts
WebClient webClient = new WebClient();
HtmlPage myPage = webClient.getPage(myURL);

// convert page to generated HTML and convert to document
Document doc = Jsoup.parse(myPage.asXml(), baseURI);

// clean up resources        
webClient.close();

代码示例来源:origin: stackoverflow.com

WebClient webClient = new WebClient(BrowserVersion.CHROME);

String url = "https://github.com/login";

webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);

HtmlPage page = webClient.getPage(url);
DomElement form = (DomElement) page.querySelector("form");

System.out.println(form.asXml());

webClient.close();

代码示例来源:origin: stackoverflow.com

try(final WebClient webClient = new WebClient(BrowserVersion.CHROME)) {
   java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF);
   webClient.setAjaxController(new NicelyResynchronizingAjaxController());
   webClient.getOptions().setThrowExceptionOnScriptError(false);
   webClient.getOptions().setUseInsecureSSL(true);
   webClient.waitForBackgroundJavaScript(5 * 1000);         
   HtmlPage page = webClient.getPage("https://jumpseller.cl/support/webpayplus/");
   String stringToSave = page.asXml(); // It's a string with full HTML-code, if need you can save it to file.
   webClient.close();  
 }

代码示例来源:origin: stackoverflow.com

WebClient client = new WebClient(BrowserVersion.CHROME);
 client.getOptions().setJavaScriptEnabled(true);
 client.getOptions().setThrowExceptionOnScriptError(false);
 client.getOptions().setThrowExceptionOnFailingStatusCode(false);
 HtmlPage page = client.getPage("http://yoursite.com/");
 HtmlTextInput user = page.getElementByName("USER_ID");
 user.setValueAttribute("youruser");
 HtmlPasswordInput password = page.getElementByName("PWD");
 password.setValueAttribute("yourpassword");
 HtmlButtonInput loginButton = (HtmlButtonInput) page.getByXPath("//input[@class='loginbtn']").get(0);
 page = loginButton.click();
 System.out.println(page.asText());
 client.close();

代码示例来源:origin: apache/cxf

@Test
public void testGetBookAsyncResponse404() throws Exception {
  String address = "http://localhost:" + PORT + "/bookstore/bookheaders/404";
  WebClient wc = createWebClient(address);
  Future<Response> future = wc.async().get(Response.class);
  assertEquals(404, future.get().getStatus());
  wc.close();
}

代码示例来源:origin: apache/cxf

@Test
public void testGetBookResponseProcessingException() throws Exception {
  String address = "http://localhost:" + PORT + "/bookstore/books/123";
  List<Object> providers = new ArrayList<>();
  providers.add(new FaultyBookReader());
  WebClient wc = WebClient.create(address, providers);
  Future<Book> future = wc.async().get(Book.class);
  try {
    future.get();
    fail("Exception expected");
  } catch (ExecutionException ex) {
    assertTrue(ex.getCause() instanceof ResponseProcessingException);
  }
  wc.close();
}

代码示例来源:origin: apache/cxf

@Test
public void testNonExistent() throws Exception {
  String address = "http://168.168.168.168/bookstore";
  List<Object> providers = new ArrayList<>();
  providers.add(new TestResponseFilter());
  WebClient wc = WebClient.create(address, providers);
  Future<Book> future = wc.async().get(Book.class);
  try {
    future.get();
    fail("Exception expected");
  } catch (ExecutionException ex) {
    Throwable cause = ex.getCause();
    assertTrue(cause instanceof ProcessingException);
    assertTrue(ex.getCause().getCause() instanceof IOException);
  } finally {
    wc.close();
  }
}
@Test

代码示例来源:origin: apache/cxf

@Test
public void testGetBookAsync404() throws Exception {
  String address = "http://localhost:" + PORT + "/bookstore/bookheaders/404";
  WebClient wc = createWebClient(address);
  Future<Book> future = wc.async().get(Book.class);
  try {
    future.get();
    fail("Exception expected");
  } catch (ExecutionException ex) {
    assertTrue(ex.getCause() instanceof NotFoundException);
  }
  wc.close();
}

代码示例来源:origin: apache/cxf

@Test
public void testPatchBookInputStream() throws Exception {
  String address = "http://localhost:" + PORT + "/bookstore/patch";
  WebClient wc = WebClient.create(address);
  wc.type("application/xml");
  WebClient.getConfig(wc).getRequestContext().put("use.async.http.conduit", true);
  Book book = wc.invoke("PATCH",
             new ByteArrayInputStream(
               "<Book><name>Patch</name><id>123</id></Book>".getBytes()),
             Book.class);
  assertEquals("Patch", book.getName());
  wc.close();
}

代码示例来源:origin: apache/cxf

@Test
public void testPostBookProcessingException() throws Exception {
  String address = "http://localhost:" + PORT + "/bookstore/";
  List<Object> providers = new ArrayList<>();
  providers.add(new FaultyBookWriter());
  WebClient wc = WebClient.create(address, providers);
  Future<Book> future = wc.async().post(Entity.xml(new Book()), Book.class);
  try {
    future.get();
    fail("Exception expected");
  } catch (ExecutionException ex) {
    assertTrue(ex.getCause() instanceof ProcessingException);
  }
  wc.close();
}

代码示例来源:origin: apache/cxf

@Test
public void testGetBookAsync404Callback() throws Exception {
  String address = "http://localhost:" + PORT + "/bookstore/bookheaders/404";
  WebClient wc = createWebClient(address);
  final Holder<Object> holder = new Holder<>();
  InvocationCallback<Object> callback = createCallback(holder);
  try {
    wc.async().get(callback).get();
    fail("Exception expected");
  } catch (ExecutionException ex) {
    assertTrue(ex.getCause() instanceof NotFoundException);
    assertTrue(ex.getCause() == holder.value);
  }
  wc.close();
}

代码示例来源:origin: apache/cxf

@Test
public void testPatchBook() throws Exception {
  String address = "http://localhost:" + PORT + "/bookstore/patch";
  WebClient wc = WebClient.create(address);
  wc.type("application/xml");
  WebClient.getConfig(wc).getRequestContext().put("use.async.http.conduit", true);
  Book book = wc.invoke("PATCH", new Book("Patch", 123L), Book.class);
  assertEquals("Patch", book.getName());
  wc.close();
}

代码示例来源:origin: apache/cxf

@Test
public void testRetrieveBookCustomMethodAsync() throws Exception {
  String address = "http://localhost:" + PORT + "/bookstore/retrieve";
  WebClient wc = WebClient.create(address);
  wc.accept("application/xml");
  Future<Book> book = wc.async().method("RETRIEVE", Entity.xml(new Book("Retrieve", 123L)),
                     Book.class);
  assertEquals("Retrieve", book.get().getName());
  wc.close();
}

代码示例来源:origin: apache/cxf

@Test
public void testDeleteWithBody() throws Exception {
  String address = "http://localhost:" + PORT + "/bookstore/deletebody";
  WebClient wc = WebClient.create(address);
  wc.type("application/xml").accept("application/xml");
  WebClient.getConfig(wc).getRequestContext().put("use.async.http.conduit", true);
  Book book = wc.invoke("DELETE", new Book("Delete", 123L), Book.class);
  assertEquals("Delete", book.getName());
  wc.close();
}

代码示例来源:origin: apache/cxf

@Test
public void testRetrieveBookCustomMethodAsyncSync() throws Exception {
  String address = "http://localhost:" + PORT + "/bookstore/retrieve";
  WebClient wc = WebClient.create(address);
  // Setting this property is not needed given that
  // we have the async conduit loaded in the test module:
  // WebClient.getConfig(wc).getRequestContext().put("use.async.http.conduit", true);
  wc.type("application/xml").accept("application/xml");
  Book book = wc.invoke("RETRIEVE", new Book("Retrieve", 123L), Book.class);
  assertEquals("Retrieve", book.getName());
  wc.close();
}

相关文章

WebClient类方法