use of io.vertx.core.http.UpgradeRejectedException in project vert.x by eclipse.
the class WebSocketHandshakeInboundHandler method handshakeComplete.
private Future<HeadersAdaptor> handshakeComplete(FullHttpResponse response) {
int sc = response.status().code();
if (sc != 101) {
String msg = "WebSocket upgrade failure: " + sc;
ByteBuf content = response.content();
if (content != null && content.readableBytes() > 0) {
msg += " (" + content.toString(StandardCharsets.UTF_8) + ")";
}
UpgradeRejectedException failure = new UpgradeRejectedException(msg, sc);
return Future.failedFuture(failure);
} else {
try {
handshaker.finishHandshake(chctx.channel(), response);
return Future.succeededFuture(new HeadersAdaptor(response.headers()));
} catch (WebSocketHandshakeException e) {
return Future.failedFuture(e);
}
}
}
use of io.vertx.core.http.UpgradeRejectedException in project ksql by confluentinc.
the class WebsocketUtils method makeWsRequest.
static void makeWsRequest(String request, Map<String, String> clientProps, MultiMap headers, TestKsqlRestApp restApp, boolean tls) throws SSLHandshakeException, UpgradeRejectedException {
Vertx vertx = Vertx.vertx();
io.vertx.core.http.HttpClient httpClient = null;
try {
HttpClientOptions httpClientOptions = new HttpClientOptions();
if (tls) {
httpClientOptions.setSsl(true).setVerifyHost(false);
final Optional<JksOptions> trustStoreOptions = VertxSslOptionsFactory.getJksTrustStoreOptions(clientProps);
final String alias = clientProps.get(KsqlClient.SSL_KEYSTORE_ALIAS_CONFIG);
final Optional<JksOptions> keyStoreOptions = VertxSslOptionsFactory.buildJksKeyStoreOptions(clientProps, Optional.ofNullable(alias));
trustStoreOptions.ifPresent(options -> httpClientOptions.setTrustStoreOptions(options));
keyStoreOptions.ifPresent(options -> httpClientOptions.setKeyStoreOptions(options));
}
httpClient = vertx.createHttpClient(httpClientOptions);
URI listener = tls ? restApp.getWssListener() : restApp.getWsListener();
final URI uri = listener.resolve("/ws/query?request=" + request);
CompletableFuture<Void> completableFuture = new CompletableFuture<>();
httpClient.webSocketAbs(uri.toString(), headers, WebsocketVersion.V07, Collections.emptyList(), ar -> {
if (ar.succeeded()) {
ar.result().frameHandler(frame -> completableFuture.complete(null));
ar.result().exceptionHandler(completableFuture::completeExceptionally);
} else {
completableFuture.completeExceptionally(ar.cause());
}
});
completableFuture.get(30, TimeUnit.SECONDS);
} catch (Exception e) {
if (e instanceof ExecutionException) {
if (e.getCause() instanceof SSLHandshakeException) {
throw (SSLHandshakeException) e.getCause();
} else if (e.getCause() instanceof UpgradeRejectedException) {
throw (UpgradeRejectedException) e.getCause();
} else {
throw new RuntimeException(e);
}
} else {
throw new RuntimeException(e);
}
} finally {
if (httpClient != null) {
httpClient.close();
}
vertx.close();
}
}
use of io.vertx.core.http.UpgradeRejectedException in project ksql by confluentinc.
the class BasicAuthFunctionalTest method makeWsRequest.
private static int makeWsRequest(final Optional<BasicCredentials> creds) throws Exception {
JsonObject request = new JsonObject().put("ksql", "SELECT * FROM KSQL_PROCESSING_LOG EMIT CHANGES;");
MultiMap headers = MultiMap.caseInsensitiveMultiMap();
creds.ifPresent(c -> {
final String authHeader = "Basic " + buildBasicAuthHeader(c.username(), c.password());
headers.add(AUTHORIZATION.toString(), authHeader);
});
try {
String escaped = UrlEscapers.urlFormParameterEscaper().escape(request.toString());
WebsocketUtils.makeWsRequest(escaped, Collections.emptyMap(), headers, REST_APP, false);
} catch (UpgradeRejectedException e) {
return e.getStatus();
}
return OK.code();
}
Aggregations