本文整理了Java中io.vertx.core.http.HttpClient.websocketAbs()
方法的一些代码示例,展示了HttpClient.websocketAbs()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpClient.websocketAbs()
方法的具体详情如下:
包路径:io.vertx.core.http.HttpClient
类名称:HttpClient
方法名:websocketAbs
[英]Connect a WebSocket with the specified absolute url, with the specified headers, using the specified version of WebSockets, and the specified websocket sub protocols.
[中]使用指定版本的WebSocket和指定的WebSocket子协议,连接具有指定绝对url和指定标题的WebSocket。
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testWebsocketAbs() {
SelfSignedCertificate certificate = SelfSignedCertificate.create();
HttpServerOptions serverOptions = new HttpServerOptions().setPort(HttpTestBase.DEFAULT_HTTPS_PORT)
.setSsl(true)
.setKeyCertOptions(certificate.keyCertOptions());
HttpClientOptions clientOptions = new HttpClientOptions()
.setTrustAll(true)
.setVerifyHost(false);
client = vertx.createHttpClient(clientOptions);
server = vertx.createHttpServer(serverOptions).requestHandler(request -> {
if ("/test".equals(request.path())) {
request.upgrade().close();
} else {
request.response().end();
}
}).listen(onSuccess(server -> {
String url = "wss://" + clientOptions.getDefaultHost() + ":" + HttpTestBase.DEFAULT_HTTPS_PORT + "/test";
client.websocketAbs(url, null, null, null, ws -> {
ws.closeHandler(v -> {
testComplete();
});
}, null);
}));
await();
}
代码示例来源:origin: io.vertx/vertx-core
@Test
public void testWebsocketAbs() {
SelfSignedCertificate certificate = SelfSignedCertificate.create();
HttpServerOptions serverOptions = new HttpServerOptions().setPort(HttpTestBase.DEFAULT_HTTPS_PORT)
.setSsl(true)
.setKeyCertOptions(certificate.keyCertOptions());
HttpClientOptions clientOptions = new HttpClientOptions()
.setTrustAll(true)
.setVerifyHost(false);
client = vertx.createHttpClient(clientOptions);
server = vertx.createHttpServer(serverOptions).requestHandler(request -> {
if ("/test".equals(request.path())) {
request.upgrade().close();
} else {
request.response().end();
}
}).listen(onSuccess(server -> {
String url = "wss://" + clientOptions.getDefaultHost() + ":" + HttpTestBase.DEFAULT_HTTPS_PORT + "/test";
client.websocketAbs(url, null, null, null, ws -> {
ws.closeHandler(v -> {
testComplete();
});
}, null);
}));
await();
}
代码示例来源:origin: io.vertx/vertx-rx-java
/**
* Connect a WebSocket with the specified absolute url, with the specified headers, using
* the specified version of WebSockets, and the specified websocket sub protocols.
* @param url the absolute url
* @param headers the headers
* @param version the websocket version
* @param subProtocols the subprotocols to use
* @param wsConnect handler that will be called with the websocket when connected
* @param failureHandler handler that will be called if websocket connection fails
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpClient websocketAbs(String url, io.vertx.rxjava.core.MultiMap headers, WebsocketVersion version, String subProtocols, Handler<io.vertx.rxjava.core.http.WebSocket> wsConnect, Handler<Throwable> failureHandler) {
delegate.websocketAbs(url, headers.getDelegate(), version, subProtocols, new Handler<io.vertx.core.http.WebSocket>() {
public void handle(io.vertx.core.http.WebSocket event) {
wsConnect.handle(io.vertx.rxjava.core.http.WebSocket.newInstance(event));
}
}, failureHandler);
return this;
}
代码示例来源:origin: vert-x3/vertx-rx
/**
* Connect a WebSocket with the specified absolute url, with the specified headers, using
* the specified version of WebSockets, and the specified websocket sub protocols.
* @param url the absolute url
* @param headers the headers
* @param version the websocket version
* @param subProtocols the subprotocols to use
* @param wsConnect handler that will be called with the websocket when connected
* @param failureHandler handler that will be called if websocket connection fails
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpClient websocketAbs(String url, io.vertx.rxjava.core.MultiMap headers, WebsocketVersion version, String subProtocols, Handler<io.vertx.rxjava.core.http.WebSocket> wsConnect, Handler<Throwable> failureHandler) {
delegate.websocketAbs(url, headers.getDelegate(), version, subProtocols, new Handler<io.vertx.core.http.WebSocket>() {
public void handle(io.vertx.core.http.WebSocket event) {
wsConnect.handle(io.vertx.rxjava.core.http.WebSocket.newInstance(event));
}
}, failureHandler);
return this;
}
代码示例来源:origin: mewna/catnip
@SuppressWarnings("squid:HiddenFieldCheck")
private void connectSocket(final String url) {
client.websocketAbs(url, null, null, null,
socket -> {
this.socket = socket;
socketOpen = true;
catnip.eventBus().publish(Raw.CONNECTED, shardInfo());
socket.frameHandler(this::handleSocketFrame)
.closeHandler(this::handleSocketClose)
.exceptionHandler(t -> catnip.logAdapter().error("Shard {}/{}: Exception in Websocket", id, limit, t));
},
failure -> {
socket = null;
socketOpen = false;
catnip.logAdapter().error("Shard {}/{}: Couldn't connect socket:", id, limit, failure);
catnip.eventBus().publish(Raw.CLOSED, shardInfo());
stateReply(ShardConnectState.FAILED);
});
}
内容来源于网络,如有侵权,请联系作者删除!