本文整理了Java中org.apache.cxf.jaxrs.client.WebClient.get()
方法的一些代码示例,展示了WebClient.get()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebClient.get()
方法的具体详情如下:
包路径:org.apache.cxf.jaxrs.client.WebClient
类名称:WebClient
方法名:get
[英]Does HTTP GET invocation
[中]HTTP是否得到调用
代码示例来源: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/cxf
@Test
public void testBooksAreReturned() throws JsonProcessingException {
Response r = createWebClient("/rest/api/bookstore", MediaType.APPLICATION_JSON).get();
assertEquals(Status.OK.getStatusCode(), r.getStatus());
final Book[] books = r.readEntity(Book[].class);
assertThat(Arrays.asList(books), hasItems(new Book("New Book #1", 1), new Book("New Book #2", 2)));
r.close();
}
代码示例来源:origin: apache/tika
@Override
public String translate(String text, String sourceLanguage,
String targetLanguage) throws TikaException, IOException {
if (!this.isAvailable)
return text;
Response response = client.accept(MediaType.APPLICATION_JSON)
.query("key", apiKey).query("source", sourceLanguage)
.query("target", targetLanguage).query("q", text).get();
BufferedReader reader = new BufferedReader(new InputStreamReader(
(InputStream) response.getEntity(), UTF_8));
String line = null;
StringBuffer responseText = new StringBuffer();
while ((line = reader.readLine()) != null) {
responseText.append(line);
}
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonResp = mapper.readTree(responseText.toString());
return jsonResp.findValuesAsText("translatedText").get(0);
}
代码示例来源: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/cxf
@Test
public void testThatValidationConstraintsAreViolatedWhenBookIdIsNotSet() {
final Response r = createWebClient("/bookstore/book").get();
assertEquals(Status.BAD_REQUEST.getStatusCode(), r.getStatus());
}
代码示例来源: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
@Override
public String translate(String text, String sourceLanguage,
String targetLanguage) throws TikaException, IOException {
if (!this.isAvailable)
return text;
Response response = client.accept(MediaType.APPLICATION_JSON)
.query("user_key", userKey).query("source", sourceLanguage)
.query("target", targetLanguage).query("q", text).get();
BufferedReader reader = new BufferedReader(new InputStreamReader(
(InputStream) response.getEntity(), UTF_8));
String line = null;
StringBuffer responseText = new StringBuffer();
while ((line = reader.readLine()) != null) {
responseText.append(line);
}
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonResp = mapper.readTree(responseText.toString());
if (jsonResp.findValuesAsText("errors").isEmpty()) {
return jsonResp.findValuesAsText("translation").get(0);
} else {
throw new TikaException(jsonResp.findValue("errors").get(0).asText());
}
}
代码示例来源: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/cxf
@Test
public void testGetAllBooksIs() throws Exception {
final Response response = createWebClient("/bookstore/is", MediaType.TEXT_PLAIN).get();
try {
assertEquals(200, response.getStatus());
assertThat(response.readEntity(String.class), equalTo(IOUtils.readStringFromStream(
getClass().getResourceAsStream("/files/books.txt"))));
} finally {
response.close();
}
}
代码示例来源: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
private void awaitServerStartup() throws Exception {
Instant started = Instant.now();
long elapsed = Duration.between(started, Instant.now()).toMillis();
WebClient client = WebClient.create(endPoint+"/tika").accept("text/plain");
while (elapsed < 30000) {
try {
Response response = client.get();
if (response.getStatus() == 200) {
return;
}
LOG.info("tika test client failed to connect to server with status: {}", response.getStatus());
} catch (javax.ws.rs.ProcessingException e) {
LOG.info("tika test client failed to connect to server: {}", e.getMessage());
LOG.debug("tika test client failed to connect to server", e);
}
Thread.sleep(100);
elapsed = Duration.between(started, Instant.now()).toMillis();
}
}
代码示例来源:origin: apache/cxf
@Test
public void testThatNoValidationConstraintsAreViolatedWhenBookIdIsSet() {
final Response r = createWebClient("/bookstore/book").query("id", "123").get();
assertEquals(Status.OK.getStatusCode(), r.getStatus());
}
代码示例来源: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/cxf
@Test
public void testThatMinValidationFails() {
final Response r = createWebClient("/bookstore/books").query("page", "0").get();
assertEquals(Status.BAD_REQUEST.getStatusCode(), r.getStatus());
}
代码示例来源: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/cxf
@Test
public void testThatValidationConstraintsAreViolatedWhenBookNameIsNotSet() {
final Response r = createWebClient("/bookstore/book").query("id", "124").get();
assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), r.getStatus());
}
代码示例来源:origin: apache/tika
@Test
public void testGetVersion() throws Exception {
Response response = WebClient
.create(endPoint + VERSION_PATH)
.type("text/plain")
.accept("text/plain")
.get();
assertEquals(new Tika().toString(),
getStringFromInputStream((InputStream) response.getEntity()));
}
}
内容来源于网络,如有侵权,请联系作者删除!