本文整理汇总了Java中io.vertx.reactivex.core.http.HttpClient类的典型用法代码示例。如果您正苦于以下问题:Java HttpClient类的具体用法?Java HttpClient怎么用?Java HttpClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpClient类属于io.vertx.reactivex.core.http包,在下文中一共展示了HttpClient类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: restApiTest
import io.vertx.reactivex.core.http.HttpClient; //导入依赖的package包/类
@Test
public void restApiTest(TestContext testContext) {
HttpClient httpClient = vertx.createHttpClient();
Async async = testContext.async();
httpClient.delete(1234, "localhost", "/books/1", res -> {
testContext.assertEquals(200, res.statusCode());
res.bodyHandler(body -> {
testContext.assertTrue(body.length() == 0);
httpClient.close();
async.complete();
});
}).putHeader("Content-Type", "application/json; charset=utf-8")
.end();
}
开发者ID:BillyYccc,项目名称:vertx-postgresql-starter,代码行数:20,代码来源:DeleteBookByIdHandlerTest.java
示例2: testGetRequest
import io.vertx.reactivex.core.http.HttpClient; //导入依赖的package包/类
private void testGetRequest(TestContext context, String url, String expectedResult) {
HttpClient client = Vertx.newInstance(vertx.vertx()).createHttpClient();
Async async = context.async();
client.getNow(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, url,
resp -> resp.bodyHandler(body -> {
context.assertEquals(HttpResponseStatus.OK.code(), resp.statusCode());
context.assertTrue(resp.getHeader(EXPECTED_RESPONSE_HEADER) != null);
context.assertEquals(EXPECTED_XSERVER_HEADER_VALUE,
resp.getHeader(EXPECTED_RESPONSE_HEADER));
try {
context.assertEquals(body.toString(),
expectedResult, "Wrong engines processed request, expected " + expectedResult);
} catch (Exception e) {
context.fail(e);
}
client.close();
async.complete();
}));
}
开发者ID:Cognifide,项目名称:knotx,代码行数:20,代码来源:KnotxServerRoutingTest.java
示例3: testGetRequest
import io.vertx.reactivex.core.http.HttpClient; //导入依赖的package包/类
private void testGetRequest(TestContext context, String url) {
HttpClient client = Vertx.newInstance(vertx.vertx()).createHttpClient();
Async async = context.async();
client.getNow(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, url,
resp -> {
MultiMap headers = resp.headers();
headers.names().forEach(name -> {
context.assertEquals(resp.statusCode(), 200, "Wrong status code received.");
context
.assertTrue(expectedHeaders.contains(name), "Header " + name + " is not expected.");
context.assertEquals(expectedHeaders.get(name), headers.get(name),
"Wrong value of " + name + " header.");
});
async.complete();
});
}
开发者ID:Cognifide,项目名称:knotx,代码行数:17,代码来源:SampleApplicationHeadersTest.java
示例4: testGetRequest
import io.vertx.reactivex.core.http.HttpClient; //导入依赖的package包/类
private void testGetRequest(TestContext context, String url, String expectedResponseFile) {
HttpClient client = Vertx.newInstance(vertx.vertx()).createHttpClient();
Async async = context.async();
client.getNow(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, url,
resp -> resp.bodyHandler(body -> {
context.assertEquals(resp.statusCode(), HttpResponseStatus.OK.code());
try {
context.assertEquals(Jsoup.parse(body.toString()).body().html().trim(),
Jsoup.parse(FileReader.readText(expectedResponseFile)).body().html().trim());
} catch (Exception e) {
context.fail(e);
}
client.close();
async.complete();
}));
}
开发者ID:Cognifide,项目名称:knotx,代码行数:17,代码来源:SampleApplicationTest.java
示例5: restApiTest
import io.vertx.reactivex.core.http.HttpClient; //导入依赖的package包/类
@Test
public void restApiTest(TestContext testContext) {
HttpClient httpClient = vertx.createHttpClient();
Async async = testContext.async();
httpClient.put(1234, "localhost", "/books/3", res -> {
testContext.assertEquals(200, res.statusCode());
res.bodyHandler(body -> {
testContext.assertTrue(body.length() > 0);
JsonObject expectedResponseBody = new JsonObject()
.put("id", 3)
.put("title", "Java Concurrency in Practice")
.put("category", "java")
.put("publicationDate", "2006-05-19");
testContext.assertEquals(expectedResponseBody, body.toJsonObject());
httpClient.close();
async.complete();
});
}).putHeader("Content-Type", "application/json; charset=utf-8")
.end(new JsonObject()
.put("title", "Java Concurrency in Practice")
.put("category", "java")
.put("publicationDate", "2006-05-19").toString());
}
开发者ID:BillyYccc,项目名称:vertx-postgresql-starter,代码行数:30,代码来源:UpsertBookByIdHandlerTest.java
示例6: restApiTest
import io.vertx.reactivex.core.http.HttpClient; //导入依赖的package包/类
@Test
public void restApiTest(TestContext testContext) {
HttpClient httpClient = vertx.createHttpClient();
Async async = testContext.async();
httpClient.post(1234, "localhost", "/books", res -> {
testContext.assertEquals(200, res.statusCode());
res.bodyHandler(body -> {
testContext.assertTrue(body.length() > 0);
JsonObject expectedResponseBody = new JsonObject()
.put("id", 3)
.put("title", "Design Patterns")
.put("category", "design")
.put("publicationDate", "1995-01-15");
testContext.assertEquals(expectedResponseBody, body.toJsonObject());
httpClient.close();
async.complete();
});
}).putHeader("Content-Type", "application/json; charset=utf-8")
.end(new JsonObject()
.put("id", 3)
.put("title", "Design Patterns")
.put("category", "design")
.put("publicationDate", "1995-01-15").toString());
}
开发者ID:BillyYccc,项目名称:vertx-postgresql-starter,代码行数:31,代码来源:AddBookHandlerTest.java
示例7: get
import io.vertx.reactivex.core.http.HttpClient; //导入依赖的package包/类
private Observable<HttpClientResponse> get(HttpClient client, RequestOptions requestOptions,
MultiMap headers) {
return Observable.unsafeCreate(subscriber -> {
HttpClientRequest req = client.get(requestOptions);
req.headers().addAll(headers);
if (headers.get(HttpHeaderNames.HOST.toString()) != null) {
req.setHost(headers.get(HttpHeaderNames.HOST.toString()));
}
Observable<HttpClientResponse> resp = req.toObservable();
resp.subscribe(subscriber);
req.end();
});
}
开发者ID:Cognifide,项目名称:knotx,代码行数:14,代码来源:HttpRepositoryConnectorProxyImpl.java
示例8: request
import io.vertx.reactivex.core.http.HttpClient; //导入依赖的package包/类
private static Observable<HttpClientResponse> request(HttpClient client, HttpMethod method,
int port, String domain, String uri,
Action1<HttpClientRequest> requestBuilder) {
return Observable.unsafeCreate(subscriber -> {
HttpClientRequest req = client.request(method, port, domain, uri);
Observable<HttpClientResponse> resp = req.toObservable();
resp.subscribe(subscriber);
requestBuilder.call(req);
req.end();
});
}
开发者ID:Cognifide,项目名称:knotx,代码行数:12,代码来源:KnotxServerRoutingTest.java
示例9: testPostRequest
import io.vertx.reactivex.core.http.HttpClient; //导入依赖的package包/类
private void testPostRequest(String url, Action1<HttpClientResponse> expectedResponse) {
HttpClient client = Vertx.newInstance(vertx.vertx()).createHttpClient();
String testBody = "a=b";
Observable<HttpClientResponse> request = request(client, HttpMethod.POST, KNOTX_SERVER_PORT,
KNOTX_SERVER_ADDRESS, url, req -> {
req.headers().set("content-length", String.valueOf(testBody.length()));
req.headers().set("content-type", "application/x-www-form-urlencoded");
req.write(testBody);
});
request.subscribe(expectedResponse::call);
}
开发者ID:Cognifide,项目名称:knotx,代码行数:13,代码来源:KnotxServerRoutingTest.java
示例10: testPostRequest
import io.vertx.reactivex.core.http.HttpClient; //导入依赖的package包/类
private void testPostRequest(TestContext context, String url, Map<String, String> formData,
String expectedResponseFile, boolean ajaxCall) {
HttpClient client = Vertx.newInstance(vertx.vertx()).createHttpClient();
Async async = context.async();
Observable<HttpClientResponse> request = request(client, HttpMethod.POST, KNOTX_SERVER_PORT,
KNOTX_SERVER_ADDRESS, url, req -> {
String bodyForm = formData.entrySet().stream()
.map(entry -> entry.getKey() + "=" + entry.getValue())
.reduce((p1, p2) -> p1 + "&" + p2).get();
req.headers().set("content-length", String.valueOf(bodyForm.length()));
req.headers().set("content-type", "application/x-www-form-urlencoded");
if (ajaxCall) {
req.headers().set("X-Requested-With", "XMLHttpRequest");
}
req.write(bodyForm);
});
request.subscribe(resp -> resp.bodyHandler(body -> {
context.assertEquals(resp.statusCode(), HttpResponseStatus.OK.code());
try {
context.assertEquals(Jsoup.parse(body.toString()).body().html(),
Jsoup.parse(FileReader.readText(expectedResponseFile)).body().html());
} catch (Exception e) {
context.fail(e);
}
async.complete();
}));
}
开发者ID:Cognifide,项目名称:knotx,代码行数:31,代码来源:SampleApplicationTest.java
示例11: testGetServerError
import io.vertx.reactivex.core.http.HttpClient; //导入依赖的package包/类
private void testGetServerError(TestContext context, String url) {
HttpClient client = Vertx.newInstance(vertx.vertx()).createHttpClient();
Async async = context.async();
client.getNow(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, url,
resp -> resp.bodyHandler(body -> {
context.assertEquals(resp.statusCode(), HttpResponseStatus.INTERNAL_SERVER_ERROR.code());
client.close();
async.complete();
}));
}
开发者ID:Cognifide,项目名称:knotx,代码行数:11,代码来源:SampleApplicationTest.java
示例12: websocketClient
import io.vertx.reactivex.core.http.HttpClient; //导入依赖的package包/类
public void websocketClient(Vertx vertx) {
HttpClient client = vertx.createHttpClient(new HttpClientOptions());
client.websocketStream(8080, "localhost", "/the_uri").toObservable().subscribe(
ws -> {
// Use the websocket
},
error -> {
// Could not connect
}
);
}
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:12,代码来源:RxifiedExamples.java
示例13: httpClientRequest
import io.vertx.reactivex.core.http.HttpClient; //导入依赖的package包/类
public void httpClientRequest(Vertx vertx) {
HttpClient client = vertx.createHttpClient(new HttpClientOptions());
HttpClientRequest request = client.request(HttpMethod.GET, 8080, "localhost", "/the_uri");
request.toObservable().subscribe(
response -> {
// Process the response
},
error -> {
// Could not connect
}
);
request.end();
}
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:14,代码来源:RxifiedExamples.java
示例14: createHttpClient
import io.vertx.reactivex.core.http.HttpClient; //导入依赖的package包/类
private HttpClient createHttpClient(Vertx vertx) {
return clientOptions.isEmpty()
? io.vertx.reactivex.core.Vertx.newInstance(vertx).createHttpClient()
: io.vertx.reactivex.core.Vertx.newInstance(vertx)
.createHttpClient(new HttpClientOptions(clientOptions));
}
开发者ID:Cognifide,项目名称:knotx,代码行数:7,代码来源:HttpRepositoryConnectorProxyImpl.java
注:本文中的io.vertx.reactivex.core.http.HttpClient类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论