javax.websocket.server.ServerContainer#addEndpoint ( )源码实例Demo

下面列出了javax.websocket.server.ServerContainer#addEndpoint ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Tomcat8-Source-Read   文件: TesterEchoServer.java
@Override
public void contextInitialized(ServletContextEvent sce) {
    super.contextInitialized(sce);
    ServerContainer sc =
            (ServerContainer) sce.getServletContext().getAttribute(
                    Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE);
    try {
        sc.addEndpoint(Async.class);
        sc.addEndpoint(Basic.class);
        sc.addEndpoint(BasicLimitLow.class);
        sc.addEndpoint(BasicLimitHigh.class);
        sc.addEndpoint(WriterError.class);
        sc.addEndpoint(RootEcho.class);
    } catch (DeploymentException e) {
        throw new IllegalStateException(e);
    }
}
 
@Override
public void contextInitialized(ServletContextEvent sce) {
    super.contextInitialized(sce);

    ServerContainer sc = (ServerContainer) sce.getServletContext().getAttribute(
            Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE);

    try {
        ServerEndpointConfig sec = getServerEndpointConfig();
        if (sec == null) {
            sc.addEndpoint(getEndpointClass());
        } else {
            sc.addEndpoint(sec);
        }
    } catch (DeploymentException e) {
        throw new RuntimeException(e);
    }
}
 
源代码3 项目: Tomcat8-Source-Read   文件: TestCloseBug58624.java
@Override
public void contextInitialized(ServletContextEvent sce) {
    super.contextInitialized(sce);

    ServerContainer sc = (ServerContainer) sce.getServletContext().getAttribute(
            Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE);

    ServerEndpointConfig sec = ServerEndpointConfig.Builder.create(
            Bug58624ServerEndpoint.class, PATH).build();

    try {
        sc.addEndpoint(sec);
    } catch (DeploymentException e) {
        throw new RuntimeException(e);
    }
}
 
源代码4 项目: tomcatsrc   文件: TestCloseBug58624.java
@Override
public void contextInitialized(ServletContextEvent sce) {
    super.contextInitialized(sce);

    ServerContainer sc = (ServerContainer) sce.getServletContext().getAttribute(
            Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE);

    ServerEndpointConfig sec = ServerEndpointConfig.Builder.create(
            Bug58624ServerEndpoint.class, PATH).build();

    try {
        sc.addEndpoint(sec);
    } catch (DeploymentException e) {
        throw new RuntimeException(e);
    }
}
 
源代码5 项目: seed   文件: WebSocketListener.java
@Override
public void contextInitialized(ServletContextEvent sce) {
    ServerContainer container = (ServerContainer) sce.getServletContext().getAttribute(SERVER_CONTAINER);
    if (container != null) {
        for (Class<?> endpointClass : serverEndpointClasses) {
            try {
                LOGGER.debug("Publishing WebSocket server endpoint {}", endpointClass.getCanonicalName());
                container.addEndpoint(endpointClass);
            } catch (DeploymentException e) {
                throw SeedException.wrap(e, WebErrorCode.CANNOT_PUBLISH_WEBSOCKET_ENDPOINT)
                        .put("class", endpointClass);
            }
        }
    } else {
        LOGGER.info("No WebSocket implementation found, WebSocket support disabled");
    }
}
 
private void registerEndpoint(Class<?> endpointClass) {
	ServerContainer serverContainer = getServerContainer();
	Assert.state(serverContainer != null,
			"No ServerContainer set. Most likely the server's own WebSocket ServletContainerInitializer " +
			"has not run yet. Was the Spring ApplicationContext refreshed through a " +
			"org.springframework.web.context.ContextLoaderListener, " +
			"i.e. after the ServletContext has been fully initialized?");
	try {
		if (logger.isDebugEnabled()) {
			logger.debug("Registering @ServerEndpoint class: " + endpointClass);
		}
		serverContainer.addEndpoint(endpointClass);
	}
	catch (DeploymentException ex) {
		throw new IllegalStateException("Failed to register @ServerEndpoint class: " + endpointClass, ex);
	}
}
 
源代码7 项目: tomcatsrc   文件: TestWsServerContainer.java
@Override
public void contextInitialized(ServletContextEvent sce) {
    super.contextInitialized(sce);

    ServerContainer sc =
            (ServerContainer) sce.getServletContext().getAttribute(
                    Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE);

    ServerEndpointConfig sec = ServerEndpointConfig.Builder.create(
            TesterEchoServer.Basic.class, "/{param}").build();

    try {
        sc.addEndpoint(sec);
    } catch (DeploymentException e) {
        throw new RuntimeException(e);
    }
}
 
源代码8 项目: mdw   文件: StartupListener.java
@Override
public void contextInitialized(ServletContextEvent contextEvent) {
    ServletContext servletContext = contextEvent.getServletContext();
    mdwMain = new MdwMain();
    String container = "Tomcat"; // TODO
    if (ApplicationContext.isSpringBoot()) {
        ServerContainer serverContainer = (ServerContainer)servletContext.getAttribute("javax.websocket.server.ServerContainer");
        try {
            serverContainer.addEndpoint(WebSocketMessenger.class);
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
        mdwMain.startup(container, SpringBootApplication.getBootDir().toString(), servletContext.getContextPath());
    }
    else {
        mdwMain.startup(container, servletContext.getRealPath("/"), servletContext.getContextPath());
        new InitialRequest().submit();
    }
}
 
源代码9 项目: tomcatsrc   文件: TestClose.java
@Override
public void contextInitialized(ServletContextEvent sce) {
    super.contextInitialized(sce);

    ServerContainer sc = (ServerContainer) sce
            .getServletContext()
            .getAttribute(
                    Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE);

    ServerEndpointConfig sec = ServerEndpointConfig.Builder.create(
            getEndpointClass(), PATH).build();

    try {
        sc.addEndpoint(sec);
    } catch (DeploymentException e) {
        throw new RuntimeException(e);
    }
}
 
源代码10 项目: tomcatsrc   文件: TestWsRemoteEndpointImplServer.java
@Override
public void contextInitialized(ServletContextEvent sce) {
    super.contextInitialized(sce);

    ServerContainer sc = (ServerContainer) sce.getServletContext().getAttribute(
            Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE);

    List<Class<? extends Encoder>> encoders = new ArrayList<Class<? extends Encoder>>();
    encoders.add(Bug58624Encoder.class);
    ServerEndpointConfig sec = ServerEndpointConfig.Builder.create(
            Bug58624Endpoint.class, PATH).encoders(encoders).build();

    try {
        sc.addEndpoint(sec);
    } catch (DeploymentException e) {
        throw new RuntimeException(e);
    }
}
 
源代码11 项目: tomcatsrc   文件: TesterEchoServer.java
@Override
public void contextInitialized(ServletContextEvent sce) {
    super.contextInitialized(sce);
    ServerContainer sc =
            (ServerContainer) sce.getServletContext().getAttribute(
                    Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE);
    try {
        sc.addEndpoint(Async.class);
        sc.addEndpoint(Basic.class);
        sc.addEndpoint(BasicLimitLow.class);
        sc.addEndpoint(BasicLimitHigh.class);
        sc.addEndpoint(RootEcho.class);
    } catch (DeploymentException e) {
        throw new IllegalStateException(e);
    }
}
 
@Override
public void contextInitialized(ServletContextEvent sce) {
    super.contextInitialized(sce);

    ServerContainer sc = (ServerContainer) sce.getServletContext().getAttribute(
            Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE);

    List<Class<? extends Encoder>> encoders = new ArrayList<Class<? extends Encoder>>();
    encoders.add(Bug58624Encoder.class);
    ServerEndpointConfig sec = ServerEndpointConfig.Builder.create(
            Bug58624Endpoint.class, PATH).encoders(encoders).build();

    try {
        sc.addEndpoint(sec);
    } catch (DeploymentException e) {
        throw new RuntimeException(e);
    }
}
 
源代码13 项目: quarks   文件: WebSocketServerEcho.java
public void start(URI endpointURI, boolean needClientAuth) {
    curEndpointURI = endpointURI;
    curNeedClientAuth = needClientAuth;

    System.out.println(svrName+" "+endpointURI + " needClientAuth="+needClientAuth);

    server = createServer(endpointURI, needClientAuth);
    connector = (ServerConnector)server.getConnectors()[0];

    // Setup the basic application "context" for this application at "/"
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    server.setHandler(context);
    
    try {
        // Initialize javax.websocket layer
        ServerContainer wscontainer = WebSocketServerContainerInitializer.configureContext(context);

        // Add WebSocket endpoint to javax.websocket layer
        wscontainer.addEndpoint(this.getClass());

        // System.setProperty("javax.net.debug", "ssl"); // or "all"; "help" for full list

        server.start();
        System.out.println(svrName+" started "+connector);
        // server.dump(System.err);            
    }
    catch (Exception e) {
        throw new RuntimeException("start", e);
    }
}
 
源代码14 项目: product-cep   文件: WebSocketServer.java
public void start(int port, String host) {
    server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(port);
    connector.setHost(host);
    server.addConnector(connector);

    // Setup the basic application "context" for this application at "/"
    // This is also known as the handler tree (in jetty speak)
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    server.setHandler(context);

    try {
        // Initialize javax.websocket layer
        ServerContainer wscontainer = WebSocketServerContainerInitializer.configureContext(context);

        // Add WebSocket endpoint to javax.websocket layer
        wscontainer.addEndpoint(EventSocket.class);

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    server.start();
                    server.join();
                } catch (Exception e) {
                    log.error(e);
                }
            }
        }).start();

    } catch (Throwable t) {
        log.error(t);
    }
}
 
源代码15 项目: zeppelin   文件: TerminalThread.java
public void run() {
  ServerConnector connector = new ServerConnector(jettyServer);
  connector.setPort(port);
  jettyServer.addConnector(connector);

  ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
  context.setContextPath("/terminal/");

  // We look for a file, as ClassLoader.getResource() is not
  // designed to look for directories (we resolve the directory later)
  ClassLoader clazz = TerminalThread.class.getClassLoader();
  URL url = clazz.getResource("html");
  if (url == null) {
    throw new RuntimeException("Unable to find resource directory");
  }

  ResourceHandler resourceHandler = new ResourceHandler();
  // Resolve file to directory
  String webRootUri = url.toExternalForm();
  LOGGER.info("WebRoot is " + webRootUri);
  // debug
  // webRootUri = "/home/hadoop/zeppelin-current/interpreter/sh";
  resourceHandler.setResourceBase(webRootUri);

  HandlerCollection handlers = new HandlerCollection(context, resourceHandler);
  jettyServer.setHandler(handlers);

  try {
    ServerContainer container = WebSocketServerContainerInitializer.configureContext(context);
    container.addEndpoint(TerminalSocket.class);
    jettyServer.start();
    jettyServer.join();
  } catch (Exception e) {
    LOGGER.error(e.getMessage(), e);
  }
}
 
@Override
public void contextInitialized(ServletContextEvent sce) {
	ServletContext container = sce.getServletContext();

	final ServerContainer serverContainer = (ServerContainer) container
			.getAttribute(SERVER_CONTAINER_ATTRIBUTE);
	try {
		serverContainer.addEndpoint(new WicketServerEndpointConfig());
	} catch (DeploymentException e) {
		throw new WicketSpringBootException(e);
	}
}
 
源代码17 项目: quarkus-http   文件: AddEndpointServlet.java
@Override
public void init(ServletConfig c) throws ServletException {
    String websocketPath = "/foo";
    ServerEndpointConfig config = ServerEndpointConfig.Builder.create(ProgramaticEndpoint.class, websocketPath).build();
    ServerContainer serverContainer = (ServerContainer) c.getServletContext().getAttribute("javax.websocket.server.ServerContainer");
    try {
        serverContainer.addEndpoint(config);
    } catch (DeploymentException ex) {
        throw new ServletException("Error deploying websocket endpoint:", ex);
    }
}
 
源代码18 项目: tomcatsrc   文件: TestWsSubprotocols.java
@Override
public void contextInitialized(ServletContextEvent sce) {
    super.contextInitialized(sce);
    ServerContainer sc = (ServerContainer) sce.getServletContext()
            .getAttribute(Constants.
                    SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE);
    try {
        sc.addEndpoint(SubProtocolsEndpoint.class);
    } catch (DeploymentException e) {
        throw new IllegalStateException(e);
    }
}
 
源代码19 项目: Tomcat8-Source-Read   文件: TestEncodingDecoding.java
@Override
public void contextInitialized(ServletContextEvent sce) {
    super.contextInitialized(sce);
    ServerContainer sc =
            (ServerContainer) sce.getServletContext().getAttribute(
                    org.apache.tomcat.websocket.server.Constants.
                    SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE);
    try {
        sc.addEndpoint(new ServerEndpointConfig() {
            @Override
            public Map<String, Object> getUserProperties() {
                return Collections.emptyMap();
            }
            @Override
            public List<Class<? extends Encoder>> getEncoders() {
                List<Class<? extends Encoder>> encoders = new ArrayList<>(2);
                encoders.add(MsgStringEncoder.class);
                encoders.add(MsgByteEncoder.class);
                return encoders;
            }
            @Override
            public List<Class<? extends Decoder>> getDecoders() {
                List<Class<? extends Decoder>> decoders = new ArrayList<>(2);
                decoders.add(MsgStringDecoder.class);
                decoders.add(MsgByteDecoder.class);
                return decoders;
            }
            @Override
            public List<String> getSubprotocols() {
                return Collections.emptyList();
            }
            @Override
            public String getPath() {
                return PATH_PROGRAMMATIC_EP;
            }
            @Override
            public List<Extension> getExtensions() {
                return Collections.emptyList();
            }
            @Override
            public Class<?> getEndpointClass() {
                return ProgrammaticEndpoint.class;
            }
            @Override
            public Configurator getConfigurator() {
                return new ServerEndpointConfig.Configurator() {
                };
            }
        });
    } catch (DeploymentException e) {
        throw new IllegalStateException(e);
    }
}
 
源代码20 项目: Tomcat7.0.67   文件: TestEncodingDecoding.java
@Override
public void contextInitialized(ServletContextEvent sce) {
    super.contextInitialized(sce);
    ServerContainer sc =
            (ServerContainer) sce.getServletContext().getAttribute(
                    org.apache.tomcat.websocket.server.Constants.
                    SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE);
    try {
        sc.addEndpoint(new ServerEndpointConfig() {
            @Override
            public Map<String, Object> getUserProperties() {
                return Collections.emptyMap();
            }
            @Override
            public List<Class<? extends Encoder>> getEncoders() {
                List<Class<? extends Encoder>> encoders = new ArrayList<Class<? extends Encoder>>(2);
                encoders.add(MsgStringEncoder.class);
                encoders.add(MsgByteEncoder.class);
                return encoders;
            }
            @Override
            public List<Class<? extends Decoder>> getDecoders() {
                List<Class<? extends Decoder>> decoders = new ArrayList<Class<? extends Decoder>>(2);
                decoders.add(MsgStringDecoder.class);
                decoders.add(MsgByteDecoder.class);
                return decoders;
            }
            @Override
            public List<String> getSubprotocols() {
                return Collections.emptyList();
            }
            @Override
            public String getPath() {
                return PATH_PROGRAMMATIC_EP;
            }
            @Override
            public List<Extension> getExtensions() {
                return Collections.emptyList();
            }
            @Override
            public Class<?> getEndpointClass() {
                return ProgrammaticEndpoint.class;
            }
            @Override
            public Configurator getConfigurator() {
                return new ServerEndpointConfig.Configurator() {
                };
            }
        });
    } catch (DeploymentException e) {
        throw new IllegalStateException(e);
    }
}
 
 同类方法