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


Java HttpClient類代碼示例

本文整理匯總了Java中ratpack.http.client.HttpClient的典型用法代碼示例。如果您正苦於以下問題:Java HttpClient類的具體用法?Java HttpClient怎麽用?Java HttpClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: handle

import ratpack.http.client.HttpClient; //導入依賴的package包/類
@Override
public void handle(final Context ctx) throws Exception {
    final Request request = ctx.getRequest();
    final HttpClient httpClient = ctx.get(HttpClient.class);
    final URI proxiedUri = URI.create(authUri);
    LOG.info("Forward to: {}", proxiedUri);

    ctx.parse(Form.class).then(form -> {
        httpClient.requestStream(proxiedUri, requestSpec -> {
            final String s = form.entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).collect(Collectors.joining("&"));
            requestSpec.getBody().bytes(s.getBytes(Charsets.UTF_8));
            requestSpec.getHeaders().copy(request.getHeaders());
            requestSpec.method(request.getMethod());

            if (form.containsKey("client_id") && form.containsKey("client_secret")) {
                final String auth = Base64.getEncoder().encodeToString((form.get("client_id") + ":" + form.get("client_secret")).getBytes(Charsets.UTF_8));
                requestSpec.getHeaders().add("Authorization", "Basic " + auth);
            }
        }).then(receivedResponse ->
                receivedResponse.forwardTo(ctx.getResponse(), mutableHeaders -> {
                    mutableHeaders.add("Via", "Vrap OAuth 2.0 proxy");
                }));
    });
}
 
開發者ID:vrapio,項目名稱:vrap,代碼行數:25,代碼來源:AuthRouter.java

示例2: configure

import ratpack.http.client.HttpClient; //導入依賴的package包/類
@Override
protected void configure() {
  bind(ServerTracingHandler.class)
      .to(DefaultServerTracingHandler.class)
      .in(Singleton.class);

  bind(HttpClient.class).annotatedWith(Zipkin.class)
      .to(ZipkinHttpClientImpl.class)
      .in(Singleton.class);

  bind(ZipkinHttpClientImpl.class);

  Provider<ServerTracingHandler> serverTracingHandlerProvider =
      getProvider(ServerTracingHandler.class);

  Multibinder.newSetBinder(binder(), HandlerDecorator.class).addBinding()
      .toProvider(() -> HandlerDecorator.prepend(serverTracingHandlerProvider.get()))
      .in(Singleton.class);
}
 
開發者ID:hyleung,項目名稱:ratpack-zipkin,代碼行數:20,代碼來源:ServerTracingModule.java

示例3: handle

import ratpack.http.client.HttpClient; //導入依賴的package包/類
@Override
public void handle(final Context ctx) throws Exception {
    final Request request = ctx.getRequest();
    final TypedData body = ctx.get(TypedData.class);
    final HttpClient httpClient = ctx.get(HttpClient.class);
    final URI proxiedUri = proxiedUri(ctx);
    LOG.info("Forward to: {}", proxiedUri);

    httpClient.request(proxiedUri, proxyRequest(body, request))
            .then(receivedResponse ->
                    ctx.next(Registry.builder().add(receivedResponse).add(proxiedUri).build()));
}
 
開發者ID:vrapio,項目名稱:vrap,代碼行數:13,代碼來源:RamlRouter.java

示例4: newClient

import ratpack.http.client.HttpClient; //導入依賴的package包/類
@Override protected HttpClient newClient(int port) {
    return Exceptions.uncheck(() -> new ZipkinHttpClientImpl( HttpClient.of(s -> s
        .poolSize(0)
        .byteBufAllocator(UnpooledByteBufAllocator.DEFAULT)
        .maxContentLength(ServerConfig.DEFAULT_MAX_CONTENT_LENGTH)
    ), httpTracing));
}
 
開發者ID:hyleung,項目名稱:ratpack-zipkin,代碼行數:8,代碼來源:ITTracingFeature_Client.java

示例5: post

import ratpack.http.client.HttpClient; //導入依賴的package包/類
@Override protected void post(HttpClient client, String pathIncludingQuery, String body)
    throws Exception {
    harness.yield(e ->
        client.post(URI.create(url(pathIncludingQuery)), (request ->
            request.body(b -> b.text(body))
        ))
    ).getValueOrThrow();
}
 
開發者ID:hyleung,項目名稱:ratpack-zipkin,代碼行數:9,代碼來源:ITTracingFeature_Client.java

示例6: ZipkinHttpClientImpl

import ratpack.http.client.HttpClient; //導入依賴的package包/類
@Inject
public ZipkinHttpClientImpl(final HttpClient delegate, final HttpTracing httpTracing) {
    this.delegate = delegate;
    this.handler = HttpClientHandler.create(httpTracing, new HttpAdapter());
    this.injector = httpTracing.tracing().propagation().injector(MutableHeaders::set);
}
 
開發者ID:hyleung,項目名稱:ratpack-zipkin,代碼行數:7,代碼來源:ZipkinHttpClientImpl.java

示例7: closeClient

import ratpack.http.client.HttpClient; //導入依賴的package包/類
@Override protected void closeClient(HttpClient client) throws IOException {
    client.close();
}
 
開發者ID:hyleung,項目名稱:ratpack-zipkin,代碼行數:4,代碼來源:ITTracingFeature_Client.java

示例8: get

import ratpack.http.client.HttpClient; //導入依賴的package包/類
@Override protected void get(HttpClient client, String pathIncludingQuery) throws Exception {
    harness.yield(e -> client.get(URI.create(url(pathIncludingQuery)))).getValueOrThrow();
}
 
開發者ID:hyleung,項目名稱:ratpack-zipkin,代碼行數:4,代碼來源:ITTracingFeature_Client.java

示例9: getAsync

import ratpack.http.client.HttpClient; //導入依賴的package包/類
@Override protected void getAsync(HttpClient client, String pathIncludingQuery)
    throws Exception {
    harness.yield(e -> client.get(URI.create(url(pathIncludingQuery)))).getValueOrThrow();
}
 
開發者ID:hyleung,項目名稱:ratpack-zipkin,代碼行數:5,代碼來源:ITTracingFeature_Client.java


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