当前位置: 首页>>代码示例>>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;未经允许,请勿转载。