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

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

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

WebClient.create介绍

[英]Creates WebClient
[中]创建网络客户端

代码示例

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

protected static boolean canRun() {
  Response response = null;
  try {
    response = WebClient.create(readRestUrl() + GROBID_ISALIVE_PATH)
        .accept(MediaType.TEXT_HTML).get();
    String resp = response.readEntity(String.class);
    return resp != null && !resp.equals("") && resp.startsWith("<h4>");
  } catch (Exception e) {
    //swallow...can't run
    return false;
  }
}

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

protected static boolean canRun() {
    try {
      Response response = WebClient
          .create(TEXT_REST_HOST + TEXT_LID_PATH)
          .get();
      String json = response.readEntity(String.class);
      JsonArray jsonArray = new JsonParser().parse(json).getAsJsonObject().get("all_languages").getAsJsonArray();
      return jsonArray.size() != 0;
    } catch (Exception e) {
      LOG.warn("Can't run", e);
      return false;
    }
  }
}

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

public NLTKNERecogniser(){
  try {
    String restHostUrlStr="";
    try {
      restHostUrlStr = readRestUrl();
    } catch (IOException e) {
      LOG.warn("Can't read rest url", e);
    }
    if (restHostUrlStr == null || restHostUrlStr.equals("")) {
      this.restHostUrlStr = NLTK_REST_HOST;
    } else {
      this.restHostUrlStr = restHostUrlStr;
    }
    Response response = WebClient.create(restHostUrlStr).accept(MediaType.TEXT_HTML).get();
    int responseCode = response.getStatus();
    if(responseCode == 200){
      available = true;
    }
    else{
      LOG.info("NLTKRest Server is not running");
    }
  } catch (Exception e) {
    LOG.warn(e.getMessage(), e);
  }
}

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

public GrobidNERecogniser(){
  try {
      String restHostUrlStr="";
      try {
        restHostUrlStr = readRestUrl();
      } catch (IOException e) {
        LOG.warn("couldn't read rest url", e);
      }
      if (restHostUrlStr == null || restHostUrlStr.equals("")) {
        this.restHostUrlStr = GROBID_REST_HOST;
      } else {
        this.restHostUrlStr = restHostUrlStr;
      }
      Response response = WebClient.create(restHostUrlStr).accept(MediaType.APPLICATION_JSON).get();
      int responseCode = response.getStatus();
      if(responseCode == 200){
        available = true;
      }
      else{
        LOG.info("Grobid REST Server is not running");
      }

    }
    catch (Exception e) {
      LOG.info(e.getMessage(), e);
    }
}

代码示例来源: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/tika

private Set<String> getAllLanguages() {
  Set<String> languages = new HashSet<>();
  try {
    Response response = WebClient
        .create(restHostUrlStr + TEXT_LID_PATH)
        .get();
    String json = response.readEntity(String.class);
    JsonArray jsonArray = new JsonParser().parse(json).getAsJsonObject().get("all_languages").getAsJsonArray();
    for (JsonElement jsonElement : jsonArray) {
      languages.add(jsonElement.toString());
    }
  } catch (Exception e) {
    LOG.warn("problem getting and parsing json", e);
  }
  return languages;
}

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

public void parse(String filePath, ContentHandler handler, Metadata metadata,
         ParseContext context) throws FileNotFoundException {
  File pdfFile = new File(filePath);
  ContentDisposition cd = new ContentDisposition(
      "form-data; name=\"input\"; filename=\"" + pdfFile.getName() + "\"");
  Attachment att = new Attachment("input", new FileInputStream(pdfFile), cd);
  MultipartBody body = new MultipartBody(att);
  Response response = WebClient
      .create(restHostUrlStr + GROBID_PROCESSHEADER_PATH)
      .accept(MediaType.APPLICATION_XML).type(MediaType.MULTIPART_FORM_DATA)
      .post(body);
  try {
    String resp = response.readEntity(String.class);
    Metadata teiMet = new TEIDOMParser().parse(resp, context);
    for (String key : teiMet.names()) {
      metadata.add("grobid:header_" + key, teiMet.get(key));
    }
  } catch (Exception e) {
    LOG.warn("Couldn't read response", e);
  }
}

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

WebClient client = WebClient.create(YANDEX_TRANSLATE_URL_BASE);
Response response = client.accept(MediaType.APPLICATION_JSON)
    .query("key", this.apiKey).query("lang", langCode)
    .query("text", text).get();
BufferedReader reader = new BufferedReader(new InputStreamReader(
    (InputStream) response.getEntity(), UTF_8));

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

@Test
public void testHelloWorld() throws Exception {
  Response response = WebClient.create(endPoint + TIKA_PATH)
      .type("text/plain").accept("text/plain").get();
  assertEquals(TikaResource.GREETING,
      getStringFromInputStream((InputStream) response.getEntity()));
}

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

@Test
public void testGetField_XXX_NotFound() throws Exception {
  Response response = WebClient.create(endPoint + META_PATH + "/xxx").type("application/msword")
      .accept(MediaType.APPLICATION_JSON).put(ClassLoader.getSystemResourceAsStream(TikaResourceTest.TEST_DOC));
  Assert.assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());
}

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

@Test
public void testPasswordXLSXML() throws Exception {
  Response response = WebClient.create(endPoint + TIKA_PATH)
      .type("application/vnd.ms-excel")
      .accept("text/xml")
      .put(ClassLoader.getSystemResourceAsStream("password.xls"));
  assertEquals(UNPROCESSEABLE, response.getStatus());
}

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

@Test
public void testPasswordXLSHTML() throws Exception {
  Response response = WebClient.create(endPoint + TIKA_PATH)
      .type("application/vnd.ms-excel")
      .accept("text/html")
      .put(ClassLoader.getSystemResourceAsStream("password.xls"));
  assertEquals(UNPROCESSEABLE, response.getStatus());
}

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

@Test
public void testPasswordXLS() throws Exception {
  Response response = WebClient.create(endPoint + TIKA_PATH)
      .type("application/vnd.ms-excel")
      .accept("text/plain")
      .put(ClassLoader.getSystemResourceAsStream("password.xls"));
  assertEquals(UNPROCESSEABLE, response.getStatus());
}

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

@Test
public void test415() throws Exception {
  Response response = WebClient.create(endPoint + UNPACKER_PATH)
      .type("xxx/xxx")
      .accept("*/*")
      .put(ClassLoader.getSystemResourceAsStream(TEST_DOC_WAV));
  assertEquals(415, response.getStatus());
}

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

@Test
public void testApplicationWadl() throws Exception {
  Response response = WebClient
      .create(endPoint + TIKA_PATH + "?_wadl")
      .accept("text/plain").get();
  String resp = getStringFromInputStream((InputStream) response
      .getEntity());
  assertTrue(resp.startsWith("<application"));
}

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

providers.add(jacksonJsonProvider);
client = WebClient.create(networkURI, providers);
jsonNode.put("inputText", inputText);
Response response = client.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).post(jsonNode);
BufferedReader reader = new BufferedReader(new InputStreamReader(
  (InputStream) response.getEntity(), UTF_8));

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

@Test
  public void testProperPathWelcome() throws Exception{
     Response response = WebClient
     .create(endPoint + WELCOME_PATH)
       .type("text/html")
       .accept("text/html")
       .get();

     String html = getStringFromInputStream((InputStream) response.getEntity());
     assertContains(PATH_RESOURCE, html);
     assertContains(PATH_RESOURCE_2, html);
  }
}

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

@Test
public void testGetField_Author_TEXT_Partial_BAD_REQUEST() throws Exception {
  InputStream stream = ClassLoader.getSystemResourceAsStream(TikaResourceTest.TEST_DOC);
  Response response = WebClient.create(endPoint + META_PATH + "/Author").type("application/msword")
      .accept(MediaType.TEXT_PLAIN).put(copy(stream, 8000));
  Assert.assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}

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

@Test
public void testWMFInRTF() throws Exception {
  Response response = WebClient.create(endPoint + TIKA_PATH)
      .type("application/rtf")
      .accept("text/plain")
      .put(ClassLoader.getSystemResourceAsStream("testRTF_npeFromWMFInTikaServer.rtf"));
  String responseMsg = getStringFromInputStream((InputStream) response
      .getEntity());
  assertTrue(responseMsg.contains("Example text"));
}

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

@Test
public void testSimpleWordXML() throws Exception {
  Response response = WebClient.create(endPoint + TIKA_PATH)
      .type("application/msword")
      .accept("text/xml")
      .put(ClassLoader.getSystemResourceAsStream(TEST_DOC));
  String responseMsg = getStringFromInputStream((InputStream) response
      .getEntity());
  assertTrue(responseMsg.contains("test"));
}

相关文章

WebClient类方法