org.apache.tomcat.websocket.server.WsServerContainer类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(502)

本文整理了Java中org.apache.tomcat.websocket.server.WsServerContainer类的一些代码示例,展示了WsServerContainer类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WsServerContainer类的具体详情如下:
包路径:org.apache.tomcat.websocket.server.WsServerContainer
类名称:WsServerContainer

WsServerContainer介绍

[英]Provides a per class loader (i.e. per web application) instance of a ServerContainer. Web application wide defaults may be configured by setting the following servlet context initialisation parameters to the desired values.

  • Constants#BINARY_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM
  • Constants#TEXT_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM
    [中]提供ServerContainer的每个类装入器(即每个web应用程序)实例。可以通过将以下servlet上下文初始化参数设置为所需值来配置Web应用程序范围的默认值。
    *常量#二进制_缓冲区_大小_SERVLET _上下文_初始化_参数
    *常量#文本_缓冲区_大小_SERVLET _上下文_初始化_参数

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
public void upgradeInternal(ServerHttpRequest request, ServerHttpResponse response,
    @Nullable String selectedProtocol, List<Extension> selectedExtensions, Endpoint endpoint)
    throws HandshakeFailureException {
  HttpServletRequest servletRequest = getHttpServletRequest(request);
  HttpServletResponse servletResponse = getHttpServletResponse(response);
  StringBuffer requestUrl = servletRequest.getRequestURL();
  String path = servletRequest.getRequestURI();  // shouldn't matter
  Map<String, String> pathParams = Collections.<String, String> emptyMap();
  ServerEndpointRegistration endpointConfig = new ServerEndpointRegistration(path, endpoint);
  endpointConfig.setSubprotocols(Collections.singletonList(selectedProtocol));
  endpointConfig.setExtensions(selectedExtensions);
  try {
    getContainer(servletRequest).doUpgrade(servletRequest, servletResponse, endpointConfig, pathParams);
  }
  catch (ServletException ex) {
    throw new HandshakeFailureException(
        "Servlet request failed to upgrade to WebSocket: " + requestUrl, ex);
  }
  catch (IOException ex) {
    throw new HandshakeFailureException(
        "Response update failed during upgrade to WebSocket: " + requestUrl, ex);
  }
}

代码示例来源:origin: org.apache.tomcat.embed/tomcat-embed-websocket

if (!sc.areEndpointsRegistered() ||
    !UpgradeUtil.isWebSocketUpgradeRequest(request, response)) {
  chain.doFilter(request, response);
  path = req.getServletPath() + pathInfo;
WsMappingResult mappingResult = sc.findMapping(path);

代码示例来源:origin: org.apache.tomcat/tomcat-websocket

validateEncoders(annotation.encoders());
    build();
addEndpoint(sec);

代码示例来源:origin: org.jboss.web/jbossweb

public WsRemoteEndpointImplServer(AbstractServletOutputStream sos,
    WsServerContainer serverContainer) {
  this.sos = sos;
  this.wsWriteTimeout = serverContainer.getTimeout();
  this.executorService = serverContainer.getExecutorService();
}

代码示例来源:origin: codefollower/Tomcat-Research

@Override
  public void contextDestroyed(ServletContextEvent sce) {
    ServletContext sc = sce.getServletContext();
    Object obj = sc.getAttribute(Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE);
    if (obj instanceof WsServerContainer) {
      ((WsServerContainer) obj).shutdownExecutor();
      ((WsServerContainer) obj).destroy();
    }
  }
}

代码示例来源:origin: codefollower/Tomcat-Research

@Override
  public void sessionDestroyed(HttpSessionEvent se) {
    wsServerContainer.closeAuthenticatedSession(se.getSession().getId());
  }
}

代码示例来源:origin: org.apache.tomcat.embed/tomcat-embed-websocket

static WsServerContainer init(ServletContext servletContext,
      boolean initBySciMechanism) {

    WsServerContainer sc = new WsServerContainer(servletContext);

    servletContext.setAttribute(
        Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE, sc);

    servletContext.addListener(new WsSessionListener(sc));
    // Can't register the ContextListener again if the ContextListener is
    // calling this method
    if (initBySciMechanism) {
      servletContext.addListener(new WsContextListener());
    }

    return sc;
  }
}

代码示例来源:origin: org.apache.tomcat.embed/tomcat-embed-websocket

/**
 * {@inheritDoc}
 *
 * Overridden to make it visible to other classes in this package.
 */
@Override
protected void registerSession(Endpoint endpoint, WsSession wsSession) {
  super.registerSession(endpoint, wsSession);
  if (wsSession.isOpen() &&
      wsSession.getUserPrincipal() != null &&
      wsSession.getHttpSessionId() != null) {
    registerAuthenticatedSession(wsSession,
        wsSession.getHttpSessionId());
  }
}

代码示例来源:origin: org.apache.tomcat.embed/tomcat-embed-websocket

webSocketContainer.registerSession(ep, wsSession);
} catch (DeploymentException e) {
  throw new IllegalArgumentException(e);

代码示例来源:origin: codefollower/Tomcat-Research

sc.addEndpoint(config);
sc.addEndpoint(clazz);

代码示例来源:origin: org.jboss.web/jbossweb

@Override
  public void contextDestroyed(ServletContextEvent sce) {
    ServletContext sc = sce.getServletContext();
    Object obj = sc.getAttribute(Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE);
    if (obj instanceof WsServerContainer) {
      ((WsServerContainer) obj).destroy();
    }
  }
}

代码示例来源:origin: org.apache.tomcat.embed/tomcat-embed-websocket

public WsRemoteEndpointImplServer(SocketWrapperBase<?> socketWrapper,
    WsServerContainer serverContainer) {
  this.socketWrapper = socketWrapper;
  this.wsWriteTimeout = serverContainer.getTimeout();
}

代码示例来源:origin: codefollower/Tomcat-Research

@Override
public void doFilter(ServletRequest request, ServletResponse response,
    FilterChain chain) throws IOException, ServletException {
  // This filter only needs to handle WebSocket upgrade requests
  if (!sc.areEndpointsRegistered() ||
      !UpgradeUtil.isWebSocketUpgradeRequest(request, response)) {
    chain.doFilter(request, response);
    return;
  }
  // HTTP request with an upgrade header for WebSocket present
  HttpServletRequest req = (HttpServletRequest) request;
  HttpServletResponse resp = (HttpServletResponse) response;
  // Check to see if this WebSocket implementation has a matching mapping
  String path;
  String pathInfo = req.getPathInfo();
  if (pathInfo == null) {
    path = req.getServletPath();
  } else {
    path = req.getServletPath() + pathInfo;
  }
  WsMappingResult mappingResult = sc.findMapping(path);
  if (mappingResult == null) {
    // No endpoint registered for the requested path. Let the
    // application handle it (it might redirect or forward for example)
    chain.doFilter(request, response);
    return;
  }
  UpgradeUtil.doUpgrade(sc, req, resp, mappingResult.getConfig(),
      mappingResult.getPathParams());
}

代码示例来源:origin: org.apache.tomcat.embed/tomcat-embed-websocket

validateEncoders(annotation.encoders());
    build();
addEndpoint(sec);

代码示例来源:origin: codefollower/Tomcat-Research

public WsRemoteEndpointImplServer(ServletOutputStream sos,
    WsServerContainer serverContainer) {
  this.sos = sos;
  this.wsWriteTimeout = serverContainer.getTimeout();
  this.executorService = serverContainer.getExecutorService();
}

代码示例来源:origin: org.apache.tomcat.embed/tomcat-embed-websocket

@Override
  public void sessionDestroyed(HttpSessionEvent se) {
    wsServerContainer.closeAuthenticatedSession(se.getSession().getId());
  }
}

代码示例来源:origin: org.apache.tomcat/tomcat7-websocket

static WsServerContainer init(ServletContext servletContext,
    boolean initBySciMechanism) {
  WsServerContainer sc = new WsServerContainer(servletContext);
  servletContext.setAttribute(
      Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE, sc);
  servletContext.addListener(new WsSessionListener(sc));
  // Can't register the ContextListener again if the ContextListener is
  // calling this method
  if (initBySciMechanism) {
    servletContext.addListener(new WsContextListener());
  }
  return sc;
}

代码示例来源:origin: org.apache.tomcat/tomcat7-websocket

/**
 * {@inheritDoc}
 *
 * Overridden to make it visible to other classes in this package.
 */
@Override
protected void registerSession(Endpoint endpoint, WsSession wsSession) {
  super.registerSession(endpoint, wsSession);
  if (wsSession.isOpen() &&
      wsSession.getUserPrincipal() != null &&
      wsSession.getHttpSessionId() != null) {
    registerAuthenticatedSession(wsSession,
        wsSession.getHttpSessionId());
  }
}

代码示例来源:origin: org.apache.tomcat/tomcat-websocket

webSocketContainer.registerSession(ep, wsSession);
} catch (DeploymentException e) {
  throw new IllegalArgumentException(e);

代码示例来源:origin: org.apache.tomcat/tomcat-websocket

sc.addEndpoint(config);
sc.addEndpoint(clazz);

相关文章