move check for duplicate mappings to WebSocketMapping class

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2019-01-22 18:08:31 +11:00
parent 4008005a0e
commit 3c2f728574
2 changed files with 11 additions and 13 deletions

View File

@ -44,15 +44,16 @@ import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.WebSocketException;
import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry;
import org.eclipse.jetty.websocket.core.WebSocketResources;
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
import org.eclipse.jetty.websocket.javax.client.JavaxWebSocketClientContainer;
import org.eclipse.jetty.websocket.javax.common.InvalidWebSocketException;
import org.eclipse.jetty.websocket.javax.server.internal.AnnotatedServerEndpointConfig;
import org.eclipse.jetty.websocket.javax.server.internal.JavaxWebSocketCreator;
import org.eclipse.jetty.websocket.javax.server.internal.UndefinedServerEndpointConfig;
import org.eclipse.jetty.websocket.servlet.WebSocketMapping;
import org.eclipse.jetty.websocket.servlet.WebSocketUpgradeFilter;
@ManagedObject("JSR356 Server Container")
public class JavaxWebSocketServerContainer
@ -108,7 +109,7 @@ public class JavaxWebSocketServerContainer
// Create the Jetty ServerContainer implementation
container = new JavaxWebSocketServerContainer(
WebSocketMapping.ensureMapping(servletContext),
WebSocketUpgradeFilter.getMapping(servletContext),
WebSocketResources.ensureWebSocketResources(servletContext),
httpClient, executor);
contextHandler.addManaged(container);
@ -238,7 +239,7 @@ public class JavaxWebSocketServerContainer
ServerEndpointConfig config = new AnnotatedServerEndpointConfig(this, endpointClass, anno);
addEndpointMapping(config);
}
catch (InvalidWebSocketException e)
catch (WebSocketException e)
{
throw new DeploymentException("Unable to deploy: " + endpointClass.getName(), e);
}
@ -270,7 +271,7 @@ public class JavaxWebSocketServerContainer
{
addEndpointMapping(config);
}
catch (InvalidWebSocketException e)
catch (WebSocketException e)
{
throw new DeploymentException("Unable to deploy: " + config.getEndpointClass().getName(), e);
}
@ -285,19 +286,14 @@ public class JavaxWebSocketServerContainer
}
}
private void addEndpointMapping(ServerEndpointConfig config) throws InvalidWebSocketException
private void addEndpointMapping(ServerEndpointConfig config) throws WebSocketException
{
frameHandlerFactory.getMetadata(config.getEndpointClass(), config);
JavaxWebSocketCreator creator = new JavaxWebSocketCreator(this, config, webSocketResources
.getExtensionRegistry());
PathSpec pathSpec = new UriTemplatePathSpec(config.getPath());
if (webSocketMapping.getMapping(pathSpec) != null)
throw new InvalidWebSocketException("endpoint path mapping already registered");
webSocketMapping.addMapping(pathSpec, creator, frameHandlerFactory, customizer);
}

View File

@ -40,6 +40,7 @@ import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.WebSocketException;
import org.eclipse.jetty.websocket.core.WebSocketResources;
import org.eclipse.jetty.websocket.core.server.Handshaker;
import org.eclipse.jetty.websocket.core.server.Negotiation;
@ -117,10 +118,11 @@ public class WebSocketMapping implements Dumpable, LifeCycle.Listener
* @param customizer the customizer to use to customize the WebSocket session.
*/
public void addMapping(PathSpec pathSpec, WebSocketCreator creator, FrameHandlerFactory factory, FrameHandler.Customizer customizer)
throws WebSocketException
{
// Handling for response forbidden (and similar paths)
// no creation, sorry
// No factory worked!
if (getMapping(pathSpec) != null)
throw new WebSocketException("Duplicate WebSocket Mapping for PathSpec");
mappings.put(pathSpec, new Negotiator(creator, factory, customizer));
}