Refine search
@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 void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { log.trace("modifyHandshake"); super.modifyHandshake(sec, request, response); }
@Override public boolean checkOrigin(String originHeaderValue) { log.trace("checkOrigin: {}", originHeaderValue); return super.checkOrigin(originHeaderValue); }
@Override public void onOpen(Session session, EndpointConfig endpointConfig) { ServerEndpointConfig sec = (ServerEndpointConfig) endpointConfig; Object pojo; try { pojo = sec.getConfigurator().getEndpointInstance( sec.getEndpointClass()); } catch (InstantiationException e) { throw new IllegalArgumentException(sm.getString( "pojoEndpointServer.getPojoInstanceFail", sec.getEndpointClass().getName()), e); } setPojo(pojo); @SuppressWarnings("unchecked") Map<String,String> pathParameters = (Map<String, String>) sec.getUserProperties().get( POJO_PATH_PARAM_KEY); setPathParameters(pathParameters); PojoMethodMapping methodMapping = (PojoMethodMapping) sec.getUserProperties().get( POJO_METHOD_MAPPING_KEY); setMethodMapping(methodMapping); doOnOpen(session, endpointConfig); } }
@Override public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { sec.getUserProperties().put(HANDSHAKE_REQUEST, request); super.modifyHandshake(sec, request, response); }
if (!sec.getConfigurator().checkOrigin(origin)) { resp.sendError(HttpServletResponse.SC_FORBIDDEN); return; subProtocol = sec.getConfigurator().getNegotiatedSubprotocol( sec.getSubprotocols(), subProtocols); installedExtensions.addAll(Constants.INSTALLED_EXTENSIONS); List<Extension> negotiatedExtensionsPhase1 = sec.getConfigurator().getNegotiatedExtensions( installedExtensions, extensionsRequested); WsPerSessionServerEndpointConfig perSessionServerEndpointConfig = new WsPerSessionServerEndpointConfig(sec); sec.getConfigurator().modifyHandshake(perSessionServerEndpointConfig, wsRequest, wsResponse); wsRequest.finished(); Class<?> clazz = sec.getEndpointClass(); if (Endpoint.class.isAssignableFrom(clazz)) { ep = (Endpoint) sec.getConfigurator().getEndpointInstance( clazz); } else {
Map<String, Object> userProperties = config.getUserProperties(); userProperties.put(PROP_LOCAL_ADDRESS,req.getLocalSocketAddress()); userProperties.put(PROP_REMOTE_ADDRESS,req.getRemoteSocketAddress()); ServerEndpointConfig.Configurator configurator = config.getConfigurator(); if (!configurator.checkOrigin(req.getOrigin())) List<String> supported = config.getSubprotocols(); List<String> requested = req.getSubProtocols(); String subprotocol = configurator.getNegotiatedSubprotocol(supported,requested); if (StringUtil.isNotBlank(subprotocol)) List<Extension> usedExtensions = configurator.getNegotiatedExtensions(installedExtensions,requestedExts); List<ExtensionConfig> configs = new ArrayList<>(); if (usedExtensions != null) configurator.modifyHandshake(config,jsrHandshakeRequest,jsrHandshakeResponse); Class<?> endpointClass = config.getEndpointClass(); Object endpoint = config.getConfigurator().getEndpointInstance(endpointClass);
if (!sec.getConfigurator().checkOrigin(origin)) { resp.sendError(HttpServletResponse.SC_FORBIDDEN); return; "Sec-WebSocket-Protocol"); if (!subProtocols.isEmpty()) { subProtocol = sec.getConfigurator(). getNegotiatedSubprotocol( sec.getSubprotocols(), subProtocols); Class<?> clazz = sec.getEndpointClass(); if (Endpoint.class.isAssignableFrom(clazz)) { ep = (Endpoint) sec.getConfigurator().getEndpointInstance( clazz); } else { WsPerSessionServerEndpointConfig perSessionServerEndpointConfig = new WsPerSessionServerEndpointConfig(sec); sec.getConfigurator().modifyHandshake(perSessionServerEndpointConfig, wsRequest, wsResponse); wsRequest.finished();
@Override public <T> Object getEndpointInstance(Class<T> endpointClass) throws InstantiationException { return ((ServerEndpointConfig) configuration).getConfigurator() .getEndpointInstance(endpointClass); } };
/** * Server-side; Get the negotiated extensions' names based on the extensions supported by client. * * @param clientExtensions names of the extensions' supported by client. * @return names of extensions supported by both client and class that implements this one. */ List<Extension> getNegotiatedExtensions(List<Extension> clientExtensions) { if (configuration instanceof ServerEndpointConfig) { return configurator .getNegotiatedExtensions(((ServerEndpointConfig) configuration).getExtensions(), clientExtensions); } else { return Collections.emptyList(); } }
/** * Server-side; Compute the sub-protocol which will be used. * * @param clientProtocols sub-protocols supported by client. * @return negotiated sub-protocol, {@code null} if none found. */ String getNegotiatedProtocol(List<String> clientProtocols) { if (configuration instanceof ServerEndpointConfig) { return configurator.getNegotiatedSubprotocol(((ServerEndpointConfig) configuration).getSubprotocols(), clientProtocols); } else { return null; } }
@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); }
@Override public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { super.modifyHandshake(this, request, response); }
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); } }
@Override public List<Extension> getNegotiatedExtensions(List<Extension> installed, List<Extension> requested) { log.trace("negotiatedExtensions: installed={}, requested={}", installed, requested); // TODO: its not common to need to negotiate these outside of the container // but we could eventually expose them in the WebSocketHandshake as in getNegotiatedSubprotocol return super.getNegotiatedExtensions(installed, requested); }
@Override public List<Extension> getNegotiatedExtensions(List<Extension> installed, List<Extension> requested) { return delegate.getNegotiatedExtensions(installed, requested); }
@Override public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException { return configurator.getEndpointInstance(endpointClass); } };
@Override public String getNegotiatedSubprotocol(List<String> supported, List<String> requested) { return delegate.getNegotiatedSubprotocol(supported, requested); }
@Override public boolean checkOrigin(String originHeaderValue) { return delegate.checkOrigin(originHeaderValue); }
ServerEndpointConfig.Configurator getContainerDefaultConfigurator() { if (this.containerDefaultConfigurator == null) { this.containerDefaultConfigurator = fetchContainerDefaultConfigurator(); } return this.containerDefaultConfigurator; }