当前位置: 首页>>代码示例>>Java>>正文


Java HttpClient.getNow方法代码示例

本文整理汇总了Java中io.vertx.core.http.HttpClient.getNow方法的典型用法代码示例。如果您正苦于以下问题:Java HttpClient.getNow方法的具体用法?Java HttpClient.getNow怎么用?Java HttpClient.getNow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.vertx.core.http.HttpClient的用法示例。


在下文中一共展示了HttpClient.getNow方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: hello3

import io.vertx.core.http.HttpClient; //导入方法依赖的package包/类
@Path("3")
@GET
public void hello3(@Suspended final AsyncResponse asyncResponse,
	      // Inject the Vertx instance
	      @Context Vertx vertx){
	System.err.println("Creating client");
	HttpClientOptions options = new HttpClientOptions();
	options.setSsl(true);
	options.setTrustAll(true);
	options.setVerifyHost(false);
	HttpClient client = vertx.createHttpClient(options);
	client.getNow(443,
			"www.google.com", 
			"/robots.txt", 
			resp -> {
				System.err.println("Got response");
				resp.bodyHandler(body -> {
					System.err.println("Got body");
					asyncResponse.resume(Response.ok(body.toString()).build());
				});
			});
	System.err.println("Created client");
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:24,代码来源:MyResource.java

示例2: hello4

import io.vertx.core.http.HttpClient; //导入方法依赖的package包/类
@Path("4")
@GET
public void hello4(@Suspended final AsyncResponse asyncResponse,
	      // Inject the Vertx instance
	      @Context Vertx vertx){
	System.err.println("Creating client");
	HttpClientOptions options = new HttpClientOptions();
	options.setSsl(true);
	options.setTrustAll(true);
	options.setVerifyHost(false);
	HttpClient client = vertx.createHttpClient(options);
	ObservableHandler<HttpClientResponse> responseHandler = RxHelper.observableHandler();
	client.getNow(443,
			"www.google.com", 
			"/robots.txt", 
			responseHandler.toHandler());
	
	ObservableHandler<Buffer> bodyHandler = RxHelper.observableHandler();
	responseHandler.subscribe(resp -> {
		System.err.println("Got response");
		resp.bodyHandler(bodyHandler.toHandler());
	});
	
	bodyHandler.subscribe(body -> {
		System.err.println("Got body");
		asyncResponse.resume(Response.ok(body.toString()).build());
	});
	System.err.println("Created client");
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:30,代码来源:MyResource.java

示例3: testGet

import io.vertx.core.http.HttpClient; //导入方法依赖的package包/类
@Test(timeout = 3000L)
public void testGet(TestContext context) throws Exception {
    HttpClient client = vertx.createHttpClient();
    Async async = context.async();
    client.getNow(port, "localhost", "/todos/164", response -> response.bodyHandler(body -> {
        context.assertEquals(getTodoFromJson(body.toString()), todoEx);
        client.close();
        async.complete();
    }));
}
 
开发者ID:sczyh30,项目名称:todo-backend-vert.x,代码行数:11,代码来源:TodoApiTest.java

示例4: testSampleService

import io.vertx.core.http.HttpClient; //导入方法依赖的package包/类
@Test
public void testSampleService(TestContext context) {

    final Async async = context.async();
    HttpClient client = vertx.createHttpClient();
    int deployedHttpPort = Verticle.Facade.deploymentOptions.getConfig().getInteger("http-port");

    // Any id should be accepted in this first test implementation
    client.getNow(
            deployedHttpPort, "localhost", "/scale/13",
            response -> {
                response.handler(body -> {
                    context.assertTrue(body.toString().contains("#13"));
                });
            });

    // Negative ids are incorrect, they should be rejected
    client.getNow(
            deployedHttpPort, "localhost", "/scale/-13",
            response -> {
                response.handler(body -> {
                    context.assertTrue(body.toString().contains("does not exist"));
                });
            });

    async.complete();
}
 
开发者ID:lysid,项目名称:scales,代码行数:28,代码来源:ScalesIntegrationTests.java


注:本文中的io.vertx.core.http.HttpClient.getNow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。