Add Javadoc

This commit is contained in:
Rossen Stoyanchev 2013-05-14 16:41:03 -04:00
parent 59ef34d769
commit 6825aaf41f
72 changed files with 259 additions and 146 deletions

View File

@ -25,7 +25,6 @@ import java.nio.ByteBuffer;
*
* @author Rossen Stoyanchev
* @since 4.0
* @see WebSocketMessage
*/
public final class BinaryMessage extends WebSocketMessage<ByteBuffer> {

View File

@ -19,13 +19,14 @@ package org.springframework.web.socket;
/**
* A handler for WebSocket messages and lifecycle events.
*
* <p> Implementations of this interface are encouraged to handle exceptions locally where
* it makes sense or alternatively let the exception bubble up in which case the exception
* is logged and the session closed with {@link CloseStatus#SERVER_ERROR SERVER_ERROR(1011)} by default.
* The exception handling strategy is provided by
* {@link org.springframework.web.socket.support.ExceptionWebSocketHandlerDecorator ExceptionWebSocketHandlerDecorator},
* which can be customized or replaced by decorating the {@link WebSocketHandler} with a
* different decorator.
* <p>
* Implementations of this interface are encouraged to handle exceptions locally where it
* makes sense or alternatively let the exception bubble up in which case the exception is
* logged and the session closed with {@link CloseStatus#SERVER_ERROR SERVER_ERROR(1011)}
* by default. The exception handling strategy is provided by
* {@link org.springframework.web.socket.support.ExceptionWebSocketHandlerDecorator
* ExceptionWebSocketHandlerDecorator}, which can be customized or replaced by decorating
* the {@link WebSocketHandler} with a different decorator.
*
* @param <T> The type of message being handled {@link TextMessage}, {@link BinaryMessage}
* (or {@link WebSocketMessage} for both).

View File

@ -20,9 +20,7 @@ import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
/**
* A message that can be handled or sent during a WebSocket interaction. There are only
* two sub-classes {@link BinaryMessage} or a {@link TextMessage} with no further
* sub-classing expected.
* A message that can be handled or sent on a WebSocket connection.
*
* @author Rossen Stoyanchev
* @since 4.0
@ -43,7 +41,6 @@ public abstract class WebSocketMessage<T> {
this.payload = payload;
}
/**
* Returns the message payload. This will never be {@code null}.
*/

View File

@ -17,12 +17,12 @@
package org.springframework.web.socket;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.URI;
import java.security.Principal;
/**
* Allows sending messages over a WebSocket connection as well as closing it.
* A WebSocket session abstraction. Allows sending messages over a WebSocket connection
* and closing it.
*
* @author Rossen Stoyanchev
* @since 4.0

View File

@ -28,7 +28,7 @@ import org.springframework.web.socket.WebSocketSession;
/**
* An base class for implementations adapting {@link WebSocketSession}.
* An abstract base class for implementations of {@link WebSocketSession}.
*
* @author Rossen Stoyanchev
* @since 4.0

View File

@ -25,7 +25,9 @@ import org.springframework.web.socket.WebSocketSession;
/**
* A {@link WebSocketHandler} for binary messages with empty methods.
* A convenient base class for {@link WebSocketHandler} implementation that process binary
* messages only. Text messages are rejected with {@link CloseStatus#NOT_ACCEPTABLE}. All
* other methods have empty implementations.
*
* @author Rossen Stoyanchev
* @author Phillip Webb

View File

@ -23,6 +23,8 @@ import org.springframework.web.socket.WebSocketSession;
/**
* A WebSocketSession with configurable properties.
*
* @author Rossen Stoyanchev
* @since 4.0
*/

View File

@ -28,7 +28,7 @@ import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.support.ExceptionWebSocketHandlerDecorator;
/**
* Adapts Spring's {@link WebSocketHandler} to Jetty's {@link WebSocketListener}.
* Adapts {@link WebSocketHandler} to the Jetty 9 {@link WebSocketListener}.
*
* @author Phillip Webb
* @since 4.0

View File

@ -31,7 +31,8 @@ import org.springframework.web.socket.WebSocketSession;
/**
* Adapts Jetty's {@link Session} to Spring's {@link WebSocketSession}.
* Adapts a Jetty {@link org.eclipse.jetty.websocket.api.Session} to
* {@link WebSocketSession}.
*
* @author Phillip Webb
* @author Rossen Stoyanchev

View File

@ -34,7 +34,7 @@ import org.springframework.web.socket.support.ExceptionWebSocketHandlerDecorator
/**
* A wrapper around a {@link WebSocketHandler} that adapts it to {@link Endpoint}.
* Adapts a {@link WebSocketHandler} to a standard {@link Endpoint}.
*
* @author Rossen Stoyanchev
* @since 4.0

View File

@ -30,8 +30,7 @@ import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
/**
* A standard Java implementation of {@link WebSocketSession} that delegates to
* {@link javax.websocket.Session}.
* Adapts a standard {@link javax.websocket.Session} to {@link WebSocketSession}.
*
* @author Rossen Stoyanchev
* @since 4.0

View File

@ -25,7 +25,9 @@ import org.springframework.web.socket.WebSocketSession;
/**
* A {@link WebSocketHandler} for text messages with empty methods.
* A convenient base class for {@link WebSocketHandler} implementation that process text
* messages only. Binary messages are rejected with {@link CloseStatus#NOT_ACCEPTABLE}. All
* other methods have empty implementations.
*
* @author Rossen Stoyanchev
* @author Phillip Webb

View File

@ -25,14 +25,11 @@ import org.springframework.web.socket.WebSocketSession;
/**
* A {@link WebSocketHandler} for both text and binary messages with empty methods.
* A convenient base class for {@link WebSocketHandler} implementation with empty methods.
*
* @author Rossen Stoyanchev
* @author Phillip Webb
* @since 4.0
*
* @see TextWebSocketHandlerAdapter
* @see BinaryWebSocketHandlerAdapter
*/
public class WebSocketHandlerAdapter implements WebSocketHandler {

View File

@ -15,7 +15,7 @@
*/
/**
* Classes adapting Spring's WebSocket API classes to and from various WebSocket
* Classes adapting Spring's WebSocket API classes to and from WebSocket
* implementations. Also contains convenient base classes for
* {@link org.springframework.web.socket.WebSocketHandler} implementations.
*/

View File

@ -26,7 +26,11 @@ import org.springframework.core.task.TaskExecutor;
import org.springframework.web.util.UriComponentsBuilder;
/**
* Abstract base class for WebSocket connection managers.
* A base class for WebSocket connection managers. Provides a declarative style of
* connecting to a WebSocket server given a URI to connect to. The connection occurs when
* the Spring ApplicationContext is refreshed, if the {@link #autoStartup} property is set
* to {@code true}, or if set to {@code false}, the {@link #start()} and #stop methods can
* be invoked manually.
*
* @author Rossen Stoyanchev
* @since 4.0

View File

@ -22,14 +22,13 @@ import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.WebSocketSession;
/**
* Contract for programmatically starting a WebSocket handshake request. For most cases it
* would be more convenient to use the declarative style
* {@link WebSocketConnectionManager} that starts a WebSocket connection to a
* pre-configured URI when the application starts.
*
* Contract for initiating a WebSocket request. As an alternative considering using the
* declarative style {@link WebSocketConnectionManager} that starts a WebSocket connection
* to a pre-configured URI when the application starts.
*
* @author Rossen Stoyanchev
* @since 4.0
*
*
* @see WebSocketConnectionManager
*/
public interface WebSocketClient {

View File

@ -19,6 +19,8 @@ package org.springframework.web.socket.client;
import org.springframework.core.NestedRuntimeException;
/**
* Thrown when a WebSocket connection to a server could not be established.
*
* @author Rossen Stoyanchev
* @since 4.0
*/

View File

@ -28,6 +28,11 @@ import org.springframework.web.socket.support.ExceptionWebSocketHandlerDecorator
import org.springframework.web.socket.support.LoggingWebSocketHandlerDecorator;
/**
* A WebSocket connection manager that is given a URI, a {@link WebSocketClient}, and a
* {@link WebSocketHandler}, connects to a WebSocket server through {@link #start()} and
* {@link #stop()} methods. If {@link #setAutoStartup(boolean)} is set to {@code true}
* this will be done automatically when the Spring ApplicationContext is refreshed.
*
* @author Rossen Stoyanchev
* @since 4.0
*/

View File

@ -19,6 +19,7 @@ package org.springframework.web.socket.client.endpoint;
import javax.websocket.ContainerProvider;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;
import javax.websocket.server.ServerEndpoint;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
@ -27,6 +28,11 @@ import org.springframework.web.socket.client.ConnectionManagerSupport;
import org.springframework.web.socket.support.BeanCreatingHandlerProvider;
/**
* A WebSocket connection manager that is given a URI, a {@link ServerEndpoint}-annotated
* endpoint, connects to a WebSocket server through the {@link #start()} and
* {@link #stop()} methods. If {@link #setAutoStartup(boolean)} is set to {@code true}
* this will be done automatically when the Spring ApplicationContext is refreshed.
*
* @author Rossen Stoyanchev
* @since 4.0
*/

View File

@ -37,8 +37,14 @@ import org.springframework.web.socket.client.ConnectionManagerSupport;
import org.springframework.web.socket.support.BeanCreatingHandlerProvider;
/**
* A WebSocket connection manager that is given a URI, an {@link Endpoint}, connects to a
* WebSocket server through the {@link #start()} and {@link #stop()} methods. If
* {@link #setAutoStartup(boolean)} is set to {@code true} this will be done automatically
* when the Spring ApplicationContext is refreshed.
*
* @author Rossen Stoyanchev
* @since 4.0
* @see AnnotatedEndpointConnectionManager
*/
public class EndpointConnectionManager extends ConnectionManagerSupport implements BeanFactoryAware {

View File

@ -43,7 +43,8 @@ import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
/**
* A standard Java {@link WebSocketClient}.
* Initiates WebSocket requests to a WebSocket server programatically through the standard
* Java WebSocket API .
*
* @author Rossen Stoyanchev
* @since 4.0

View File

@ -15,10 +15,7 @@
*/
/**
* Client-side classes for use with standard Java WebSocket endpoints including
* {@link org.springframework.web.socket.client.endpoint.EndpointConnectionManager} and
* {@link org.springframework.web.socket.client.endpoint.AnnotatedEndpointConnectionManager}
* for connecting to server endpoints using type-based or annotated endpoints respectively.
* Client-side classes for use with standard Java WebSocket endpoints.
*/
package org.springframework.web.socket.client.endpoint;

View File

@ -15,7 +15,7 @@
*/
/**
* Server-side abstractions for WebSocket applications.
* Client-side abstractions for WebSocket applications.
*/
package org.springframework.web.socket.client;

View File

@ -40,7 +40,7 @@ import org.springframework.util.StringUtils;
import org.springframework.web.socket.WebSocketHandler;
/**
* TODO
* A default implemnetation of {@link HandshakeHandler}.
* <p>
* A container-specific {@link RequestUpgradeStrategy} is required since standard Java
* WebSocket currently does not provide a way to initiate a WebSocket handshake.

View File

@ -23,7 +23,6 @@ import org.springframework.core.NestedRuntimeException;
* Thrown when handshake processing failed to complete due to an internal, unrecoverable
* error. This implies a server error (HTTP status code 500) as opposed to a failure in
* the handshake negotiation.
*
* <p>
* By contrast, when handshake negotiation fails, the response status code will be 200 and
* the response headers and body will have been updated to reflect the cause for the

View File

@ -21,22 +21,31 @@ import java.io.IOException;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.support.PerConnectionWebSocketHandler;
/**
* Contract for processing a WebSocket handshake request.
*
* @author Rossen Stoyanchev
* @since 4.0
*
* @see org.springframework.web.socket.server.support.WebSocketHttpRequestHandler
*/
public interface HandshakeHandler {
/**
* Initiate the handshake.
*
* @param request
* @param response
* @param webSocketHandler
* @return
* @param request the current request
* @param response the current response
* @param webSocketHandler the handler to process WebSocket messages; see
* {@link PerConnectionWebSocketHandler} for providing a handler with
* per-connection lifecycle.
*
* @return whether the handshake negotiation was successful or not. In either case the
* response status, headers, and body will have been updated to reflect the
* result of the negotiation
*
* @throws IOException thrown when accessing or setting the response
*

View File

@ -39,14 +39,22 @@ import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
/**
* BeanPostProcessor that detects beans of type
* {@link javax.websocket.server.ServerEndpointConfig} and registers the provided
* {@link javax.websocket.Endpoint} with a standard Java WebSocket runtime.
*
* <p>If the runtime is a Servlet container, use {@link ServletEndpointExporter}.
* Detects beans of type {@link javax.websocket.server.ServerEndpointConfig} and registers
* with the standard Java WebSocket runtime. Also detects beans annotated with
* {@link ServerEndpoint} and registers them as well. Although not required, it is likely
* annotated endpoints should have their {@code configurator} property set to
* {@link SpringConfigurator}.
* <p>
* When this class is used, by declaring it in Spring configuration, it should be possible
* to turn off a Servlet container's scan for WebSocket endpoints. This can be done with
* the help of the {@code <absolute-ordering>} element in web.xml.
*
* @author Rossen Stoyanchev
* @since 4.0
*
* @see ServerEndpointRegistration
* @see SpringConfigurator
* @see ServletServerContainerFactoryBean
*/
public class ServerEndpointExporter implements InitializingBean, BeanPostProcessor, ApplicationContextAware {
@ -66,9 +74,12 @@ public class ServerEndpointExporter implements InitializingBean, BeanPostProcess
/**
* TODO
* @param annotatedEndpointClasses
*/
* Explicitly list annotated endpoint types that should be registered on startup. This
* can be done if you wish to turn off a Servlet container's scan for endpoints, which
* goes through all 3rd party jars in the, and rely on Spring configuration instead.
*
* @param annotatedEndpointClasses {@link ServerEndpoint}-annotated types
*/
public void setAnnotatedEndpointClasses(Class<?>... annotatedEndpointClasses) {
this.annotatedEndpointClasses.clear();
this.annotatedEndpointClasses.addAll(Arrays.asList(annotatedEndpointClasses));

View File

@ -38,12 +38,16 @@ import org.springframework.web.socket.support.BeanCreatingHandlerProvider;
/**
* An implementation of {@link javax.websocket.server.ServerEndpointConfig} that also
* holds the target {@link javax.websocket.Endpoint} provided as a reference or as a bean
* name. Beans of this type are detected by {@link ServerEndpointExporter} and registered
* with a Java WebSocket runtime at startup.
* contains the target {@link javax.websocket.Endpoint}, provided either as a reference or
* as a bean name.
* <p>
* {@link ServerEndpointRegistration} beans are detected by {@link ServerEndpointExporter}
* and registered with a Java WebSocket runtime at startup.
*
* @author Rossen Stoyanchev
* @since 4.0
*
* @see ServerEndpointExporter
*/
public class ServerEndpointRegistration implements ServerEndpointConfig, BeanFactoryAware {

View File

@ -28,13 +28,15 @@ import org.springframework.web.socket.server.DefaultHandshakeHandler;
import org.springframework.web.socket.sockjs.SockJsService;
/**
* A FactoryBean for {@link javax.websocket.server.ServerContainer}. Since
* A FactoryBean for configuring {@link javax.websocket.server.ServerContainer}. Since
* there is only one {@code ServerContainer} instance accessible under a well-known
* {@code javax.servlet.ServletContext} attribute, simply declaring this FactoryBean and
* using its setters allows configuring the {@code ServerContainer} through Spring
* configuration. This is useful even if the ServerContainer is not injected into any
* other bean. For example, an application can configure a {@link DefaultHandshakeHandler}
* , a {@link SockJsService}, or {@link ServerEndpointExporter}, and separately declare this
* configuration.
* <p>
* This is useful even if the {@code ServerContainer} is not injected into any other bean.
* For example, an application can configure a {@link DefaultHandshakeHandler}, a
* {@link SockJsService}, or {@link ServerEndpointExporter}, and separately declare this
* FactoryBean in order to customize the properties of the (one and only)
* {@code ServerContainer} instance.
*

View File

@ -27,12 +27,20 @@ import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;
/**
* This should be used in conjunction with {@link ServerEndpoint @ServerEndpoint} classes.
*
* <p>For {@link javax.websocket.Endpoint}, see {@link ServerEndpointExporter}.
* A {@link javax.websocket.server.ServerEndpointConfig.Configurator} for initializing
* {@link ServerEndpoint}-annotated classes through Spring.
* <p>
* <pre class="code">
* &#064;ServerEndpoint(value = "/echo", configurator = SpringConfigurator.class)
* public class EchoEndpoint {
* // ...
* }
* </pre>
*
* @author Rossen Stoyanchev
* @since 4.0
*
* @see ServerEndpointExporter
*/
public class SpringConfigurator extends Configurator {

View File

@ -1,6 +0,0 @@
package org.springframework.web.socket.server.endpoint;
public class Test {
}

View File

@ -15,12 +15,8 @@
*/
/**
* Server classes for use with standard Java WebSocket endpoints including
* {@link org.springframework.web.socket.server.endpoint.ServerEndpointRegistration} and
* {@link org.springframework.web.socket.server.endpoint.ServerEndpointExporter} for
* registering type-based endpoints,
* {@link org.springframework.web.socket.server.endpoint.SpringConfigurator} for
* instantiating annotated endpoints through Spring.
* Server classes for use with standard Java WebSocket endpoints providing configuration
* and initialization support.
*/
package org.springframework.web.socket.server.endpoint;

View File

@ -15,7 +15,7 @@
*/
/**
* Server-side abstractions for WebSocket applications.
* Server-side abstractions for WebSocket interactions.
*/
package org.springframework.web.socket.server;

View File

@ -31,13 +31,12 @@ import org.springframework.web.socket.server.HandshakeFailureException;
import org.springframework.web.socket.server.RequestUpgradeStrategy;
/**
* A {@link RequestUpgradeStrategy} that supports WebSocket handlers of type
* {@link WebSocketHandler} as well as {@link javax.websocket.Endpoint}.
* A {@link RequestUpgradeStrategy} for containers that support standard Java WebSocket.
*
* @author Rossen Stoyanchev
* @since 4.0
*/
public abstract class AbstractEndpointUpgradeStrategy implements RequestUpgradeStrategy {
public abstract class AbstractStandardUpgradeStrategy implements RequestUpgradeStrategy {
protected final Log logger = LogFactory.getLog(getClass());

View File

@ -59,7 +59,7 @@ import org.springframework.web.socket.server.endpoint.ServerEndpointRegistration
* @author Rossen Stoyanchev
* @since 4.0
*/
public class GlassFishRequestUpgradeStrategy extends AbstractEndpointUpgradeStrategy {
public class GlassFishRequestUpgradeStrategy extends AbstractStandardUpgradeStrategy {
private final static Random random = new Random();

View File

@ -39,7 +39,7 @@ import org.springframework.web.socket.server.HandshakeFailureException;
import org.springframework.web.socket.server.RequestUpgradeStrategy;
/**
* {@link RequestUpgradeStrategy} for use with Jetty. Based on Jetty's internal
* {@link RequestUpgradeStrategy} for use with Jetty 9. Based on Jetty's internal
* {@code org.eclipse.jetty.websocket.server.WebSocketHandler} class.
*
* @author Phillip Webb

View File

@ -18,10 +18,14 @@ package org.springframework.web.socket.server.support;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.adapter.ConfigurableWebSocketSession;
/**
* Copies information from the handshake HTTP request and response to a given
* {@link WebSocketSession}.
*
* @author Rossen Stoyanchev
* @since 4.0
*/

View File

@ -42,7 +42,7 @@ import org.springframework.web.socket.server.endpoint.ServerEndpointRegistration
* @author Rossen Stoyanchev
* @since 4.0
*/
public class TomcatRequestUpgradeStrategy extends AbstractEndpointUpgradeStrategy {
public class TomcatRequestUpgradeStrategy extends AbstractStandardUpgradeStrategy {
@Override
public String[] getSupportedVersions() {

View File

@ -35,7 +35,16 @@ import org.springframework.web.socket.support.ExceptionWebSocketHandlerDecorator
import org.springframework.web.socket.support.LoggingWebSocketHandlerDecorator;
/**
* An {@link HttpRequestHandler} that wraps the invocation of a {@link HandshakeHandler}.
* An {@link HttpRequestHandler} for processing WebSocket handshake requests.
* <p>
* This is the main class to use when configuring a server WebSocket at a specific URL. It
* is a very thin wrapper around a {@link HandshakeHandler} and a {@link WebSocketHandler}
* instance also adapting the {@link HttpServletRequest} and {@link HttpServletResponse}
* to {@link ServerHttpRequest} and {@link ServerHttpResponse} respectively.
* <p>
* The {@link #decorateWebSocketHandler(WebSocketHandler)} method decorates the given
* WebSocketHandler with a logging and exception handling decorators. This method can
* be overridden to change that.
*
* @author Rossen Stoyanchev
* @since 4.0

View File

@ -48,7 +48,6 @@ import org.springframework.web.socket.WebSocketHandler;
* support, SockJS path resolution, and processing for static SockJS requests (e.g.
* "/info", "/iframe.html", etc). Sub-classes are responsible for handling transport
* requests.
*
* <p>
* It is expected that this service is mapped correctly to one or more prefixes such as
* "/echo" including all sub-URLs (e.g. "/echo/**"). A SockJS service itself is generally

View File

@ -31,11 +31,12 @@ import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.WebSocketMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.adapter.ConfigurableWebSocketSession;
/**
* TODO
* An abstract base class SockJS sessions implementing {@link WebSocketSession}.
*
* @author Rossen Stoyanchev
* @since 4.0
@ -314,7 +315,7 @@ public abstract class AbstractSockJsSession implements ConfigurableWebSocketSess
logger.warn("Terminating connection due to failure to send message: " + ex.getMessage());
disconnect(CloseStatus.SERVER_ERROR);
close(CloseStatus.SERVER_ERROR);
throw new SockJsRuntimeException("Failed to write " + frame, ex);
throw new TransportErrorException("Failed to write " + frame, ex, this.getId());
}
}

View File

@ -17,6 +17,8 @@
package org.springframework.web.socket.sockjs;
/**
* A {@link TransportHandler} that requires access to SockJS configuration options.
*
* @author Rossen Stoyanchev
* @since 4.0
*/

View File

@ -19,6 +19,9 @@ package org.springframework.web.socket.sockjs;
import org.springframework.scheduling.TaskScheduler;
/**
* SockJS configuration options that need to be made available to {@link TransportHandler}
* s and SockJS sessions.
*
* @author Rossen Stoyanchev
* @since 4.0
*/

View File

@ -23,6 +23,9 @@ import org.springframework.util.Assert;
import com.fasterxml.jackson.core.io.JsonStringEncoder;
/**
* Represents a SockJS frames. Provides methods for access to commonly used message
* frames.
*
* @author Rossen Stoyanchev
* @since 4.0
*/

View File

@ -23,9 +23,12 @@ import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.socket.WebSocketHandler;
/**
* A service for processing SockJS requests.
*
* @author Rossen Stoyanchev
* @since 4.0
*
* @see org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler
*/
public interface SockJsService {

View File

@ -19,7 +19,8 @@ package org.springframework.web.socket.sockjs;
import org.springframework.web.socket.WebSocketHandler;
/**
* A factory for creating a SockJS session.
* A factory for creating a SockJS session. {@link TransportHandler}s typically also serve
* as SockJS session factories.
*
* @param <S> The type of session being created
* @author Rossen Stoyanchev

View File

@ -22,13 +22,12 @@ import org.springframework.web.socket.WebSocketHandler;
/**
* Raised when a TransportHandler fails during request processing.
*
* <p>If the underlying exception occurs while sending messages to the client,
* the session will have been closed and the {@link WebSocketHandler} notified.
*
* <p>If the underlying exception occurs while processing an incoming HTTP request
* including posted messages, the session will remain open. Only the incoming
* request is rejected.
* <p>
* If the underlying exception occurs while sending messages to the client, the session is
* closed and the {@link WebSocketHandler} notified.
* <p>
* If the underlying exception occurs while processing an incoming HTTP request, including
* over HTTP POST, the session will remain open. Only the incoming request is rejected.
*
* @author Rossen Stoyanchev
* @since 4.0

View File

@ -21,8 +21,16 @@ import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.socket.WebSocketHandler;
/**
* A contract for SockJS transport implementations. A {@link TransportHandler} is closely
* related to and often delegates to an {@link AbstractSockJsSession}. In fact most
* transports are also implementations of {@link SockJsSessionFactory} with the only exception
* to that being HTTP transports that receive messages as they depend on finding an existing
* session. See {@link TransportType} for a list of all available transport types.
*
* @author Rossen Stoyanchev
* @since 4.0
*
* @see SockJsService
*/
public interface TransportHandler {

View File

@ -24,6 +24,8 @@ import java.util.Map;
import org.springframework.http.HttpMethod;
/**
* SockJS server transport types.
*
* @author Rossen Stoyanchev
* @since 4.0
*/

View File

@ -60,7 +60,8 @@ import org.springframework.web.socket.sockjs.transport.XhrTransportHandler;
/**
* A default implementation of {@link SockJsService} adding support for transport handling
* and session management.
* and session management. See {@link AbstractSockJsService} base class for important
* details on request mapping.
*
* @author Rossen Stoyanchev
* @since 4.0

View File

@ -34,6 +34,17 @@ import org.springframework.web.socket.support.ExceptionWebSocketHandlerDecorator
import org.springframework.web.socket.support.LoggingWebSocketHandlerDecorator;
/**
* An {@link HttpRequestHandler} for processing SockJS requests.
* <p>
* This is the main class to use when configuring a SockJS service at a specific URL. It
* is a very thin wrapper around a {@link SockJsService} and a {@link WebSocketHandler}
* instance also adapting the {@link HttpServletRequest} and {@link HttpServletResponse}
* to {@link ServerHttpRequest} and {@link ServerHttpResponse} respectively.
* <p>
* The {@link #decorateWebSocketHandler(WebSocketHandler)} method decorates the given
* WebSocketHandler with a logging and exception handling decorators. This method can be
* overridden to change that.
*
* @author Rossen Stoyanchev
* @since 4.0
*/

View File

@ -15,7 +15,7 @@
*/
/**
* Server-side SockJS classes including a
* Key server-side SockJS implementation classes including a
* {@link org.springframework.web.socket.sockjs.support.DefaultSockJsService} implementation
* as well as a Spring MVC HandlerMapping mapping SockJS services to incoming requests.
*

View File

@ -36,7 +36,7 @@ import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* Base class for HTTP-based transports that read input messages.
* Base class for HTTP-based transports that read input messages from HTTP requests.
*
* @author Rossen Stoyanchev
* @since 4.0

View File

@ -33,7 +33,7 @@ import org.springframework.web.socket.sockjs.SockJsSessionFactory;
import org.springframework.web.socket.sockjs.TransportErrorException;
/**
* TODO
* Base class for HTTP-based transports that send messages over HTTP.
*
* @author Rossen Stoyanchev
* @since 4.0

View File

@ -34,7 +34,7 @@ import org.springframework.web.socket.sockjs.TransportErrorException;
import org.springframework.web.socket.support.ExceptionWebSocketHandlerDecorator;
/**
* An abstract base class for use with HTTP-based transports.
* An abstract base class for use with HTTP transport based SockJS sessions.
*
* @author Rossen Stoyanchev
* @since 4.0

View File

@ -23,12 +23,13 @@ import org.springframework.http.MediaType;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.util.Assert;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.sockjs.TransportType;
import org.springframework.web.socket.sockjs.SockJsFrame.DefaultFrameFormat;
import org.springframework.web.socket.sockjs.SockJsFrame.FrameFormat;
import org.springframework.web.socket.sockjs.TransportType;
/**
* TODO
* A TransportHandler for sending messages via Server-Sent events:
* <a href="http://dev.w3.org/html5/eventsource/">http://dev.w3.org/html5/eventsource/</a>.
*
* @author Rossen Stoyanchev
* @since 4.0

View File

@ -26,14 +26,17 @@ import org.springframework.http.server.ServerHttpResponse;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.sockjs.TransportErrorException;
import org.springframework.web.socket.sockjs.TransportType;
import org.springframework.web.socket.sockjs.SockJsFrame.DefaultFrameFormat;
import org.springframework.web.socket.sockjs.SockJsFrame.FrameFormat;
import org.springframework.web.socket.sockjs.TransportErrorException;
import org.springframework.web.socket.sockjs.TransportHandler;
import org.springframework.web.socket.sockjs.TransportType;
import org.springframework.web.util.JavaScriptUtils;
/**
* TODO
* An HTTP {@link TransportHandler} that uses a famous browsder document.domain technique:
* <a href="http://stackoverflow.com/questions/1481251/what-does-document-domain-document-domain-do">
* http://stackoverflow.com/questions/1481251/what-does-document-domain-document-domain-do</a>
*
* @author Rossen Stoyanchev
* @since 4.0

View File

@ -26,13 +26,13 @@ import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.sockjs.SockJsFrame;
import org.springframework.web.socket.sockjs.SockJsFrame.FrameFormat;
import org.springframework.web.socket.sockjs.TransportErrorException;
import org.springframework.web.socket.sockjs.TransportType;
import org.springframework.web.socket.sockjs.SockJsFrame.FrameFormat;
import org.springframework.web.util.JavaScriptUtils;
/**
* TODO
* A TransportHandler that sends messages via JSONP polling.
*
* @author Rossen Stoyanchev
* @since 4.0

View File

@ -27,8 +27,14 @@ import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
import org.springframework.web.socket.sockjs.AbstractSockJsSession;
import org.springframework.web.socket.sockjs.TransportErrorException;
import org.springframework.web.socket.sockjs.TransportHandler;
import org.springframework.web.socket.sockjs.TransportType;
/**
* A {@link TransportHandler} that receives messages over HTTP.
*
* @author Rossen Stoyanchev
*/
public class JsonpTransportHandler extends AbstractHttpReceivingTransportHandler {
private final FormHttpMessageConverter formConverter = new FormHttpMessageConverter();

View File

@ -21,7 +21,11 @@ import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.sockjs.SockJsConfiguration;
import org.springframework.web.socket.sockjs.SockJsFrame;
/**
* A SockJS session for use with polling HTTP transports.
*
* @author Rossen Stoyanchev
*/
public class PollingSockJsSession extends AbstractHttpSockJsSession {
public PollingSockJsSession(String sessionId, SockJsConfiguration config, WebSocketHandler handler) {

View File

@ -28,14 +28,14 @@ import org.springframework.web.socket.sockjs.SockJsConfiguration;
/**
* A wrapper around a {@link WebSocketHandler} instance that parses and adds SockJS
* messages frames and also sends SockJS heartbeat messages.
*
* An implementation of {@link WebSocketHandler} that adds SockJS messages frames, sends
* SockJS heartbeat messages, and delegates lifecycle events and messages to a target
* {@link WebSocketHandler}.
* <p>
* Implementations of the {@link WebSocketHandler} interface in this class allow
* exceptions from the wrapped {@link WebSocketHandler} to propagate. However, any
* exceptions resulting from SockJS message handling (e.g. while sending SockJS frames or
* heartbeat messages) are caught and treated as transport errors, i.e. routed to the
* Methods in this class allow exceptions from the wrapped {@link WebSocketHandler} to
* propagate. However, any exceptions resulting from SockJS message handling (e.g. while
* sending SockJS frames or heartbeat messages) are caught and treated as transport
* errors, i.e. routed to the
* {@link WebSocketHandler#handleTransportError(WebSocketSession, Throwable)
* handleTransportError} method of the wrapped handler and the session closed.
*

View File

@ -23,9 +23,14 @@ import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.sockjs.SockJsConfiguration;
import org.springframework.web.socket.sockjs.SockJsFrame;
import org.springframework.web.socket.sockjs.TransportErrorException;
import org.springframework.web.socket.sockjs.SockJsFrame.FrameFormat;
import org.springframework.web.socket.sockjs.TransportErrorException;
/**
* A SockJS session for use with streaming HTTP transports.
*
* @author Rossen Stoyanchev
*/
public class StreamingSockJsSession extends AbstractHttpSockJsSession {
private int byteCount;

View File

@ -31,8 +31,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
/**
* A WebSocket implementation of {@link AbstractSockJsSession}. Delegates to a
* {@link WebSocketSession}.
* A SockJS session for use with the WebSocket transport.
*
* @author Rossen Stoyanchev
* @since 4.0

View File

@ -33,9 +33,11 @@ import org.springframework.web.socket.sockjs.TransportType;
/**
* A WebSocket {@link TransportHandler} that delegates to a {@link HandshakeHandler}
* passing a SockJS {@link WebSocketHandler}. Also implements {@link HandshakeHandler}
* directly in support for raw WebSocket communication at SockJS URL "/websocket".
* A WebSocket {@link TransportHandler}. Uses {@link SockJsWebSocketHandler} and
* {@link WebSocketServerSockJsSession} to add SockJS processing.
* <p>
* Also implements {@link HandshakeHandler} to support raw WebSocket communication at
* SockJS URL "/websocket".
*
* @author Rossen Stoyanchev
* @since 4.0

View File

@ -21,13 +21,14 @@ import org.springframework.http.MediaType;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.util.Assert;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.sockjs.TransportType;
import org.springframework.web.socket.sockjs.SockJsFrame.DefaultFrameFormat;
import org.springframework.web.socket.sockjs.SockJsFrame.FrameFormat;
import org.springframework.web.socket.sockjs.TransportHandler;
import org.springframework.web.socket.sockjs.TransportType;
/**
* TODO
* A {@link TransportHandler} based on XHR (long) polling.
*
* @author Rossen Stoyanchev
* @since 4.0

View File

@ -22,13 +22,14 @@ import org.springframework.http.MediaType;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.util.Assert;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.sockjs.TransportType;
import org.springframework.web.socket.sockjs.SockJsFrame.DefaultFrameFormat;
import org.springframework.web.socket.sockjs.SockJsFrame.FrameFormat;
import org.springframework.web.socket.sockjs.TransportHandler;
import org.springframework.web.socket.sockjs.TransportType;
/**
* TODO
* A {@link TransportHandler} that sends messages over an HTTP streaming request.
*
* @author Rossen Stoyanchev
* @since 4.0

View File

@ -19,8 +19,15 @@ import java.io.IOException;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.web.socket.sockjs.TransportHandler;
import org.springframework.web.socket.sockjs.TransportType;
/**
* A {@link TransportHandler} that receives messages over HTTP.
*
* @author Rossen Stoyanchev
*/
public class XhrTransportHandler extends AbstractHttpReceivingTransportHandler {

View File

@ -26,7 +26,10 @@ import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.util.Assert;
/**
*
* Instantiates a target handler through a Spring {@link BeanFactory} and also provides
* an equivalent destroy method. Mainly for internal use to assist with initializing and
* destroying handlers with per-connection lifecycle.
*
* @author Rossen Stoyanchev
* @since 4.0
*/

View File

@ -25,6 +25,10 @@ import org.springframework.web.socket.WebSocketSession;
/**
* An exception handling {@link WebSocketHandlerDecorator}. Traps all {@link Throwable}
* instances that escape from the decorated handler and closes the session with
* {@link CloseStatus#SERVER_ERROR}.
*
* @author Rossen Stoyanchev
* @since 4.0
*/

View File

@ -25,6 +25,8 @@ import org.springframework.web.socket.WebSocketSession;
/**
* A {@link WebSocketHandlerDecorator} that adds logging to WebSocket lifecycle events.
*
* @author Rossen Stoyanchev
* @since 4.0
*/

View File

@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@ -14,24 +14,11 @@
* limitations under the License.
*/
package org.springframework.web.socket.sockjs;
import org.springframework.core.NestedRuntimeException;
/**
*
* @author Rossen Stoyanchev
* @since 4.0
* WebSocket-related classes used by client and server code such as
* a {@link org.springframework.web.socket.support.WebSocketHandlerDecorator}
* and sub-class implementations, as well as a
* {@link org.springframework.web.socket.support.PerConnectionWebSocketHandler}.
*/
@SuppressWarnings("serial")
public class SockJsRuntimeException extends NestedRuntimeException {
package org.springframework.web.socket.support;
public SockJsRuntimeException(String msg) {
super(msg);
}
public SockJsRuntimeException(String msg, Throwable cause) {
super(msg, cause);
}
}

View File

@ -211,7 +211,7 @@ public class AbstractSockJsSessionTests extends BaseAbstractSockJsSessionTests<T
this.session.writeFrame(SockJsFrame.openFrame());
fail("expected exception");
}
catch (SockJsRuntimeException ex) {
catch (TransportErrorException ex) {
assertEquals(CloseStatus.SERVER_ERROR, this.session.getStatus());
verify(this.webSocketHandler).afterConnectionClosed(this.session, CloseStatus.SERVER_ERROR);
}