Java Code Examples for javax.websocket.server.ServerEndpointConfig#Configurator

The following examples show how to use javax.websocket.server.ServerEndpointConfig#Configurator . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HandshakeUtil.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
/**
 * Prepare for upgrade
 */
public static void prepareUpgrade(final ServerEndpointConfig config, final WebSocketHttpExchange exchange) {
    ExchangeHandshakeRequest request = new ExchangeHandshakeRequest(exchange);
    ExchangeHandshakeResponse response = new ExchangeHandshakeResponse(exchange);
    ServerEndpointConfig.Configurator c = config.getConfigurator();
    c.modifyHandshake(config, request, response);
    response.update();
}
 
Example 2
Source File: RpcWebInitializer.java    From Brutusin-RPC with Apache License 2.0 5 votes vote down vote up
private void initWebsocketRpcRuntime(final ServletContext ctx, final RpcSpringContext rpcCtx) {
    LOGGER.info("Starting Websocket RPC runtime");
    ServerEndpointConfig.Configurator cfg = new WebsocketEndpointConfigurator(ctx, rpcCtx);
    ServerEndpointConfig sec = ServerEndpointConfig.Builder.create(WebsocketEndpoint.class, RpcConfig.getInstance().getPath() + "/wskt").configurator(cfg).build();
    try {
        rpcCtx.getWebsocketContainer().addEndpoint(sec);
    } catch (DeploymentException ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 3
Source File: AngularBeansServletContextListener.java    From AngularBeans with GNU Lesser General Public License v3.0 5 votes vote down vote up
private ServerEndpointConfig.Configurator configuratorFor(final String prefix, final boolean isRaw) {
	return new ServerEndpointConfig.Configurator() {

		@Override
		public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException {
			try {
				return endpointClass.getConstructor(SockJsServer.class, String.class, String.class)
						.newInstance(sockJsServer, context.getContextPath(), prefix);
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}

		@Override
		public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request,
				HandshakeResponse response) {
			if (isRaw) {
				// We have no reliable key (like session id) to save
				// headers with for raw websocket requests
				return;
			}
			String path = request.getRequestURI().getPath();
			Matcher matcher = SESSION_PATTERN.matcher(path);
			if (matcher.matches()) {
				String sessionId = matcher.group(1);
				saveHeaders(sessionId, request.getHeaders());
			}
		}
	};
}
 
Example 4
Source File: SockJsServlet.java    From AngularBeans with GNU Lesser General Public License v3.0 5 votes vote down vote up
private ServerEndpointConfig.Configurator configuratorFor(final String prefix, final boolean isRaw) {
	return new ServerEndpointConfig.Configurator() {

		@Override
		public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException {
			try {
				return endpointClass.getConstructor(SockJsServer.class, String.class, String.class)
						.newInstance(sockJsServer, getServletContext().getContextPath(), prefix);
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}

		@Override
		public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request,
				HandshakeResponse response) {

			if (isRaw) {
				// We have no reliable key (like session id) to save
				// headers with for raw websocket requests
				return;
			}

			String path = request.getRequestURI().getPath();
			Matcher matcher = SESSION_PATTERN.matcher(path);
			if (matcher.matches()) {
				String sessionId = matcher.group(1);
				saveHeaders(sessionId, request.getHeaders());
			}
		}
	};
}
 
Example 5
Source File: HandshakeUtil.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
/**
 * Checks the orgin against the
 */
public static boolean checkOrigin(ServerEndpointConfig config, WebSocketHttpExchange exchange) {
    ServerEndpointConfig.Configurator c = config.getConfigurator();
    return c.checkOrigin(exchange.getRequestHeader(HttpHeaderNames.ORIGIN));
}
 
Example 6
Source File: FHIRNotificationServiceEndpointConfig.java    From FHIR with Apache License 2.0 4 votes vote down vote up
@Override
public Configurator getConfigurator() {
    return new ServerEndpointConfig.Configurator();
}
 
Example 7
Source File: WebsocketBundle.java    From dropwizard-websockets with MIT License 4 votes vote down vote up
public WebsocketBundle(ServerEndpointConfig.Configurator defaultConfigurator, Class<?>... endpoints) {
    this(defaultConfigurator, Arrays.asList(endpoints), new ArrayList<>());
}
 
Example 8
Source File: WebsocketBundle.java    From dropwizard-websockets with MIT License 4 votes vote down vote up
public WebsocketBundle(ServerEndpointConfig.Configurator defaultConfigurator, Collection<Class<?>> endpointClasses, Collection<ServerEndpointConfig> serverEndpointConfigs) {
    this.defaultConfigurator = defaultConfigurator;
    endpointClasses.forEach((clazz)-> addEndpoint(clazz));
    this.endpointConfigs.addAll(serverEndpointConfigs);
}
 
Example 9
Source File: DefaultServerEndpointConfig.java    From ameba with MIT License 4 votes vote down vote up
/**
 * <p>Constructor for DefaultServerEndpointConfig.</p>
 *
 * @param manager a manager
 * @param endpointClass  a {@link java.lang.Class} endpoint class.
 * @param webSocketConf  a {@link ameba.websocket.WebSocket} object.
 */
public DefaultServerEndpointConfig(final InjectionManager manager,
                                   Class endpointClass,
                                   final WebSocket webSocketConf) {
    path = webSocketConf.path();
    subprotocols = Arrays.asList(webSocketConf.subprotocols());
    encoders = Lists.newArrayList(webSocketConf.encoders());
    decoders = Lists.newArrayList(webSocketConf.decoders());
    for (Class<? extends Extension> extensionClass : webSocketConf.extensions()) {
        extensions.add(Injections.getOrCreate(manager, extensionClass));
    }
    final WebSocketEndpointProvider provider = manager.getInstance(WebSocketEndpointProvider.class);

    final EndpointMeta endpointMeta = provider.parseMeta(endpointClass, webSocketConf);

    final ServerEndpointConfig.Configurator cfgr =
            Injections.getOrCreate(manager, webSocketConf.configurator());
    serverEndpointConfigurator = new ServerEndpointConfig.Configurator() {

        @Override
        public String getNegotiatedSubprotocol(List<String> supported, List<String> requested) {
            return cfgr.getNegotiatedSubprotocol(supported, requested);
        }

        @Override
        public List<Extension> getNegotiatedExtensions(List<Extension> installed, List<Extension> requested) {
            return cfgr.getNegotiatedExtensions(installed, requested);
        }

        @Override
        public boolean checkOrigin(String originHeaderValue) {
            return cfgr.checkOrigin(originHeaderValue);
        }

        @Override
        public void modifyHandshake(ServerEndpointConfig sec,
                                    HandshakeRequest request, HandshakeResponse response) {
            cfgr.modifyHandshake(sec, request, response);
        }

        @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);
        }
    };
}
 
Example 10
Source File: DefaultServerEndpointConfig.java    From ameba with MIT License 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public ServerEndpointConfig.Configurator getConfigurator() {
    return serverEndpointConfigurator;
}
 
Example 11
Source File: AppConfig.java    From jetty-web-sockets-jsr356 with Apache License 2.0 4 votes vote down vote up
@Bean
public ServerEndpointConfig.Configurator configurator() {
	return new SpringServerEndpointConfigurator();
}