482270 - Expose upgrade request locales.

Exposed as a user property.
This commit is contained in:
Simone Bordet 2015-12-08 12:02:57 +01:00
parent 66e596511d
commit e6f23a692e

View File

@ -20,7 +20,9 @@ package org.eclipse.jetty.websocket.jsr356.server;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.websocket.Extension;
import javax.websocket.Extension.Parameter;
@ -43,6 +45,7 @@ public class JsrCreator implements WebSocketCreator
{
public static final String PROP_REMOTE_ADDRESS = "javax.websocket.endpoint.remoteAddress";
public static final String PROP_LOCAL_ADDRESS = "javax.websocket.endpoint.localAddress";
public static final String PROP_LOCALES = "javax.websocket.upgrade.locales";
private static final Logger LOG = Log.getLogger(JsrCreator.class);
private final ServerEndpointMetadata metadata;
private final ExtensionFactory extensionFactory;
@ -61,17 +64,19 @@ public class JsrCreator implements WebSocketCreator
// Get raw config, as defined when the endpoint was added to the container
ServerEndpointConfig config = metadata.getConfig();
// Establish a copy of the config, so that the UserProperties are unique
// per upgrade request.
config = new BasicServerEndpointConfig(config);
// Bug 444617 - Expose localAddress and remoteAddress for jsr modify handshake to use
// This is being implemented as an optional set of userProperties so that
// it is not JSR api breaking. A few users on #jetty and a few from cometd
// have asked for access to this information.
config.getUserProperties().put(PROP_LOCAL_ADDRESS,req.getLocalSocketAddress());
config.getUserProperties().put(PROP_REMOTE_ADDRESS,req.getRemoteSocketAddress());
Map<String, Object> userProperties = config.getUserProperties();
userProperties.put(PROP_LOCAL_ADDRESS,req.getLocalSocketAddress());
userProperties.put(PROP_REMOTE_ADDRESS,req.getRemoteSocketAddress());
userProperties.put(PROP_LOCALES,Collections.list(req.getLocales()));
// Get Configurator from config object (not guaranteed to be unique per endpoint upgrade)
ServerEndpointConfig.Configurator configurator = config.getConfigurator();