Top Description Fields Constructors Methods
org.springframework.web.socket.handler

public Class PerConnectionWebSocketHandler

extends Object
implements WebSocketHandler, BeanFactoryAware
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.Aware, org.springframework.web.socket.WebSocketHandler
Imports
java.util.Map, java.util.concurrent.ConcurrentHashMap, org.apache.commons.logging.Log, .LogFactory, org.springframework.beans.factory.BeanFactory, .BeanFactoryAware, org.springframework.web.socket.CloseStatus, .WebSocketHandler, .WebSocketMessage, .WebSocketSession

A WebSocketHandler that initializes and destroys a WebSocketHandler instance for each WebSocket connection and delegates all other methods to it.

Essentially create an instance of this class once, providing the type of WebSocketHandler class to create for each connection, and then pass it to any API method that expects a WebSocketHandler.

If initializing the target WebSocketHandler type requires a Spring BeanFactory, then the setBeanFactory(BeanFactory) property accordingly. Simply declaring this class as a Spring bean will do that. Otherwise, WebSocketHandler instances of the target type will be created using the default constructor.

Author
Rossen Stoyanchev
Since
4.0

Field Summary

Modifier and TypeField and Description
private final Map<WebSocketSession, WebSocketHandler>
private static final Log
private final BeanCreatingHandlerProvider<WebSocketHandler>
private final boolean

Constructor Summary

AccessConstructor and Description
public
public
PerConnectionWebSocketHandler(Class<? extends WebSocketHandler> handlerType, boolean supportsPartialMessages)

Method Summary

Modifier and TypeMethod and Description
public void
afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus)

Implements org.springframework.web.socket.WebSocketHandler.afterConnectionClosed.

Invoked after the WebSocket connection has been closed by either side, or after a transport error has occurred.

public void
afterConnectionEstablished(WebSocketSession session)

Implements org.springframework.web.socket.WebSocketHandler.afterConnectionEstablished.

Invoked after WebSocket negotiation has succeeded and the WebSocket connection is opened and ready for use.

private void
private WebSocketHandler
public void
handleMessage(WebSocketSession session, WebSocketMessage<?> message)

Implements org.springframework.web.socket.WebSocketHandler.handleMessage.

Invoked when a new WebSocket message arrives.

public void
handleTransportError(WebSocketSession session, Throwable exception)

Implements org.springframework.web.socket.WebSocketHandler.handleTransportError.

Handle an error from the underlying WebSocket message transport.

public void
setBeanFactory(BeanFactory
owning BeanFactory (never null). The bean can immediately call methods on the factory.
beanFactory
)

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Callback that supplies the owning factory to a bean instance.

public boolean
supportsPartialMessages()

Implements org.springframework.web.socket.WebSocketHandler.supportsPartialMessages.

Whether the WebSocketHandler handles partial messages.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

handlersback to summary
private final Map<WebSocketSession, WebSocketHandler> handlers
loggerback to summary
private static final Log logger
providerback to summary
private final BeanCreatingHandlerProvider<WebSocketHandler> provider
supportsPartialMessagesback to summary
private final boolean supportsPartialMessages

Constructor Detail

PerConnectionWebSocketHandlerback to summary
public PerConnectionWebSocketHandler(Class<? extends WebSocketHandler> handlerType)
PerConnectionWebSocketHandlerback to summary
public PerConnectionWebSocketHandler(Class<? extends WebSocketHandler> handlerType, boolean supportsPartialMessages)

Method Detail

afterConnectionClosedback to summary
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception

Implements org.springframework.web.socket.WebSocketHandler.afterConnectionClosed.

Doc from org.springframework.web.socket.WebSocketHandler.afterConnectionClosed.

Invoked after the WebSocket connection has been closed by either side, or after a transport error has occurred. Although the session may technically still be open, depending on the underlying implementation, sending messages at this point is discouraged and most likely will not succeed.

Annotations
@Override
Exceptions
Exception:
this method can handle or propagate exceptions; see class-level Javadoc for details.
afterConnectionEstablishedback to summary
public void afterConnectionEstablished(WebSocketSession session) throws Exception

Implements org.springframework.web.socket.WebSocketHandler.afterConnectionEstablished.

Doc from org.springframework.web.socket.WebSocketHandler.afterConnectionEstablished.

Invoked after WebSocket negotiation has succeeded and the WebSocket connection is opened and ready for use.

Annotations
@Override
Exceptions
Exception:
this method can handle or propagate exceptions; see class-level Javadoc for details.
destroyHandlerback to summary
private void destroyHandler(WebSocketSession session)
getHandlerback to summary
private WebSocketHandler getHandler(WebSocketSession session)
handleMessageback to summary
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception

Implements org.springframework.web.socket.WebSocketHandler.handleMessage.

Doc from org.springframework.web.socket.WebSocketHandler.handleMessage.

Invoked when a new WebSocket message arrives.

Annotations
@Override
Exceptions
Exception:
this method can handle or propagate exceptions; see class-level Javadoc for details.
handleTransportErrorback to summary
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception

Implements org.springframework.web.socket.WebSocketHandler.handleTransportError.

Doc from org.springframework.web.socket.WebSocketHandler.handleTransportError.

Handle an error from the underlying WebSocket message transport.

Annotations
@Override
Exceptions
Exception:
this method can handle or propagate exceptions; see class-level Javadoc for details.
setBeanFactoryback to summary
public void setBeanFactory(BeanFactory beanFactory)

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Doc from org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Callback that supplies the owning factory to a bean instance.

Invoked after the population of normal bean properties but before an initialization callback such as InitializingBean#afterPropertiesSet() or a custom init-method.

Parameters
beanFactory:BeanFactory

owning BeanFactory (never null). The bean can immediately call methods on the factory.

Annotations
@Override
supportsPartialMessagesback to summary
public boolean supportsPartialMessages()

Implements org.springframework.web.socket.WebSocketHandler.supportsPartialMessages.

Doc from org.springframework.web.socket.WebSocketHandler.supportsPartialMessages.

Whether the WebSocketHandler handles partial messages. If this flag is set to true and the underlying WebSocket server supports partial messages, then a large WebSocket message, or one of an unknown size may be split and maybe received over multiple calls to handleMessage(WebSocketSession, WebSocketMessage). The flag org.springframework.web.socket.WebSocketMessage#isLast() indicates if the message is partial and whether it is the last part.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override