Search in sources :

Example 1 with ServerContainer

use of jakarta.websocket.server.ServerContainer in project spring-framework by spring-projects.

the class ServerEndpointExporter method registerEndpoint.

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);
    }
}
Also used : DeploymentException(jakarta.websocket.DeploymentException) ServerContainer(jakarta.websocket.server.ServerContainer)

Example 2 with ServerContainer

use of jakarta.websocket.server.ServerContainer in project spring-framework by spring-projects.

the class AbstractStandardUpgradeStrategy method getContainer.

protected ServerContainer getContainer(HttpServletRequest request) {
    ServletContext servletContext = request.getServletContext();
    String attrName = "jakarta.websocket.server.ServerContainer";
    ServerContainer container = (ServerContainer) servletContext.getAttribute(attrName);
    Assert.notNull(container, "No 'jakarta.websocket.server.ServerContainer' ServletContext attribute. " + "Are you running in a Servlet container that supports JSR-356?");
    return container;
}
Also used : ServletContext(jakarta.servlet.ServletContext) ServerContainer(jakarta.websocket.server.ServerContainer)

Example 3 with ServerContainer

use of jakarta.websocket.server.ServerContainer in project spring-framework by spring-projects.

the class ServerEndpointExporter method registerEndpoint.

private void registerEndpoint(ServerEndpointConfig endpointConfig) {
    ServerContainer serverContainer = getServerContainer();
    Assert.state(serverContainer != null, "No ServerContainer set");
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("Registering ServerEndpointConfig: " + endpointConfig);
        }
        serverContainer.addEndpoint(endpointConfig);
    } catch (DeploymentException ex) {
        throw new IllegalStateException("Failed to register ServerEndpointConfig: " + endpointConfig, ex);
    }
}
Also used : DeploymentException(jakarta.websocket.DeploymentException) ServerContainer(jakarta.websocket.server.ServerContainer)

Example 4 with ServerContainer

use of jakarta.websocket.server.ServerContainer in project spring-framework by spring-projects.

the class WebSphereRequestUpgradeStrategy method upgradeInternal.

@Override
public void upgradeInternal(ServerHttpRequest httpRequest, ServerHttpResponse httpResponse, @Nullable String selectedProtocol, List<Extension> selectedExtensions, Endpoint endpoint) throws HandshakeFailureException {
    HttpServletRequest request = getHttpServletRequest(httpRequest);
    HttpServletResponse response = getHttpServletResponse(httpResponse);
    StringBuffer requestUrl = request.getRequestURL();
    // shouldn't matter
    String path = request.getRequestURI();
    Map<String, String> pathParams = Collections.<String, String>emptyMap();
    ServerEndpointRegistration endpointConfig = new ServerEndpointRegistration(path, endpoint);
    endpointConfig.setSubprotocols(Collections.singletonList(selectedProtocol));
    endpointConfig.setExtensions(selectedExtensions);
    try {
        ServerContainer container = getContainer(request);
        upgradeMethod.invoke(container, request, response, endpointConfig, pathParams);
    } catch (Exception ex) {
        throw new HandshakeFailureException("Servlet request failed to upgrade to WebSocket for " + requestUrl, ex);
    }
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) HandshakeFailureException(org.springframework.web.socket.server.HandshakeFailureException) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) HandshakeFailureException(org.springframework.web.socket.server.HandshakeFailureException) ServerContainer(jakarta.websocket.server.ServerContainer)

Example 5 with ServerContainer

use of jakarta.websocket.server.ServerContainer in project tomcat by apache.

the class TesterEndpointConfig method contextInitialized.

@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);
    }
}
Also used : ServerEndpointConfig(jakarta.websocket.server.ServerEndpointConfig) DeploymentException(jakarta.websocket.DeploymentException) ServerContainer(jakarta.websocket.server.ServerContainer)

Aggregations

ServerContainer (jakarta.websocket.server.ServerContainer)5 DeploymentException (jakarta.websocket.DeploymentException)3 ServletContext (jakarta.servlet.ServletContext)1 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)1 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)1 ServerEndpointConfig (jakarta.websocket.server.ServerEndpointConfig)1 HandshakeFailureException (org.springframework.web.socket.server.HandshakeFailureException)1