Issue #424 - Jetty impl. of Websocket ServerEndpointConfig.Configurator lifecycle out of spec
This commit is contained in:
parent
8eb240c2be
commit
032e984674
|
@ -59,8 +59,8 @@ public class JsrCreator implements WebSocketCreator
|
||||||
@Override
|
@Override
|
||||||
public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp)
|
public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp)
|
||||||
{
|
{
|
||||||
JsrHandshakeRequest hsreq = new JsrHandshakeRequest(req);
|
JsrHandshakeRequest jsrHandshakeRequest = new JsrHandshakeRequest(req);
|
||||||
JsrHandshakeResponse hsresp = new JsrHandshakeResponse(resp);
|
JsrHandshakeResponse jsrHandshakeResponse = new JsrHandshakeResponse(resp);
|
||||||
|
|
||||||
// Get raw config, as defined when the endpoint was added to the container
|
// Get raw config, as defined when the endpoint was added to the container
|
||||||
ServerEndpointConfig config = metadata.getConfig();
|
ServerEndpointConfig config = metadata.getConfig();
|
||||||
|
@ -81,10 +81,7 @@ public class JsrCreator implements WebSocketCreator
|
||||||
// Get Configurator from config object (not guaranteed to be unique per endpoint upgrade)
|
// Get Configurator from config object (not guaranteed to be unique per endpoint upgrade)
|
||||||
ServerEndpointConfig.Configurator configurator = config.getConfigurator();
|
ServerEndpointConfig.Configurator configurator = config.getConfigurator();
|
||||||
|
|
||||||
// modify handshake
|
// [JSR] Step 1: check origin
|
||||||
configurator.modifyHandshake(config,hsreq,hsresp);
|
|
||||||
|
|
||||||
// check origin
|
|
||||||
if (!configurator.checkOrigin(req.getOrigin()))
|
if (!configurator.checkOrigin(req.getOrigin()))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -99,7 +96,7 @@ public class JsrCreator implements WebSocketCreator
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// deal with sub protocols
|
// [JSR] Step 2: deal with sub protocols
|
||||||
List<String> supported = config.getSubprotocols();
|
List<String> supported = config.getSubprotocols();
|
||||||
List<String> requested = req.getSubProtocols();
|
List<String> requested = req.getSubProtocols();
|
||||||
String subprotocol = configurator.getNegotiatedSubprotocol(supported,requested);
|
String subprotocol = configurator.getNegotiatedSubprotocol(supported,requested);
|
||||||
|
@ -108,22 +105,22 @@ public class JsrCreator implements WebSocketCreator
|
||||||
resp.setAcceptedSubProtocol(subprotocol);
|
resp.setAcceptedSubProtocol(subprotocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
// deal with extensions
|
// [JSR] Step 3: deal with extensions
|
||||||
List<Extension> installedExts = new ArrayList<>();
|
List<Extension> installedExtensions = new ArrayList<>();
|
||||||
for (String extName : extensionFactory.getAvailableExtensions().keySet())
|
for (String extName : extensionFactory.getAvailableExtensions().keySet())
|
||||||
{
|
{
|
||||||
installedExts.add(new JsrExtension(extName));
|
installedExtensions.add(new JsrExtension(extName));
|
||||||
}
|
}
|
||||||
List<Extension> requestedExts = new ArrayList<>();
|
List<Extension> requestedExts = new ArrayList<>();
|
||||||
for (ExtensionConfig reqCfg : req.getExtensions())
|
for (ExtensionConfig reqCfg : req.getExtensions())
|
||||||
{
|
{
|
||||||
requestedExts.add(new JsrExtension(reqCfg));
|
requestedExts.add(new JsrExtension(reqCfg));
|
||||||
}
|
}
|
||||||
List<Extension> usedExts = configurator.getNegotiatedExtensions(installedExts,requestedExts);
|
List<Extension> usedExtensions = configurator.getNegotiatedExtensions(installedExtensions,requestedExts);
|
||||||
List<ExtensionConfig> configs = new ArrayList<>();
|
List<ExtensionConfig> configs = new ArrayList<>();
|
||||||
if (usedExts != null)
|
if (usedExtensions != null)
|
||||||
{
|
{
|
||||||
for (Extension used : usedExts)
|
for (Extension used : usedExtensions)
|
||||||
{
|
{
|
||||||
ExtensionConfig ecfg = new ExtensionConfig(used.getName());
|
ExtensionConfig ecfg = new ExtensionConfig(used.getName());
|
||||||
for (Parameter param : used.getParameters())
|
for (Parameter param : used.getParameters())
|
||||||
|
@ -135,12 +132,8 @@ public class JsrCreator implements WebSocketCreator
|
||||||
}
|
}
|
||||||
resp.setExtensions(configs);
|
resp.setExtensions(configs);
|
||||||
|
|
||||||
// create endpoint class
|
// [JSR] Step 4: build out new ServerEndpointConfig
|
||||||
try
|
PathSpec pathSpec = jsrHandshakeRequest.getRequestPathSpec();
|
||||||
{
|
|
||||||
Class<?> endpointClass = config.getEndpointClass();
|
|
||||||
Object endpoint = config.getConfigurator().getEndpointInstance(endpointClass);
|
|
||||||
PathSpec pathSpec = hsreq.getRequestPathSpec();
|
|
||||||
if (pathSpec instanceof WebSocketPathSpec)
|
if (pathSpec instanceof WebSocketPathSpec)
|
||||||
{
|
{
|
||||||
// We have a PathParam path spec
|
// We have a PathParam path spec
|
||||||
|
@ -149,6 +142,15 @@ public class JsrCreator implements WebSocketCreator
|
||||||
// Wrap the config with the path spec information
|
// Wrap the config with the path spec information
|
||||||
config = new PathParamServerEndpointConfig(config,wspathSpec,requestPath);
|
config = new PathParamServerEndpointConfig(config,wspathSpec,requestPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// [JSR] Step 5: Call modifyHandshake
|
||||||
|
configurator.modifyHandshake(config,jsrHandshakeRequest,jsrHandshakeResponse);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// [JSR] Step 6: create endpoint class
|
||||||
|
Class<?> endpointClass = config.getEndpointClass();
|
||||||
|
Object endpoint = config.getConfigurator().getEndpointInstance(endpointClass);
|
||||||
return new EndpointInstance(endpoint,config,metadata);
|
return new EndpointInstance(endpoint,config,metadata);
|
||||||
}
|
}
|
||||||
catch (InstantiationException e)
|
catch (InstantiationException e)
|
||||||
|
|
Loading…
Reference in New Issue