Making subprotocol negotiation behavior report warnings on bad configuration
This commit is contained in:
parent
2944339893
commit
1eca1e7c3c
|
@ -28,6 +28,7 @@ import javax.websocket.server.ServerEndpointConfig.Configurator;
|
|||
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.websocket.api.util.QuoteUtil;
|
||||
|
||||
public class BasicServerEndpointConfigurator extends Configurator
|
||||
{
|
||||
|
@ -63,6 +64,21 @@ public class BasicServerEndpointConfigurator extends Configurator
|
|||
@Override
|
||||
public String getNegotiatedSubprotocol(List<String> supported, List<String> requested)
|
||||
{
|
||||
if ((requested == null) || (requested.size() == 0))
|
||||
{
|
||||
// nothing requested, don't return anything
|
||||
return null;
|
||||
}
|
||||
|
||||
// Nothing specifically called out as being supported by the endpoint
|
||||
if ((supported == null) || (supported.isEmpty()))
|
||||
{
|
||||
// Just return the first hit in this case
|
||||
LOG.warn("Client requested Subprotocols on endpoint with none supported: {}", QuoteUtil.join(requested,","));
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return the first matching hit from the list of supported protocols.
|
||||
for (String possible : requested)
|
||||
{
|
||||
if (supported.contains(possible))
|
||||
|
@ -70,6 +86,8 @@ public class BasicServerEndpointConfigurator extends Configurator
|
|||
return possible;
|
||||
}
|
||||
}
|
||||
|
||||
LOG.warn("Client requested subprotocols {} do not match any endpoint supported subprotocols {}", QuoteUtil.join(requested,","), QuoteUtil.join(supported,","));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ import org.eclipse.jetty.util.StringUtil;
|
|||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
@ServerEndpoint(value = "/", configurator = JsrBrowserConfigurator.class)
|
||||
@ServerEndpoint(value = "/", subprotocols = { "tool" }, configurator = JsrBrowserConfigurator.class)
|
||||
public class JsrBrowserSocket
|
||||
{
|
||||
private static class WriteMany implements Runnable
|
||||
|
|
|
@ -20,6 +20,10 @@ div#console .info {
|
|||
color: black;
|
||||
}
|
||||
|
||||
div#console .error {
|
||||
color: red;
|
||||
}
|
||||
|
||||
div#console .client {
|
||||
color: blue;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ var wstool = {
|
|||
this._ws.onopen = this._onopen;
|
||||
this._ws.onmessage = this._onmessage;
|
||||
this._ws.onclose = this._onclose;
|
||||
this._ws.onerror = this._onerror;
|
||||
} catch (exception) {
|
||||
wstool.info("Connect Error: " + exception);
|
||||
}
|
||||
|
@ -58,6 +59,10 @@ var wstool = {
|
|||
wstool._out("info", message);
|
||||
},
|
||||
|
||||
error : function(message) {
|
||||
wstool._out("error", message);
|
||||
},
|
||||
|
||||
infoc : function(message) {
|
||||
wstool._out("client", "[c] " + message);
|
||||
},
|
||||
|
@ -83,6 +88,12 @@ var wstool = {
|
|||
wstool.setState(true);
|
||||
wstool.info("Websocket Connected");
|
||||
},
|
||||
|
||||
_onerror : function(evt) {
|
||||
wstool.setState(false);
|
||||
wstool.error("Websocket Error: " + evt.data);
|
||||
wstool.error("See Javascript Console for possible detailed error message");
|
||||
},
|
||||
|
||||
_send : function(message) {
|
||||
if (this._ws) {
|
||||
|
|
Loading…
Reference in New Issue