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

The following are top voted examples for showing how to use javax.websocket.server.ServerEndpointConfig.Configurator. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: OpenChatAlytics   File: ServerMain.java   View source code 7 votes vote down vote up
/**
 *
 * @param context the context to add the web socket endpoints to
 * @param rtEventResource The instance of the websocket endpoint to return
 * @throws DeploymentException
 */
private static void setWebSocketEndpoints(ServletContextHandler context,
                                          EventsResource rtEventResource)
        throws DeploymentException, ServletException {

    ServerContainer wsContainer = WebSocketServerContainerInitializer.configureContext(context);

    ServerEndpointConfig serverConfig =
            ServerEndpointConfig.Builder
                                .create(EventsResource.class, EventsResource.RT_EVENT_ENDPOINT)
                                .configurator(new Configurator() {
                                    @Override
                                    public <T> T getEndpointInstance(Class<T> endpointClass)
                                            throws InstantiationException {
                                        return endpointClass.cast(rtEventResource);
                                    }
                                }).build();

    wsContainer.addEndpoint(serverConfig);
}
 
Example 2
Project: asity   File: JwaServerWebSocketTest.java   View source code 6 votes vote down vote up
@Override
protected void startServer(int port, final Action<ServerWebSocket> websocketAction) throws
  Exception {
  server = new Server();
  ServerConnector connector = new ServerConnector(server);
  connector.setPort(port);
  server.addConnector(connector);
  ServletContextHandler handler = new ServletContextHandler();
  server.setHandler(handler);
  ServerContainer container = WebSocketServerContainerInitializer.configureContext(handler);
  ServerEndpointConfig config = ServerEndpointConfig.Builder.create(AsityServerEndpoint.class,
    TEST_URI)
  .configurator(new Configurator() {
    @Override
    public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException {
      return endpointClass.cast(new AsityServerEndpoint().onwebsocket(websocketAction));
    }
  })
  .build();
  container.addEndpoint(config);
  server.start();
}
 
Example 3
Project: vibe-java-platform   File: JwaServerWebSocketTest.java   View source code 6 votes vote down vote up
@Override
protected void startServer() throws Exception {
    server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(port);
    server.addConnector(connector);
    ServletContextHandler handler = new ServletContextHandler();
    server.setHandler(handler);
    ServerContainer container = WebSocketServerContainerInitializer.configureContext(handler);
    ServerEndpointConfig config = ServerEndpointConfig.Builder.create(VibeServerEndpoint.class, "/test")
    .configurator(new Configurator() {
        @Override
        public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException {
            return endpointClass.cast(new VibeServerEndpoint().onwebsocket(performer.serverAction()));
        }
    })
    .build();
    container.addEndpoint(config);
    server.start();
}
 
Example 4
Project: minijax   File: MinijaxWebSocketUtils.java   View source code 5 votes vote down vote up
public static void init(final ServletContextHandler context, final MinijaxApplication application)
        throws ServletException, DeploymentException {

    final ServerContainer container = WebSocketServerContainerInitializer.configureContext(context);
    final Configurator configurator = new MinijaxWebSocketConfigurator(application);

    for (final Class<?> c : application.getWebSockets()) {
        final ServerEndpointConfig config = ServerEndpointConfig.Builder
                .create(c, c.getAnnotation(ServerEndpoint.class).value())
                .configurator(configurator)
                .build();
        container.addEndpoint(config);
    }
}