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);
}
}
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;
}
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);
}
}
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);
}
}
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);
}
}
Aggregations