use of io.netty.handler.codec.http.HttpHeaderNames.AUTHORIZATION in project cf-java-client by cloudfoundry.
the class ReactorServerInformation method getAuthenticationCode.
@Override
public Mono<GetAutoLoginAuthenticationCodeResponse> getAuthenticationCode(GetAutoLoginAuthenticationCodeRequest request) {
return post(request, GetAutoLoginAuthenticationCodeResponse.class, builder -> builder.pathSegment("autologin"), outbound -> outbound.map(r -> {
String encoded = Base64.getEncoder().encodeToString(new AsciiString(request.getClientId()).concat(":").concat(request.getClientSecret()).toByteArray());
r.requestHeaders().set(AUTHORIZATION, BASIC_PREAMBLE + encoded);
return r;
})).checkpoint();
}
use of io.netty.handler.codec.http.HttpHeaderNames.AUTHORIZATION in project cf-java-client by cloudfoundry.
the class ReactorTokens method check.
@Override
public Mono<CheckTokenResponse> check(CheckTokenRequest request) {
return post(request, CheckTokenResponse.class, builder -> builder.pathSegment("check_token"), outbound -> outbound.map(r -> {
String encoded = Base64.getEncoder().encodeToString(new AsciiString(request.getClientId()).concat(":").concat(request.getClientSecret()).toByteArray());
r.requestHeaders().set(AUTHORIZATION, BASIC_PREAMBLE + encoded);
return r;
})).checkpoint();
}
use of io.netty.handler.codec.http.HttpHeaderNames.AUTHORIZATION in project ksql by confluentinc.
the class RestIntegrationTestUtil method rawRestRequest.
static VertxCompletableFuture<Void> rawRestRequest(final TestKsqlRestApp restApp, final HttpVersion httpVersion, final HttpMethod method, final String uri, final Object requestBody, final String mediaType, final Consumer<Buffer> chunkConsumer, final Optional<BasicCredentials> credentials) {
final byte[] bytes;
try {
bytes = ApiJsonMapper.INSTANCE.get().writeValueAsBytes(requestBody);
} catch (Exception e) {
throw new RuntimeException(e);
}
HttpClientOptions options = new HttpClientOptions().setDefaultPort(restApp.getHttpListener().getPort()).setDefaultHost(restApp.getHttpListener().getHost()).setVerifyHost(false);
if (httpVersion == HttpVersion.HTTP_2) {
options.setProtocolVersion(HttpVersion.HTTP_2);
}
final Vertx vertx = Vertx.vertx();
final HttpClient httpClient = vertx.createHttpClient(options);
final VertxCompletableFuture<Void> vcf = new VertxCompletableFuture<>();
final HttpClientRequest httpClientRequest = httpClient.request(method, uri, resp -> {
resp.handler(buffer -> {
try {
chunkConsumer.accept(buffer);
} catch (final Throwable t) {
vcf.completeExceptionally(t);
}
});
resp.endHandler(v -> {
chunkConsumer.accept(null);
vcf.complete(null);
});
}).exceptionHandler(vcf::completeExceptionally);
httpClientRequest.putHeader("Accept", mediaType);
credentials.ifPresent(basicCredentials -> httpClientRequest.putHeader("Authorization", createBasicAuthHeader(basicCredentials)));
Buffer bodyBuffer = Buffer.buffer(bytes);
httpClientRequest.end(bodyBuffer);
// cleanup
vcf.handle((v, throwable) -> {
httpClient.close();
vertx.close();
return null;
});
return vcf;
}
Aggregations