Class GraphQlWebSocketHandler
java.lang.Object
org.springframework.web.socket.handler.AbstractWebSocketHandler
org.springframework.web.socket.handler.TextWebSocketHandler
org.springframework.graphql.server.webmvc.GraphQlWebSocketHandler
- All Implemented Interfaces:
SubProtocolCapable
,WebSocketHandler
@RegisterReflectionForBinding(GraphQlWebSocketMessage.class)
public class GraphQlWebSocketHandler
extends TextWebSocketHandler
implements SubProtocolCapable
WebSocketHandler for GraphQL based on
GraphQL Over
WebSocket Protocol and for use on a Servlet container with
spring-websocket
.- Since:
- 1.0.0
- Author:
- Rossen Stoyanchev
-
Constructor Summary
ConstructorDescriptionGraphQlWebSocketHandler
(WebGraphQlHandler graphQlHandler, HttpMessageConverter<?> converter, Duration connectionInitTimeout) Create a new instance.GraphQlWebSocketHandler
(WebGraphQlHandler graphQlHandler, HttpMessageConverter<?> converter, Duration connectionInitTimeout, Duration keepAliveDuration) Create a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
afterConnectionClosed
(WebSocketSession session, CloseStatus closeStatus) void
asWebSocketHttpRequestHandler
(HandshakeHandler handshakeHandler) Deprecated, for removal: This API element is subject to removal in a future version.protected void
handleTextMessage
(WebSocketSession session, TextMessage webSocketMessage) initWebSocketHttpRequestHandler
(HandshakeHandler handshakeHandler) Initialize aWebSocketHttpRequestHandler
that wraps this instance and also inserts aHandshakeInterceptor
for context propagation.Methods inherited from class org.springframework.web.socket.handler.TextWebSocketHandler
handleBinaryMessage
Methods inherited from class org.springframework.web.socket.handler.AbstractWebSocketHandler
handleMessage, handlePongMessage, handleTransportError, supportsPartialMessages
-
Constructor Details
-
GraphQlWebSocketHandler
public GraphQlWebSocketHandler(WebGraphQlHandler graphQlHandler, HttpMessageConverter<?> converter, Duration connectionInitTimeout) Create a new instance.- Parameters:
graphQlHandler
- common handler for GraphQL over WebSocket requestsconverter
- for JSON encoding and decodingconnectionInitTimeout
- how long to wait after the establishment of the WebSocket for the"connection_ini"
message from the client.
-
GraphQlWebSocketHandler
public GraphQlWebSocketHandler(WebGraphQlHandler graphQlHandler, HttpMessageConverter<?> converter, Duration connectionInitTimeout, @Nullable Duration keepAliveDuration) Create a new instance.- Parameters:
graphQlHandler
- common handler for GraphQL over WebSocket requestsconverter
- for JSON encoding and decodingconnectionInitTimeout
- how long to wait after the establishment of the WebSocket for the"connection_ini"
message from the client.keepAliveDuration
- how frequently to send ping messages; if not set then ping messages are not sent.- Since:
- 1.3
-
-
Method Details
-
getSubProtocols
- Specified by:
getSubProtocols
in interfaceSubProtocolCapable
-
initWebSocketHttpRequestHandler
public WebSocketHttpRequestHandler initWebSocketHttpRequestHandler(HandshakeHandler handshakeHandler) Initialize aWebSocketHttpRequestHandler
that wraps this instance and also inserts aHandshakeInterceptor
for context propagation.- Parameters:
handshakeHandler
- the handler for WebSocket handshake- Since:
- 1.1.0
-
asWebSocketHttpRequestHandler
@Deprecated(since="1.1.0", forRemoval=true) public WebSocketHttpRequestHandler asWebSocketHttpRequestHandler(HandshakeHandler handshakeHandler) Deprecated, for removal: This API element is subject to removal in a future version.as of 1.1.0 in favor ofinitWebSocketHttpRequestHandler(HandshakeHandler)
Return aWebSocketHttpRequestHandler
that uses this instance as itsWebGraphQlHandler
and adds aHandshakeInterceptor
to propagate context.- Parameters:
handshakeHandler
- the handler for WebSocket handshake
-
afterConnectionEstablished
- Specified by:
afterConnectionEstablished
in interfaceWebSocketHandler
- Overrides:
afterConnectionEstablished
in classAbstractWebSocketHandler
-
handleTextMessage
protected void handleTextMessage(WebSocketSession session, TextMessage webSocketMessage) throws Exception - Overrides:
handleTextMessage
in classAbstractWebSocketHandler
- Throws:
Exception
-
afterConnectionClosed
- Specified by:
afterConnectionClosed
in interfaceWebSocketHandler
- Overrides:
afterConnectionClosed
in classAbstractWebSocketHandler
-
initWebSocketHttpRequestHandler(HandshakeHandler)