本文整理了Java中io.vertx.reactivex.ext.web.client.HttpResponse
类的一些代码示例,展示了HttpResponse
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse
类的具体详情如下:
包路径:io.vertx.reactivex.ext.web.client.HttpResponse
类名称:HttpResponse
暂无
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() throws Exception {
WebClient client = WebClient.create(vertx);
Single<HttpResponse<Data>> request = client.get(8080, "localhost", "/")
.as(BodyCodec.json(Data.class))
.rxSend();
// Fire the request
request.subscribe(resp -> System.out.println("Server content " + resp.body().message));
// Again
request.subscribe(resp -> System.out.println("Server content " + resp.body().message));
// And again
request.subscribe(resp -> System.out.println("Server content " + resp.body().message));
}
}
代码示例来源:origin: nemtech/nem2-sdk-java
static JsonObject mapJsonObjectOrError(final HttpResponse<JsonObject> response) {
if (response.statusCode() < 200 || response.statusCode() > 299) {
throw new RuntimeException(response.statusMessage());
}
return response.body();
}
代码示例来源:origin: io.gravitee.elasticsearch/gravitee-common-elasticsearch
@Override
public Completable putTemplate(String templateName, String template) {
return httpClient
.put(URL_TEMPLATE + '/' + templateName)
.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
.rxSendBuffer(Buffer.buffer(template))
.flatMapCompletable(response -> {
if (response.statusCode() != HttpStatusCode.OK_200) {
logger.error("Unable to put template mapping: status[{}] template[{}] response[{}]",
response.statusCode(), template, response.body());
return Completable.error(new ElasticsearchException("Unable to put template mapping"));
}
return Completable.complete();
});
}
代码示例来源:origin: io.gravitee.am.identityprovider/gravitee-am-identityprovider-oauth2-generic
private Maybe<User> profile(String accessToken) {
return client.getAbs(configuration.getUserProfileUri())
.putHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken)
.rxSend()
.toMaybe()
.map(httpClientResponse -> {
if (httpClientResponse.statusCode() != 200) {
throw new BadCredentialsException(httpClientResponse.statusMessage());
}
return createUser(httpClientResponse.bodyAsJsonObject());
});
}
代码示例来源:origin: com.cv4j.netdiscovery/netdiscovery-core
@Override
public Response apply(HttpResponse<String> stringHttpResponse) throws Exception {
String html = stringHttpResponse.body();
Response response = new Response();
response.setContent(html.getBytes());
response.setStatusCode(stringHttpResponse.statusCode());
response.setContentType(stringHttpResponse.getHeader("Content-Type"));
if (Preconditions.isNotBlank(stringHttpResponse.cookies())) {
for (String cookieStr:stringHttpResponse.cookies()) {
} else {
for (String cookieStr:stringHttpResponse.cookies()) {
代码示例来源:origin: io.gravitee.elasticsearch/gravitee-common-elasticsearch
@Override
public Single<BulkResponse> bulk(final List<String> data) {
if (data != null && !data.isEmpty()) {
String content = data.stream().collect(Collectors.joining());
return httpClient
.post(URL_BULK)
.putHeader(HttpHeaders.CONTENT_TYPE, "application/x-ndjson")
.rxSendBuffer(Buffer.buffer(content))
.map(response -> {
if (response.statusCode() != HttpStatusCode.OK_200) {
logger.error("Unable to bulk index data: status[{}] data[{}] response[{}]",
response.statusCode(), content, response.body());
throw new ElasticsearchException("Unable to bulk index data");
}
return mapper.readValue(response.bodyAsString(), BulkResponse.class);
});
}
return Single.never();
}
代码示例来源:origin: Cognifide/knotx
private Object[] logResponseData(Pair<ClientRequest, ServiceSettings> request,
HttpResponse<Buffer> resp) {
Object[] data = {
request.getLeft().getMethod(),
toUrl(request),
resp.statusCode(),
DataObjectsUtil.toString(resp.headers())};
return data;
}
代码示例来源:origin: Cognifide/knotx
private void testGetRequest(VertxTestContext context, Vertx vertx, String url,
String expectedResult) {
WebClient client = WebClient.create(vertx);
Single<HttpResponse<Buffer>> httpResponseSingle = client
.get(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, url).rxSend();
subscribeToResult_shouldSucceed(context, httpResponseSingle,
resp -> {
assertEquals(expectedResult, resp.body().toString(),
"Wrong engines processed request, expected " + expectedResult);
assertEquals(HttpResponseStatus.OK.code(), resp.statusCode());
assertNotNull(resp.getHeader(EXPECTED_RESPONSE_HEADER));
assertEquals(EXPECTED_XSERVER_HEADER_VALUE,
resp.getHeader(EXPECTED_RESPONSE_HEADER));
});
}
代码示例来源:origin: Cognifide/knotx
@Test
@KnotxApplyConfiguration("io/knotx/server/test-server.json")
public void whenRequestingPostGlobalPath_expectGlobalBC(
VertxTestContext context, Vertx vertx) {
createPassThroughKnot(vertx, "test-splitter");
createPassThroughKnot(vertx, "test-assembler");
createSimpleKnot(vertx, "B-engine", "+B", "go-c");
createSimpleKnot(vertx, "C-engine", "+C", null);
testPostRequest(context, vertx, "/content/simple.html", resp -> {
assertEquals(HttpResponseStatus.OK.code(), resp.statusCode());
assertNotNull(resp.getHeader(EXPECTED_RESPONSE_HEADER));
assertEquals(EXPECTED_XSERVER_HEADER_VALUE,
resp.getHeader(EXPECTED_RESPONSE_HEADER));
assertEquals("global+B+C", resp.bodyAsString(),
"Wrong engines processed request, expected 'global+B+C'");
});
}
代码示例来源:origin: io.gravitee.am.identityprovider/gravitee-am-identityprovider-github
private Maybe<String> authenticate(Authentication authentication) {
// prepare body request parameters
List<NameValuePair> urlParameters = new ArrayList<>();
urlParameters.add(new BasicNameValuePair(CLIENT_ID, configuration.getClientId()));
urlParameters.add(new BasicNameValuePair(CLIENT_SECRET, configuration.getClientSecret()));
urlParameters.add(new BasicNameValuePair(REDIRECT_URI, (String) authentication.getAdditionalInformation().get(REDIRECT_URI)));
urlParameters.add(new BasicNameValuePair(CODE, (String) authentication.getCredentials()));
String bodyRequest = URLEncodedUtils.format(urlParameters);
return client.postAbs(configuration.getAccessTokenUri())
.putHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(bodyRequest.length()))
.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED)
.rxSendBuffer(Buffer.buffer(bodyRequest))
.toMaybe()
.map(httpResponse -> {
if (httpResponse.statusCode() != 200) {
throw new BadCredentialsException(httpResponse.statusMessage());
}
Map<String, String> bodyResponse = URLEncodedUtils.format(httpResponse.bodyAsString());
return bodyResponse.get("access_token");
});
}
代码示例来源:origin: io.knotx/knotx-databridge-adapter-http
private void logResponse(Pair<ClientRequest, HttpDataSourceSettings> request,
HttpResponse<Buffer> resp) {
if (resp.statusCode() >= 400 && resp.statusCode() < 600) {
LOGGER.error("{} {} -> Got response {}, headers[{}]",
logResponseData(request, resp));
} else if (LOGGER.isDebugEnabled()) {
LOGGER.debug("{} {} -> Got response {}, headers[{}]",
logResponseData(request, resp));
}
}
代码示例来源:origin: Cognifide/knotx
@Test
@KnotxApplyConfiguration("io/knotx/server/test-server-csrf.json")
public void whenRequestingGetLocalPath_expectLocalAC(
VertxTestContext context, Vertx vertx) {
createPassThroughKnot(vertx, "test-splitter");
createPassThroughKnot(vertx, "test-assembler");
createSimpleKnot(vertx, "some-knot", "test", null);
WebClient client = WebClient.create(vertx);
Single<HttpResponse<io.vertx.reactivex.core.buffer.Buffer>> httpResponseSingle = client
.get(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, "/content/local/simple.html")
.rxSend();
subscribeToResult_shouldSucceed(context, httpResponseSingle, response -> {
assertEquals(HttpResponseStatus.OK.code(), response.statusCode());
assertTrue(response.getHeader(EXPECTED_RESPONSE_HEADER) != null);
assertEquals(EXPECTED_XSERVER_HEADER_VALUE,
response.getHeader(EXPECTED_RESPONSE_HEADER));
assertTrue(response.cookies().stream()
.anyMatch(cookie -> cookie.contains(CSRFHandler.DEFAULT_COOKIE_NAME)));
});
}
代码示例来源:origin: Cognifide/knotx
@Test
@KnotxApplyConfiguration("io/knotx/server/test-server.json")
public void whenRequestingPostGlobalPathAndActionDoRedirect_expectRedirectResponse(
VertxTestContext context, Vertx vertx) {
createPassThroughKnot(vertx, "test-splitter");
createPassThroughKnot(vertx, "test-assembler");
createSimpleFailingKnot(vertx, "A-post-engine", HttpResponseStatus.MOVED_PERMANENTLY.code(),
MultiMap.caseInsensitiveMultiMap().add("location", "/content/failed.html"));
testPostRequest(context, vertx, "/content/local/simple.html", resp -> {
assertEquals(HttpResponseStatus.MOVED_PERMANENTLY.code(), resp.statusCode());
assertEquals("/content/failed.html", resp.getHeader("location"));
assertNotNull(resp.getHeader(EXPECTED_RESPONSE_HEADER));
assertEquals(EXPECTED_XSERVER_HEADER_VALUE,
resp.getHeader(EXPECTED_RESPONSE_HEADER));
});
}
代码示例来源:origin: Cognifide/knotx
@Test
@KnotxApplyConfiguration("io/knotx/server/test-server-csrf.json")
public void whenDoPostSecureWithCSRF_expectOK(
VertxTestContext context, Vertx vertx) {
createPassThroughKnot(vertx, "test-splitter");
createPassThroughKnot(vertx, "test-assembler");
createSimpleKnot(vertx, "some-knot", "test", null);
MultiMap body = MultiMap.caseInsensitiveMultiMap().add("field", "value");
WebClient client = WebClient.create(vertx);
client.get(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, "/content/local/simple.html").send(
ar -> {
if (ar.succeeded()) {
String token = getToken(ar.result().cookies());
client.post(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, "/content/local/simple.html")
.putHeader(CSRFHandler.DEFAULT_HEADER_NAME, token)
.putHeader(HttpHeaderNames.COOKIE.toString(),
CSRFHandler.DEFAULT_COOKIE_NAME + "=" + token)
.sendForm(body, res -> {
if (res.succeeded()) {
assertEquals(HttpResponseStatus.OK.code(), res.result().statusCode());
context.completeNow();
} else {
context.failNow(ar.cause());
}
});
} else {
context.failNow(ar.cause());
}
});
}
代码示例来源:origin: io.gravitee.elasticsearch/gravitee-common-elasticsearch
@Override
public Single<Integer> getVersion() throws ElasticsearchException {
return httpClient
.get(URL_ROOT)
.rxSend()
.doOnError(throwable -> logger.error("Unable to get a connection to Elasticsearch", throwable))
.map(response -> mapper.readTree(response.bodyAsString()).path("version").path("number").asText())
.map(sVersion -> {
float result = Float.valueOf(sVersion.substring(0, 3));
int version = Integer.valueOf(sVersion.substring(0, 1));
if (result < 2) {
logger.warn("Please upgrade to Elasticsearch 2 or later. version={}", version);
}
return version;
});
}
代码示例来源:origin: nemtech/nem2-sdk-java
static JsonArray mapJsonArrayOrError(final HttpResponse<JsonArray> response) {
if (response.statusCode() < 200 || response.statusCode() > 299) {
throw new RuntimeException(response.statusMessage());
}
return response.body();
}
}
代码示例来源:origin: io.gravitee.elasticsearch/gravitee-common-elasticsearch
@Override
public Completable putPipeline(String pipelineName, String pipeline) {
return httpClient
.put(URL_INGEST + '/' + pipelineName)
.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
.rxSendBuffer(Buffer.buffer(pipeline))
.flatMapCompletable(response -> {
switch (response.statusCode()) {
case HttpStatusCode.OK_200:
return Completable.complete();
case HttpStatusCode.BAD_REQUEST_400:
logger.warn("Unable to create ES pipeline: {}", pipelineName);
break;
default:
logger.error("Unable to put pipeline: status[{}] pipeline[{}] response[{}]",
response.statusCode(), pipeline, response.body());
break;
}
return Completable.error(new ElasticsearchException("Unable to create ES pipeline: " + pipelineName));
});
}
代码示例来源:origin: gravitee-io/graviteeio-access-management
private Maybe<User> profile(String accessToken) {
return client.getAbs(configuration.getUserProfileUri())
.putHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken)
.rxSend()
.toMaybe()
.map(httpClientResponse -> {
if (httpClientResponse.statusCode() != 200) {
throw new BadCredentialsException(httpClientResponse.statusMessage());
}
return createUser(httpClientResponse.bodyAsJsonObject());
});
}
代码示例来源:origin: io.gravitee.elasticsearch/gravitee-common-elasticsearch
/**
* Perform an HTTP search query
* @param indexes indexes names. If null search on all indexes
* @param type document type separated by comma. If null search on all types
* @param query json body query
* @return elasticsearch response
*/
public Single<SearchResponse> search(final String indexes, final String type, final String query) {
// index can be null _search on all index
final StringBuilder url = new StringBuilder()
.append('/')
.append(indexes);
if (type != null) {
url.append('/').append(type);
}
url.append(URL_SEARCH);
return httpClient
.post(url.toString())
.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
.rxSendBuffer(Buffer.buffer(query))
.map(response -> {
if (response.statusCode() != HttpStatusCode.OK_200) {
logger.error("Unable to search: url[{}] status[{}] query[{}] response[{}]",
url.toString(), response.statusCode(), query, response.body());
throw new ElasticsearchException("Unable to search");
}
return mapper.readValue(response.bodyAsString(), SearchResponse.class);
});
}
代码示例来源:origin: io.knotx/knotx-databridge-adapter-http
private Object[] logResponseData(Pair<ClientRequest, HttpDataSourceSettings> request,
HttpResponse<Buffer> resp) {
Object[] data = {
request.getLeft().getMethod(),
toUrl(request),
resp.statusCode(),
DataObjectsUtil.toString(resp.headers())};
return data;
}
内容来源于网络,如有侵权,请联系作者删除!