當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpClientRequest.end方法代碼示例

本文整理匯總了Java中io.vertx.core.http.HttpClientRequest.end方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpClientRequest.end方法的具體用法?Java HttpClientRequest.end怎麽用?Java HttpClientRequest.end使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.vertx.core.http.HttpClientRequest的用法示例。


在下文中一共展示了HttpClientRequest.end方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: asyncPostStringWithData

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
public static void asyncPostStringWithData(String url, String body, ContentType type, String encode, Handler<String> callback) {
        checkInitialized();
        HttpClientRequest req = client.requestAbs(HttpMethod.POST, url, resp -> {
            resp.bodyHandler(buf -> {
                callback.handle(buf.toString());
            });
        });
        switch (type) {
            case XML:
                req.putHeader("content-type", "application/xml;charset=" + encode);
                break;
            case JSON:
                req.putHeader("content-type", "application/json;charset=" + encode);
                break;
            case FORM:
                req.putHeader("content-type", "application/x-www-form-urlencoded" + encode);
                break;
        }
//        req.putHeader("content-length", String.valueOf(body.length()));
//        req.write(body);
        req.end(body, encode);
    }
 
開發者ID:Leibnizhu,項目名稱:AlipayWechatPlatform,代碼行數:23,代碼來源:NetworkUtils.java

示例2: put

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
public void put(URL url,
                Object body,
                String tenantId,
                Handler<HttpClientResponse> responseHandler) {

  HttpClientRequest request = client.putAbs(url.toString(), responseHandler);

  request.headers().add("Accept","application/json, text/plain");
  request.headers().add("Content-type","application/json");

  if(tenantId != null) {
    request.headers().add(TENANT_HEADER, tenantId);
  }

  request.end(Json.encodePrettily(body));
}
 
開發者ID:folio-org,項目名稱:deprecated-mod-metadata,代碼行數:17,代碼來源:HttpClient.java

示例3: updateCredentials

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
private static final Future<HttpClientResponse> updateCredentials(final String authId, final String type, final JsonObject requestPayload, final int expectedResult) {

        final Future<HttpClientResponse> result = Future.future();
        final String uri = String.format(TEMPLATE_URI_CREDENTIALS_INSTANCE, authId, type);

        final HttpClientRequest req = vertx.createHttpClient().put(getPort(), HOST, uri)
                .putHeader(HttpHeaders.CONTENT_TYPE, HttpUtils.CONTENT_TYPE_JSON)
                .handler(response -> {
                    if (response.statusCode() == expectedResult) {
                        result.complete(response);
                    } else {
                        result.fail("update credentials failed, expected status code " + expectedResult + " but got " + response.statusCode());
                    }
                })
                .exceptionHandler(result::fail);

        if (requestPayload == null) {
            req.end();
        } else {
            req.end(requestPayload.encodePrettily());
        }
        return result;
    }
 
開發者ID:eclipse,項目名稱:hono,代碼行數:24,代碼來源:CredentialsRestServerTest.java

示例4: post

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
public void post(URL url,
          Object body,
          String tenantId,
          Handler<HttpClientResponse> responseHandler) {

  HttpClientRequest request = client.postAbs(url.toString(), responseHandler);

  request.headers().add("Accept","application/json, text/plain");
  request.headers().add("Content-type","application/json");

  if(tenantId != null) {
    request.headers().add(TENANT_HEADER, tenantId);
  }

  if(body != null) {
    String encodedBody = Json.encodePrettily(body);

    System.out.println(String.format("POST %s, Request: %s",
      url.toString(), encodedBody));

    request.end(encodedBody);
  }
  else {
    request.end();
  }
}
 
開發者ID:folio-org,項目名稱:deprecated-mod-metadata,代碼行數:27,代碼來源:HttpClient.java

示例5: testKoFormDataSimpleFileWithoutFile

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
@Test()
public void testKoFormDataSimpleFileWithoutFile(TestContext context) {
    Async async = context.async();
    HttpClientRequest req = httpClient.post(TEST_PORT, TEST_HOST, "/formdata/simple/file");
    req.handler(response -> {
        response.bodyHandler(body -> {
            context.assertEquals(response.statusCode(), 400);
            async.complete();
        });
    });
    // Construct multipart data
    req.putHeader(HttpHeaders.CONTENT_TYPE, "multipart/form-data; boundary=MyBoundary");
    req.end();
}
 
開發者ID:phiz71,項目名稱:vertx-swagger,代碼行數:15,代碼來源:FormParameterExtractorTest.java

示例6: postUrlBody

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
private void postUrlBody(String url, String doc,
  Handler<AsyncResult<Void>> future) {
  HttpClientRequest req = client.postAbs(url, res -> {
    Buffer body = Buffer.buffer();
    res.exceptionHandler(d -> future.handle(Future.failedFuture(d.getCause())));
    res.handler(body::appendBuffer);
    res.endHandler(d -> {
      if (res.statusCode() == 201) {
        containerId = body.toJsonObject().getString("Id");
        future.handle(Future.succeededFuture());
      } else {
        String m = "createContainer HTTP error "
          + Integer.toString(res.statusCode()) + "\n"
          + body.toString();
        logger.error(m);
        future.handle(Future.failedFuture(m));
      }
    });
  });
  req.exceptionHandler(d -> future.handle(Future.failedFuture(d.getCause())));
  req.putHeader("Content-Type", "application/json");
  req.end(doc);
}
 
開發者ID:folio-org,項目名稱:okapi,代碼行數:24,代碼來源:DockerModuleHandle.java

示例7: testOkFormDataSimpleNotRequiredWithParam

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
@Test()
public void testOkFormDataSimpleNotRequiredWithParam(TestContext context) {
    Async async = context.async();
    HttpClientRequest req = httpClient.post(TEST_PORT, TEST_HOST, "/formdata/simple/not/required");
    req.handler(response -> {
        response.bodyHandler(body -> {
            context.assertEquals(response.statusCode(), 200);
            context.assertEquals("toto", body.toString());
            async.complete();
        });
    });

    // Construct form
    StringBuffer payload = new StringBuffer().append("formDataNotRequired=").append(esc.escape("toto"));
    req.putHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
    req.end(payload.toString());
}
 
開發者ID:phiz71,項目名稱:vertx-swagger,代碼行數:18,代碼來源:FormParameterExtractorTest.java

示例8: testAdminConfigRendering

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
@Test
public void testAdminConfigRendering() throws InterruptedException, ExecutionException, TimeoutException {

	HttpClient client = createHttpClient();
	CompletableFuture<String> future = new CompletableFuture<>();
	HttpClientRequest request = client.request(GET, "/mesh-ui/mesh-ui-config.js", rh -> {
		rh.bodyHandler(bh -> {
			if (rh.statusCode() == 200) {
				future.complete(bh.toString());
			} else {
				future.completeExceptionally(new Exception("Status code wrong {" + rh.statusCode() + "}"));
			}
		});
	});
	request.end();

	String response = future.get(10, TimeUnit.SECONDS);
	// String expectedUrl = "localhost:" + port;
	// assertTrue("The meshConfig.js file did not contain the expected url {" + expectedUrl + "} Response {" + response + "}",
	// response.contains(expectedUrl));
	// System.out.println(response);
	assertTrue("The response string should not contain any html specific characters but it was {" + response + "} ", response.indexOf("<") != 0);

}
 
開發者ID:gentics,項目名稱:mesh,代碼行數:25,代碼來源:AdminGUIEndpointTest.java

示例9: post

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
public void post(URL url,
                 Object body,
                 String tenantId,
                 String userId,
                 Handler<HttpClientResponse> responseHandler) {

  HttpClientRequest request = client.postAbs(url.toString(), responseHandler);

  request.headers().add("Accept","application/json, text/plain");
  request.headers().add("Content-type","application/json");

  if(tenantId != null) {
    request.headers().add(TENANT_HEADER, tenantId);
  }

  if(userId != null) {
    request.headers().add(USERID_HEADER, userId);
  }

  if(body != null) {
    String encodedBody = Json.encodePrettily(body);

    System.out.println(String.format("POST %s, Request: %s",
      url.toString(), encodedBody));

    log.debug(String.format("POST %s, Request: %s",
      url.toString(), encodedBody));

    request.end(encodedBody);
  }
  else {
    request.end();
  }
}
 
開發者ID:folio-org,項目名稱:mod-circulation-storage,代碼行數:35,代碼來源:HttpClient.java

示例10: put

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
public void put(URL url,
                Object body,
                String tenantId,
                String userId,
                Handler<HttpClientResponse> responseHandler) {

  HttpClientRequest request = client.putAbs(url.toString(), responseHandler);

  request.headers().add("Accept","application/json, text/plain");
  request.headers().add("Content-type","application/json");

  if(tenantId != null) {
    request.headers().add(TENANT_HEADER, tenantId);
  }

  if(userId != null){
    request.headers().add(USERID_HEADER, userId);
  }

  String encodedBody = Json.encodePrettily(body);

  System.out.println(String.format("PUT %s, Request: %s",
    url.toString(), encodedBody));

  log.debug(String.format("PUT %s, Request: %s",
    url.toString(), encodedBody));

  request.end(encodedBody);
}
 
開發者ID:folio-org,項目名稱:mod-circulation-storage,代碼行數:30,代碼來源:HttpClient.java

示例11: endRequest

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
private void endRequest(HttpRpcRequest rpcRequest, HttpClientRequest request) {
  if (rpcRequest.method() == HttpMethod.GET) {
    request.end();
  } else if (rpcRequest.method() == HttpMethod.DELETE) {
    request.end();
  } else if (rpcRequest.method() == HttpMethod.POST) {
    request.setChunked(true)
            .end(rpcRequest.body().encode());
  } else if (rpcRequest.method() == HttpMethod.PUT) {
    request.setChunked(true)
            .end(rpcRequest.body().encode());
  }
}
 
開發者ID:edgar615,項目名稱:direwolves,代碼行數:14,代碼來源:SimpleHttpHandler.java

示例12: get

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
/**
 * Send a get request to master
 * @param uri
 * @param onSucc
 * @param onError
 */
public void get(String uri, Handler<Buffer> onSucc, Handler<Throwable> onError) {
    HttpClientRequest req = hc.request(HttpMethod.GET, port, host, uri,
            resp -> {
                if (resp.statusCode() != 200) {
                    onError.handle(new RuntimeException("Wrong status code " + resp.statusCode()));
                }
                resp.bodyHandler(onSucc);
                resp.exceptionHandler(onError);
            });
    req.exceptionHandler(onError);
    req.end();
}
 
開發者ID:ljie-PI,項目名稱:tentacles,代碼行數:19,代碼來源:RemoteCall.java

示例13: testBasicAuthAllOk

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
@Test(timeout = 2000)
public void testBasicAuthAllOk(TestContext context) {
    Async async = context.async();
    
    HttpClientRequest req = httpClient.get(TEST_PORT, TEST_HOST, "/test", response -> {
    	context.assertEquals(response.statusCode(), 200);
    	async.complete();
    });
    req.putHeader("Authorization", ALL_BASIC_AUTH);
    req.end();
    
}
 
開發者ID:phiz71,項目名稱:vertx-swagger,代碼行數:13,代碼來源:BasicAuthTest.java

示例14: testD

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
@Test(timeout = 2000)
public void testD(TestContext context) {
    Async async = context.async();
    
    HttpClientRequest req = httpClient.get(TEST_PORT, TEST_HOST, "/test", response -> {
    	context.assertEquals(response.statusCode(), 401);
    	async.complete();
    });
    req.putHeader("Authorization", D_BASIC_AUTH);
    req.end();
}
 
開發者ID:phiz71,項目名稱:vertx-swagger,代碼行數:12,代碼來源:ChainingAuthTest.java

示例15: useItWithGet

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
public void useItWithGet(TestContext context) {
  HttpClientRequest req = httpClient.get(port, "localhost", "/testb", response -> {
    context.assertEquals(200, response.statusCode());
    String headers = response.headers().entries().toString();
    response.handler(x -> {
      context.assertEquals("It works", x.toString());
    });
    response.endHandler(x -> {
      useItWithPost(context);
    });
  });
  req.headers().add("X-Okapi-Token", okapiToken);
  req.putHeader("X-Okapi-Tenant", okapiTenant);
  req.end();
}
 
開發者ID:folio-org,項目名稱:okapi,代碼行數:16,代碼來源:OkapiPerformance.java


注:本文中的io.vertx.core.http.HttpClientRequest.end方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。