javax.websocket.server
Class DefaultServerConfiguration

java.lang.Object
  extended by javax.websocket.server.DefaultServerConfiguration
All Implemented Interfaces:
EndpointConfiguration, ServerEndpointConfiguration

public class DefaultServerConfiguration
extends Object
implements ServerEndpointConfiguration

The DefaultServerConfiguration is a concrete class that embodies all the configuration parameters for an endpoint that is to be published as a server endpoint. Developers may subclass this class in order to override the configuration behavior.

Author:
dannycoward

Constructor Summary
DefaultServerConfiguration(Class<? extends Endpoint> endpointClass, String path)
          Creates a server configuration with the given path
 
Method Summary
 boolean checkOrigin(String originHeaderValue)
          Makes a check of the validity of the Origin header sent along with the opening handshake following the recommendation at: Sending the Server's Opening Handshake.
 List<Decoder> getDecoders()
          Return the Decoder implementations configured.
 List<Encoder> getEncoders()
          Return the Encoder implementations configured.
 Class<?> getEndpointClass()
          Returns the class of the Endpoint that this configuration configures.
 List<Extension> getNegotiatedExtensions(List<Extension> requestedExtensions)
          Provides a simple algorithm to return the list of extensions this server will use for the web socket session: the configuration returns a list containing all of the requested extensions passed to this method that it supports, using the order in the requested extensions, the empty list if none.
 String getNegotiatedSubprotocol(List<String> requestedSubprotocols)
          The default implementation of this method returns, the first subprotocol in the list sent by the client that the server supports, or null if there isn't one none.
 String getPath()
          Return the path of this server configuration.
 boolean matchesURI(URI uri)
          This default implementation matches the incoming path to the configuration's URI or URI template if and only if it is an exact match in the case the configuration is a URI, and if and only if it is a valid expansion of the configuration URI template, in the case where the configuration is a URI template.
 void modifyHandshake(HandshakeRequest request, HandshakeResponse response)
          The default server configuration does not make any changes to the response.
 DefaultServerConfiguration setDecoders(List<Decoder> decoders)
          Sets all the decoders that this configuration will support.
 DefaultServerConfiguration setEncoders(List<Encoder> encoders)
          Sets all the encoders that this configuration will support.
 DefaultServerConfiguration setExtensions(List<Extension> extensions)
          Sets all the extensions that this configuration will support.
 DefaultServerConfiguration setSubprotocols(List<String> subprotocols)
          Sets all the subprotocols that this configuration will support.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultServerConfiguration

public DefaultServerConfiguration(Class<? extends Endpoint> endpointClass,
                                  String path)
Creates a server configuration with the given path

Parameters:
path - the URI or URI template.
Method Detail

getEndpointClass

public Class<?> getEndpointClass()
Returns the class of the Endpoint that this configuration configures.

Specified by:
getEndpointClass in interface ServerEndpointConfiguration
Returns:
the class of the Endpoint.

setEncoders

public DefaultServerConfiguration setEncoders(List<Encoder> encoders)
Sets all the encoders that this configuration will support.

Parameters:
encoders - the encoders supported, may not be null.
Returns:
this server configuration instance.

setDecoders

public DefaultServerConfiguration setDecoders(List<Decoder> decoders)
Sets all the decoders that this configuration will support.

Parameters:
decoders - the encoders supported, may not be null.
Returns:
this server configuration instance.

setSubprotocols

public DefaultServerConfiguration setSubprotocols(List<String> subprotocols)
Sets all the subprotocols that this configuration will support.

Parameters:
subprotocols - the encoders supported, may not be null.
Returns:
this server configuration instance.

setExtensions

public DefaultServerConfiguration setExtensions(List<Extension> extensions)
Sets all the extensions that this configuration will support.

Parameters:
extensions - the encoders supported, may not be null.
Returns:
this server configuration instance.

getEncoders

public List<Encoder> getEncoders()
Return the Encoder implementations configured. These will be used by the container to encode outgoing messages.

Specified by:
getEncoders in interface EndpointConfiguration
Returns:
the encoders, in an unmodifiable list.

getDecoders

public List<Decoder> getDecoders()
Return the Decoder implementations configured. These will be used by the container to decode incoming messages into the expected custom objects on MessageHandler callbacks.

Specified by:
getDecoders in interface EndpointConfiguration
Returns:
the encoders, in an unmodifiable list.

getPath

public String getPath()
Return the path of this server configuration. The path is a relative URI or URI-template.

Specified by:
getPath in interface ServerEndpointConfiguration
Returns:
the path

getNegotiatedSubprotocol

public String getNegotiatedSubprotocol(List<String> requestedSubprotocols)
The default implementation of this method returns, the first subprotocol in the list sent by the client that the server supports, or null if there isn't one none. Subclasses may provide custom algorithms based on other factors.

Specified by:
getNegotiatedSubprotocol in interface ServerEndpointConfiguration
Parameters:
requestedSubprotocols - the list of requested subprotocols.
Returns:
the negotiated subprotocol.

getNegotiatedExtensions

public List<Extension> getNegotiatedExtensions(List<Extension> requestedExtensions)
Provides a simple algorithm to return the list of extensions this server will use for the web socket session: the configuration returns a list containing all of the requested extensions passed to this method that it supports, using the order in the requested extensions, the empty list if none. Subclasses may provide custom algorithms based on other factors.

Specified by:
getNegotiatedExtensions in interface ServerEndpointConfiguration
Parameters:
requestedExtensions - the list of extensions requested by the client
Returns:
the list of extensions that may be used.

checkOrigin

public boolean checkOrigin(String originHeaderValue)
Makes a check of the validity of the Origin header sent along with the opening handshake following the recommendation at: Sending the Server's Opening Handshake.

Specified by:
checkOrigin in interface ServerEndpointConfiguration
Parameters:
originHeaderValue - The value of the Origin header.
Returns:
whether the check passed or not.

matchesURI

public boolean matchesURI(URI uri)
This default implementation matches the incoming path to the configuration's URI or URI template if and only if it is an exact match in the case the configuration is a URI, and if and only if it is a valid expansion of the configuration URI template, in the case where the configuration is a URI template. Subclasses may override this method to provide different matching policies.

Specified by:
matchesURI in interface ServerEndpointConfiguration
Parameters:
uri - the URL of the incoming request
Returns:
whether it matched this configuration or not.

modifyHandshake

public void modifyHandshake(HandshakeRequest request,
                            HandshakeResponse response)
The default server configuration does not make any changes to the response. Subclasses may override this method in order to inspect the Http request headers of the openinghandshake, for example to track cookies sent by the client. Additionally subclasses may choose to override this method to modify the outgoing handshake response. the outgoing handshake response

Specified by:
modifyHandshake in interface ServerEndpointConfiguration
Parameters:
request - the handshake request from the client
response - the handshake response formulated by the container.



Copyright © 2012-2013 Oracle and/or its affiliates. All rights reserved.