本文整理汇总了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");
}));
});
}
示例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);
}
示例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()));
}
示例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));
}
示例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();
}
示例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);
}
示例7: closeClient
import ratpack.http.client.HttpClient; //导入依赖的package包/类
@Override protected void closeClient(HttpClient client) throws IOException {
client.close();
}
示例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();
}
示例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();
}