use of jakarta.websocket.ClientEndpointConfig in project spring-framework by spring-projects.
the class EndpointConnectionManager method openConnection.
@Override
protected void openConnection() {
this.taskExecutor.execute(() -> {
try {
if (logger.isInfoEnabled()) {
logger.info("Connecting to WebSocket at " + getUri());
}
Endpoint endpointToUse = this.endpoint;
if (endpointToUse == null) {
Assert.state(this.endpointProvider != null, "No endpoint set");
endpointToUse = this.endpointProvider.getHandler();
}
ClientEndpointConfig endpointConfig = this.configBuilder.build();
this.session = getWebSocketContainer().connectToServer(endpointToUse, endpointConfig, getUri());
logger.info("Successfully connected to WebSocket");
} catch (Throwable ex) {
logger.error("Failed to connect to WebSocket", ex);
}
});
}
use of jakarta.websocket.ClientEndpointConfig in project spring-framework by spring-projects.
the class StandardWebSocketClient method doHandshakeInternal.
@Override
protected ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler webSocketHandler, HttpHeaders headers, final URI uri, List<String> protocols, List<WebSocketExtension> extensions, Map<String, Object> attributes) {
int port = getPort(uri);
InetSocketAddress localAddress = new InetSocketAddress(getLocalHost(), port);
InetSocketAddress remoteAddress = new InetSocketAddress(uri.getHost(), port);
final StandardWebSocketSession session = new StandardWebSocketSession(headers, attributes, localAddress, remoteAddress);
final ClientEndpointConfig endpointConfig = ClientEndpointConfig.Builder.create().configurator(new StandardWebSocketClientConfigurator(headers)).preferredSubprotocols(protocols).extensions(adaptExtensions(extensions)).build();
endpointConfig.getUserProperties().putAll(getUserProperties());
final Endpoint endpoint = new StandardWebSocketHandlerAdapter(webSocketHandler, session);
Callable<WebSocketSession> connectTask = () -> {
this.webSocketContainer.connectToServer(endpoint, endpointConfig, uri);
return session;
};
if (this.taskExecutor != null) {
return this.taskExecutor.submitListenable(connectTask);
} else {
ListenableFutureTask<WebSocketSession> task = new ListenableFutureTask<>(connectTask);
task.run();
return task;
}
}
Aggregations