Issue #207 - javax.websocket.DeploymentException thrown at addEndpoint now
This commit is contained in:
parent
82942cb3a4
commit
3ee2e4ab7b
|
@ -19,6 +19,7 @@
|
||||||
package org.eclipse.jetty.websocket.jsr356.server;
|
package org.eclipse.jetty.websocket.jsr356.server;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -152,10 +153,56 @@ public class ServerContainer extends ClientContainer implements javax.websocket.
|
||||||
|
|
||||||
private void addEndpointMapping(ServerEndpointConfig config) throws DeploymentException
|
private void addEndpointMapping(ServerEndpointConfig config) throws DeploymentException
|
||||||
{
|
{
|
||||||
|
assertIsValidEndpoint(config);
|
||||||
|
|
||||||
JsrCreator creator = new JsrCreator(this, config, webSocketServerFactory.getExtensionFactory());
|
JsrCreator creator = new JsrCreator(this, config, webSocketServerFactory.getExtensionFactory());
|
||||||
mappedCreator.addMapping(new UriTemplatePathSpec(config.getPath()), creator);
|
mappedCreator.addMapping(new UriTemplatePathSpec(config.getPath()), creator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void assertIsValidEndpoint(ServerEndpointConfig config) throws DeploymentException
|
||||||
|
{
|
||||||
|
EndpointFunctions endpointFunctions = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Test that endpoint can be instantiated
|
||||||
|
Object endpoint = config.getEndpointClass().newInstance();
|
||||||
|
|
||||||
|
// Establish an EndpointFunctions to test validity of Endpoint declaration
|
||||||
|
AvailableEncoders availableEncoders = new AvailableEncoders(config);
|
||||||
|
AvailableDecoders availableDecoders = new AvailableDecoders(config);
|
||||||
|
Map<String, String> pathParameters = new HashMap<>();
|
||||||
|
endpointFunctions = newJsrEndpointFunction(endpoint, availableEncoders, availableDecoders, pathParameters, config);
|
||||||
|
endpointFunctions.start(); // this should trigger an exception if endpoint is invalid.
|
||||||
|
}
|
||||||
|
catch (InstantiationException e)
|
||||||
|
{
|
||||||
|
throw new DeploymentException("Unable to instantiate new instance of endpoint: " + config.getEndpointClass().getName(), e);
|
||||||
|
}
|
||||||
|
catch (IllegalAccessException e)
|
||||||
|
{
|
||||||
|
throw new DeploymentException("Unable access endpoint: " + config.getEndpointClass().getName(), e);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
throw new DeploymentException("Unable add endpoint: " + config.getEndpointClass().getName(), e);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (endpointFunctions != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Dispose of EndpointFunctions
|
||||||
|
endpointFunctions.stop();
|
||||||
|
}
|
||||||
|
catch (Exception ignore)
|
||||||
|
{
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EndpointFunctions newJsrEndpointFunction(Object endpoint,
|
public EndpointFunctions newJsrEndpointFunction(Object endpoint,
|
||||||
AvailableEncoders availableEncoders,
|
AvailableEncoders availableEncoders,
|
||||||
|
|
|
@ -36,6 +36,7 @@ import org.eclipse.jetty.websocket.jsr356.server.samples.InvalidOpenIntSocket;
|
||||||
import org.eclipse.jetty.websocket.jsr356.server.samples.InvalidOpenSessionIntSocket;
|
import org.eclipse.jetty.websocket.jsr356.server.samples.InvalidOpenSessionIntSocket;
|
||||||
import org.eclipse.jetty.websocket.server.MappedWebSocketCreator;
|
import org.eclipse.jetty.websocket.server.MappedWebSocketCreator;
|
||||||
import org.eclipse.jetty.websocket.server.WebSocketServerFactory;
|
import org.eclipse.jetty.websocket.server.WebSocketServerFactory;
|
||||||
|
import org.eclipse.jetty.websocket.server.WebSocketUpgradeHandlerWrapper;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
import org.junit.rules.ExpectedException;
|
||||||
|
@ -81,7 +82,7 @@ public class DeploymentExceptionTest
|
||||||
@Test
|
@Test
|
||||||
public void testDeploy_InvalidSignature() throws Exception
|
public void testDeploy_InvalidSignature() throws Exception
|
||||||
{
|
{
|
||||||
MappedWebSocketCreator creator = new DummyCreator();
|
MappedWebSocketCreator creator = new WebSocketUpgradeHandlerWrapper();
|
||||||
WebSocketServerFactory serverFactory = new WebSocketServerFactory();
|
WebSocketServerFactory serverFactory = new WebSocketServerFactory();
|
||||||
Executor executor = new QueuedThreadPool();
|
Executor executor = new QueuedThreadPool();
|
||||||
ServerContainer container = new ServerContainer(creator, serverFactory, executor);
|
ServerContainer container = new ServerContainer(creator, serverFactory, executor);
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
//
|
|
||||||
// ========================================================================
|
|
||||||
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
|
|
||||||
// ------------------------------------------------------------------------
|
|
||||||
// All rights reserved. This program and the accompanying materials
|
|
||||||
// are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
// and Apache License v2.0 which accompanies this distribution.
|
|
||||||
//
|
|
||||||
// The Eclipse Public License is available at
|
|
||||||
// http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
//
|
|
||||||
// The Apache License v2.0 is available at
|
|
||||||
// http://www.opensource.org/licenses/apache2.0.php
|
|
||||||
//
|
|
||||||
// You may elect to redistribute this code under either of these licenses.
|
|
||||||
// ========================================================================
|
|
||||||
//
|
|
||||||
|
|
||||||
package org.eclipse.jetty.websocket.jsr356.server;
|
|
||||||
|
|
||||||
import org.eclipse.jetty.http.pathmap.PathMappings;
|
|
||||||
import org.eclipse.jetty.http.pathmap.PathSpec;
|
|
||||||
import org.eclipse.jetty.websocket.server.MappedWebSocketCreator;
|
|
||||||
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
|
||||||
|
|
||||||
public class DummyCreator implements MappedWebSocketCreator
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void addMapping(PathSpec spec, WebSocketCreator creator)
|
|
||||||
{
|
|
||||||
/* do nothing */
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PathMappings<WebSocketCreator> getMappings()
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue