public <T> T getEndpointInstance(java.lang.Class<T> endpointClass) throws java.lang.InstantiationException { if (JSR356Endpoint.class.isAssignableFrom(endpointClass)) { JSR356Endpoint e = new JSR356Endpoint(framework, WebSocketProcessorFactory.getDefault().getWebSocketProcessor(framework)); if (hRequest.get() != null) { e.handshakeRequest(hRequest.get()); hRequest.set(null); } else { endPoint.set(e); } return (T) e; } else { return super.getEndpointInstance(endpointClass); } }
@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); }
@Override public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException { T endpoint = super.getEndpointInstance(endpointClass); if (endpoint instanceof KafkaWebsocketEndpoint) { return endpoint; } throw new InstantiationException( MessageFormat.format("Expected instanceof \"{0}\". Got instanceof \"{1}\".", KafkaWebsocketEndpoint.class, endpoint.getClass())); } }
/** * This method is called by the container each time a new client * connects to the logical endpoint this configurator configures. * Developers may override this method to control instantiation of * endpoint instances in order to customize the initialization * of the endpoint instance, or manage them in some other way. * If the developer overrides this method, services like * dependency injection that are otherwise supported, for example, when * the implementation is part of the Java EE platform * may not be available. * The platform default implementation of this method returns a new * endpoint instance per call, thereby ensuring that there is one * endpoint instance per client, the default deployment cardinality. * * @param endpointClass the class of the endpoint * @param <T> the type of the endpoint * @return an instance of the endpoint that will handle all * interactions from a new client. * @throws InstantiationException if there was an error producing the * endpoint instance. */ public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException { return this.getContainerDefaultConfigurator().getEndpointInstance(endpointClass); }
/** * This method is called by the container each time a new client * connects to the logical endpoint this configurator configures. * Developers may override this method to control instantiation of * endpoint instances in order to customize the initialization * of the endpoint instance, or manage them in some other way. * If the developer overrides this method, services like * dependency injection that are otherwise supported, for example, when * the implementation is part of the Java EE platform * may not be available. * The platform default implementation of this method returns a new * endpoint instance per call, thereby ensuring that there is one * endpoint instance per client, the default deployment cardinality. * * @param endpointClass the class of the endpoint * @param <T> the type of the endpoint * @return an instance of the endpoint that will handle all * interactions from a new client. * @throws InstantiationException if there was an error producing the * endpoint instance. */ public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException { return this.getContainerDefaultConfigurator().getEndpointInstance(endpointClass); }
/** * This method is called by the container each time a new client connects to the logical endpoint this * configurator configures. Developers may override this method to control instantiation of endpoint instances * in order to customize the initialization of the endpoint instance, or manage them in some other way. If the * developer overrides this method, services like dependency injection that are otherwise supported, for * example, when the implementation is part of the Java EE platform may not be available. The platform default * implementation of this method returns a new endpoint instance per call, thereby ensuring that there is one * endpoint instance per client, the default deployment cardinality. * * @param endpointClass the class of the endpoint * @param <T> the type of the endpoint * @return an instance of the endpoint that will handle all interactions from a new client. * @throws InstantiationException if there was an error producing the endpoint instance. */ public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException { return this.getContainerDefaultConfigurator().getEndpointInstance(endpointClass); }
@Override public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException { T ret = super.getEndpointInstance(endpointClass); //To change body of generated methods, choose Tools | Templates. if (!(ret instanceof WebsocketEndpoint)) { throw new AssertionError(); } WebsocketEndpoint endpoint = (WebsocketEndpoint) ret; GlobalThreadLocal gtl = GlobalThreadLocal.get(); HttpServletRequest req = gtl.getHttpRequest(); WebsocketContext wskCtx = new WebsocketContext(ctx, rpcCtx, req.getSession(), gtl.getSecurityContext()); endpoint.getContextMap().put(req.getParameterMap().get("requestId")[0], wskCtx); return ret; }
@Override public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException { T ret = super.getEndpointInstance(endpointClass); //To change body of generated methods, choose Tools | Templates. if (!(ret instanceof WebsocketEndpoint)) { throw new AssertionError(); } WebsocketEndpoint endpoint = (WebsocketEndpoint) ret; GlobalThreadLocal gtl = GlobalThreadLocal.get(); HttpServletRequest req = gtl.getHttpRequest(); WebsocketContext wskCtx = new WebsocketContext(ctx, rpcCtx, req.getSession(), gtl.getSecurityContext()); endpoint.getContextMap().put(req.getParameterMap().get("requestId")[0], wskCtx); return ret; }
@Override public <T> T getEndpointInstance(Class<T> eClass) throws InstantiationException { if (EndpointDelegate.class.equals(eClass)) { return eClass.cast(new EndpointDelegate(endpointMeta)); } return cfgr.getEndpointInstance(eClass); } };
@Override public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException { return configurator.getEndpointInstance(endpointClass); } };
@Override public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException { return delegate.getEndpointInstance(endpointClass); } }
public <T extends Object> T getEndpointInstance(Class<T> clazz) throws InstantiationException { return fetchContainerDefaultConfigurator().getEndpointInstance( clazz); } }
@Override public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException { return delegate.getEndpointInstance(endpointClass); } }
@Override public <T> Object getEndpointInstance(Class<T> endpointClass) throws InstantiationException { return ((ServerEndpointConfig) configuration).getConfigurator() .getEndpointInstance(endpointClass); } };
@Override public <T> Object getEndpointInstance(Class<T> endpointClass) throws InstantiationException { return ((ServerEndpointConfig) configuration).getConfigurator() .getEndpointInstance(endpointClass); } };
public <T extends Object> T getEndpointInstance(Class<T> clazz) throws InstantiationException { return fetchContainerDefaultConfigurator().getEndpointInstance( clazz); } }
@Override @SuppressWarnings(value = "unchecked") public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException { if (MatlabServerEndpoint.class.isAssignableFrom(endpointClass)) { return (T) new MatlabServerEndpoint(pool); } return super.getEndpointInstance(endpointClass); }
public <T extends Object> T getEndpointInstance(Class<T> clazz) throws InstantiationException { return fetchContainerDefaultConfigurator().getEndpointInstance( clazz); } }
@Override public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException { return configurator.getEndpointInstance(endpointClass); } };
@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); }