本文整理了Java中io.vertx.reactivex.ext.web.client.HttpRequest
类的一些代码示例,展示了HttpRequest
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest
类的具体详情如下:
包路径:io.vertx.reactivex.ext.web.client.HttpRequest
类名称:HttpRequest
暂无
代码示例来源: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: vert-x3/vertx-examples
@Override
public void start() throws Exception {
WebClient client = WebClient.create(vertx);
client.get(80, "perdu.com", "/")
.rxSend()
.map(HttpResponse::bodyAsString)
.subscribe(
s -> LOGGER.info("From web client: " + s),
Throwable::printStackTrace
);
}
}
代码示例来源:origin: io.gravitee.am.identityprovider/gravitee-am-identityprovider-github
private Maybe<User> profile(String accessToken) {
return client.getAbs(configuration.getUserProfileUri())
.putHeader(HttpHeaders.AUTHORIZATION, "token " + accessToken)
.rxSend()
.toMaybe()
.map(httpClientResponse -> {
if (httpClientResponse.statusCode() != 200) {
throw new BadCredentialsException(httpClientResponse.statusMessage());
}
return createUser(httpClientResponse.bodyAsJsonObject());
});
}
代码示例来源:origin: com.cv4j.netdiscovery/netdiscovery-core
httpRequest = webClient.get(443,request.getUrlParser().getHost(),Preconditions.isNotBlank(request.getUrlParser().getQuery())?request.getUrlParser().getPath()+"?"+request.getUrlParser().getQuery():request.getUrlParser().getPath()).ssl(true);
httpRequest = webClient.post(443,request.getUrlParser().getHost(),Preconditions.isNotBlank(request.getUrlParser().getQuery())?request.getUrlParser().getPath()+"?"+request.getUrlParser().getQuery():request.getUrlParser().getPath()).ssl(true);
httpRequest.putHeader(entry.getKey(),entry.getValue());
httpRequest.putHeader("Content-type",request.getHttpRequestBody().getContentType());
HttpRequest<String> stringHttpRequest = httpRequest.as(BodyCodec.string(charset));
Single<HttpResponse<String>> httpResponseSingle = null;
httpResponseSingle = stringHttpRequest.rxSend();
} else if (request.getHttpMethod()==HttpMethod.POST) {
httpResponseSingle = stringHttpRequest.rxSendBuffer(buffer);
} else {
httpResponseSingle = stringHttpRequest.rxSend();
代码示例来源:origin: FroMage/redpipe
.put("code", code);
HttpResponse<JsonObject> response = await(webClient.post(443, "github.com", "/login/oauth/access_token")
.putHeader("Accept", "application/json")
.putHeader("Content-Type", "application/json")
.as(BodyCodec.jsonObject())
.rxSendJsonObject(payload));
代码示例来源: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.acme/acme-forms-adapter-http
private Single<HttpResponse<Buffer>> callService(
Pair<ClientRequest, HttpFormsSettings> serviceData, HttpMethod method) {
final Single<HttpResponse<Buffer>> httpResponse;
final ClientRequest serviceRequest = serviceData.getLeft();
final HttpFormsSettings serviceMetadata = serviceData.getRight();
final HttpRequest<Buffer> request = webClient
.request(method, serviceMetadata.getPort(), serviceMetadata.getDomain(),
serviceRequest.getPath());
updateRequestQueryParams(request, serviceMetadata);
updateRequestHeaders(request, serviceRequest, serviceMetadata);
overrideRequestHeaders(request, serviceMetadata);
if (!serviceRequest.getFormAttributes().isEmpty()) {
httpResponse = request.rxSendForm(serviceRequest.getFormAttributes());
} else {
httpResponse = request.rxSend();
}
return httpResponse;
}
代码示例来源:origin: tsegismont/vertx-musicstore
private Single<Buffer> sendGetRequest(String mbAlbumId) {
return webClient
.getAbs("http://coverartarchive.org")
.uri("/release/" + mbAlbumId + "/front")
.as(BodyCodec.buffer())
.rxSend()
.map(HttpResponse::body);
}
代码示例来源:origin: nemtech/nem2-sdk-java
@Override
public Observable<TransactionAnnounceResponse> announce(SignedTransaction signedTransaction) {
JsonObject requestBody = new JsonObject();
requestBody.put("payload", signedTransaction.getPayload());
return this.client
.putAbs(this.url.toString())
.as(BodyCodec.jsonObject())
.rxSendJson(requestBody)
.toObservable()
.map(Http::mapJsonObjectOrError)
.map(json -> new TransactionAnnounceResponse(new JsonObject(json.toString()).getString("message")));
}
代码示例来源:origin: io.knotx.acme/acme-forms-adapter-http
private void overrideRequestHeaders(HttpRequest<Buffer> request, HttpFormsSettings metadata) {
if (metadata.getAdditionalHeaders() != null) {
metadata.getAdditionalHeaders().forEach(entry -> {
request.putHeader(entry.getKey(), entry.getValue().toString());
});
}
}
代码示例来源: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: Cognifide/knotx
private void testPostRequest(VertxTestContext context, Vertx vertx, String url,
Consumer<HttpResponse<Buffer>> expectedResponse) {
WebClient client = WebClient.create(vertx);
MultiMap formData = MultiMap.caseInsensitiveMultiMap();
formData.add("a", "b");
Single<HttpResponse<Buffer>> httpResponseSingle = client
.post(KnotxServerRoutingTest.KNOTX_SERVER_PORT,
KnotxServerRoutingTest.KNOTX_SERVER_ADDRESS,
url)
.rxSendForm(formData);
subscribeToResult_shouldSucceed(context, httpResponseSingle, expectedResponse);
}
代码示例来源:origin: io.knotx.acme/acme-forms-adapter-http
private void updateRequestQueryParams(HttpRequest<Buffer> request, HttpFormsSettings metadata) {
if (metadata.getQueryParams() != null) {
metadata.getQueryParams().forEach(entry ->
request.addQueryParam(entry.getKey(), entry.getValue().toString())
);
}
}
代码示例来源: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: 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: FroMage/redpipe
.put("code", code);
HttpResponse<JsonObject> response = await(webClient.post(443, "github.com", "/login/oauth/access_token")
.putHeader("Accept", "application/json")
.putHeader("Content-Type", "application/json")
.as(BodyCodec.jsonObject())
.rxSendJsonObject(payload));
代码示例来源: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 Single<HttpResponse<Buffer>> callService(
Pair<ClientRequest, ServiceSettings> serviceData, HttpMethod method) {
final Single<HttpResponse<Buffer>> httpResponse;
final ClientRequest serviceRequest = serviceData.getLeft();
final ServiceSettings serviceMetadata = serviceData.getRight();
final HttpRequest<Buffer> request = webClient
.request(method, serviceMetadata.getPort(), serviceMetadata.getDomain(),
serviceRequest.getPath());
updateRequestQueryParams(request, serviceMetadata);
updateRequestHeaders(request, serviceRequest, serviceMetadata);
overrideRequestHeaders(request, serviceMetadata);
if (!serviceRequest.getFormAttributes().isEmpty()) {
httpResponse = request.rxSendForm(serviceRequest.getFormAttributes());
} else {
httpResponse = request.rxSend();
}
return httpResponse;
}
代码示例来源:origin: nemtech/nem2-sdk-java
@Override
public Observable<TransactionAnnounceResponse> announceAggregateBonded(SignedTransaction signedTransaction) {
JsonObject requestBody = new JsonObject();
requestBody.put("payload", signedTransaction.getPayload());
return this.client
.putAbs(this.url + "/partial")
.as(BodyCodec.jsonObject())
.rxSendJson(requestBody)
.toObservable()
.map(Http::mapJsonObjectOrError)
.map(json -> new TransactionAnnounceResponse(new JsonObject(json.toString()).getString("message")));
}
代码示例来源:origin: io.knotx/knotx-databridge-adapter-http
private void overrideRequestHeaders(HttpRequest<Buffer> request, HttpDataSourceSettings metadata) {
if (metadata.getAdditionalHeaders() != null) {
metadata.getAdditionalHeaders().forEach(entry -> {
request.putHeader(entry.getKey(), entry.getValue().toString());
});
}
}
内容来源于网络,如有侵权,请联系作者删除!