当前位置: 首页>>代码示例>>Java>>正文


Java WebSocketServlet类代码示例

本文整理汇总了Java中org.eclipse.jetty.websocket.WebSocketServlet的典型用法代码示例。如果您正苦于以下问题:Java WebSocketServlet类的具体用法?Java WebSocketServlet怎么用?Java WebSocketServlet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WebSocketServlet类属于org.eclipse.jetty.websocket包,在下文中一共展示了WebSocketServlet类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import org.eclipse.jetty.websocket.WebSocketServlet; //导入依赖的package包/类
public void start() throws Exception
{
  server = new Server();
  Connector connector = new SelectChannelConnector();
  connector.setPort(port);
  server.addConnector(connector);

    // Setup the basic application "context" for this application at "/"
  // This is also known as the handler tree (in jetty speak)
  ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
  contextHandler.setContextPath("/");
  server.setHandler(contextHandler);
  WebSocketServlet webSocketServlet = new WebSocketServlet()
  {
    @Override
    public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol)
    {
      return websocket;
    }
  };

  contextHandler.addServlet(new ServletHolder(webSocketServlet), "/pubsub");
  server.start();
  if (port == 0) {
    port = server.getConnectors()[0].getLocalPort();
  }
}
 
开发者ID:apache,项目名称:apex-core,代码行数:28,代码来源:StramTestSupport.java

示例2: _start

import org.eclipse.jetty.websocket.WebSocketServlet; //导入依赖的package包/类
@Override
protected void _start(Task onCompleted) {
    synchronized (this) {

        setJettyLog();

        introspectParameters();

        acceptDispatchQueue = dispatchQueue.createQueue("accept: " + uri);

        try {
            final String prefix = computePrefix();
            final String scheme = uri.getScheme();
            final String host = uri.getHost();
            final int port = resolvePort(scheme, uri.getPort());
            final Map<String, String> options = URISupport.parseParamters(uri);

            this.connector = resolveConnector(scheme, options);

            this.connector.setHost(host);
            this.connector.setPort(port);

            ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.NO_SECURITY);
            contextHandler.setContextPath(prefix);

            if (corsOrigin != null && !corsOrigin.trim().isEmpty()) {
                EnumSet ALL = EnumSet.allOf(DispatcherType.class);
                Set<String> origins = resolveOrigins();
                contextHandler.addFilter(new FilterHolder(new AllowAnyOriginFilter(origins)), "/*", ALL);
            }

            contextHandler.addServlet(new ServletHolder(new WebSocketServlet() {

                @Override
                protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
                    resp.setContentType("application/json");
                    resp.getOutputStream().println("{}");
                }

                // this is what connects up the jetty websockets impl to our transports.. and jetty will make callbacks
                // to onMessage, onOpen, onClose, etc.
                @Override
                public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol) {
                    return new WebSocketTransport(WsTransportServer.this, request, protocol);
                }
            }), "/");

            this.server = new Server();
            this.server.setHandler(contextHandler);
            this.server.setConnectors(new Connector[]{ connector });
            this.server.setThreadPool(new ExecutorThreadPool((ExecutorService) blockingExecutor));
            this.server.start();

            onCompleted.run();


        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
}
 
开发者ID:christian-posta,项目名称:activemq-apollo-java-port,代码行数:63,代码来源:WsTransportServer.java


注:本文中的org.eclipse.jetty.websocket.WebSocketServlet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。