private Object createEndpoint(ServerEndpointRegistration registration, ComponentProviderService provider, WebSocketContainer container, TyrusWebSocketEngine engine) throws DeploymentException { DirectFieldAccessor accessor = new DirectFieldAccessor(engine); Object sessionListener = accessor.getPropertyValue("sessionListener"); Object clusterContext = accessor.getPropertyValue("clusterContext"); try { if (constructorWithBooleanArgument) { // Tyrus 1.11+ return constructor.newInstance(registration.getEndpoint(), registration, provider, container, "/", registration.getConfigurator(), sessionListener, clusterContext, null, Boolean.TRUE); } else { return constructor.newInstance(registration.getEndpoint(), registration, provider, container, "/", registration.getConfigurator(), sessionListener, clusterContext, null); } } catch (Exception ex) { throw new HandshakeFailureException("Failed to register " + registration, ex); } }
@Test public void endpointPerConnection() throws Exception { @SuppressWarnings("resource") ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class); ServerEndpointRegistration registration = new ServerEndpointRegistration("/path", EchoEndpoint.class); registration.setBeanFactory(context.getBeanFactory()); EchoEndpoint endpoint = registration.getConfigurator().getEndpointInstance(EchoEndpoint.class); assertNotNull(endpoint); }
@Test public void endpointSingleton() throws Exception { EchoEndpoint endpoint = new EchoEndpoint(new EchoService()); ServerEndpointRegistration registration = new ServerEndpointRegistration("/path", endpoint); EchoEndpoint actual = registration.getConfigurator().getEndpointInstance(EchoEndpoint.class); assertSame(endpoint, actual); }
private Object createEndpoint(ServerEndpointRegistration registration, ComponentProviderService provider, WebSocketContainer container, TyrusWebSocketEngine engine) throws DeploymentException { DirectFieldAccessor accessor = new DirectFieldAccessor(engine); Object sessionListener = accessor.getPropertyValue("sessionListener"); Object clusterContext = accessor.getPropertyValue("clusterContext"); try { if (constructorWithBooleanArgument) { // Tyrus 1.11+ return constructor.newInstance(registration.getEndpoint(), registration, provider, container, "/", registration.getConfigurator(), sessionListener, clusterContext, null, Boolean.TRUE); } else { return constructor.newInstance(registration.getEndpoint(), registration, provider, container, "/", registration.getConfigurator(), sessionListener, clusterContext, null); } } catch (Exception ex) { throw new HandshakeFailureException("Failed to register " + registration, ex); } }
private Object createEndpoint(ServerEndpointRegistration registration, ComponentProviderService provider, WebSocketContainer container, TyrusWebSocketEngine engine) throws DeploymentException { DirectFieldAccessor accessor = new DirectFieldAccessor(engine); Object sessionListener = accessor.getPropertyValue("sessionListener"); Object clusterContext = accessor.getPropertyValue("clusterContext"); try { if (constructorWithBooleanArgument) { // Tyrus 1.11+ return constructor.newInstance(registration.getEndpoint(), registration, provider, container, "/", registration.getConfigurator(), sessionListener, clusterContext, null, Boolean.TRUE); } else { return constructor.newInstance(registration.getEndpoint(), registration, provider, container, "/", registration.getConfigurator(), sessionListener, clusterContext, null); } } catch (Exception ex) { throw new HandshakeFailureException("Failed to register " + registration, ex); } }