use of org.eclipse.jetty.websocket.server.WebSocketServerFactory in project spring-framework by spring-projects.
the class JettyRequestUpgradeStrategy method start.
@Override
public void start() {
synchronized (this.lifecycleMonitor) {
if (!isRunning() && this.servletContext != null) {
this.running = true;
try {
this.factory = new WebSocketServerFactory(this.servletContext);
this.factory.setCreator((request, response) -> {
WebSocketHandlerContainer container = adapterHolder.get();
String protocol = container.getProtocol().orElse(null);
if (protocol != null) {
response.setAcceptedSubProtocol(protocol);
}
return container.getAdapter();
});
this.factory.start();
} catch (Throwable ex) {
throw new IllegalStateException("Unable to start WebSocketServerFactory", ex);
}
}
}
}
use of org.eclipse.jetty.websocket.server.WebSocketServerFactory in project CQ-Actions by Cognifide.
the class MessageWebsocketServlet method activate.
@Activate
public void activate() throws Exception {
WebSocketBehavior behavior = WebSocketBehavior.SERVER;
WebSocketPolicy policy = new WebSocketPolicy(behavior);
webSocketFactory = new WebSocketServerFactory(policy);
webSocketFactory.register(MessageSocket.class);
webSocketFactory.setCreator(this);
webSocketFactory.start();
}
use of org.eclipse.jetty.websocket.server.WebSocketServerFactory in project spark by perwendel.
the class WebSocketServletContextHandlerFactoryTest method testCreate_whenTimeoutIsPresent.
@Test
public void testCreate_whenTimeoutIsPresent() throws Exception {
final Integer timeout = Integer.valueOf(1000);
Map<String, WebSocketHandlerWrapper> webSocketHandlers = new HashMap<>();
webSocketHandlers.put(webSocketPath, new WebSocketHandlerClassWrapper(WebSocketTestHandler.class));
servletContextHandler = WebSocketServletContextHandlerFactory.create(webSocketHandlers, Optional.of(timeout));
ServletContext servletContext = servletContextHandler.getServletContext();
WebSocketUpgradeFilter webSocketUpgradeFilter = (WebSocketUpgradeFilter) servletContext.getAttribute("org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter");
assertNotNull("Should return a WebSocketUpgradeFilter because we configured it to have one", webSocketUpgradeFilter);
NativeWebSocketConfiguration webSocketConfiguration = (NativeWebSocketConfiguration) servletContext.getAttribute(NativeWebSocketConfiguration.class.getName());
WebSocketServerFactory webSocketServerFactory = webSocketConfiguration.getFactory();
assertEquals("Timeout value should be the same as the timeout specified when context handler was created", timeout.longValue(), webSocketServerFactory.getPolicy().getIdleTimeout());
MappedResource<WebSocketCreator> mappedResource = webSocketConfiguration.getMatch("/websocket");
PathSpec pathSpec = mappedResource.getPathSpec();
assertEquals("Should return the WebSocket path specified when context handler was created", webSocketPath, pathSpec.getDeclaration());
// Because spark works on a non-initialized / non-started ServletContextHandler and WebSocketUpgradeFilter
// the stored WebSocketCreator is wrapped for persistence through the start/stop of those contexts.
// You cannot unwrap or cast to that WebSocketTestHandler this way.
// Only websockets that are added during a live context can be cast this way.
// WebSocketCreator sc = mappedResource.getResource();
// assertTrue("Should return true because handler should be an instance of the one we passed when it was created",
// sc.getHandler() instanceof WebSocketTestHandler);
}
use of org.eclipse.jetty.websocket.server.WebSocketServerFactory in project spring-framework by spring-projects.
the class JettyRequestUpgradeStrategy method start.
@Override
public void start() {
if (!isRunning()) {
this.running = true;
try {
if (this.factory == null) {
this.factory = new WebSocketServerFactory(servletContext, this.policy);
}
this.factory.setCreator(new WebSocketCreator() {
@Override
public Object createWebSocket(ServletUpgradeRequest request, ServletUpgradeResponse response) {
WebSocketHandlerContainer container = containerHolder.get();
Assert.state(container != null, "Expected WebSocketHandlerContainer");
response.setAcceptedSubProtocol(container.getSelectedProtocol());
response.setExtensions(container.getExtensionConfigs());
return container.getHandler();
}
});
this.factory.start();
} catch (Throwable ex) {
throw new IllegalStateException("Unable to start Jetty WebSocketServerFactory", ex);
}
}
}
use of org.eclipse.jetty.websocket.server.WebSocketServerFactory in project ma-core-public by infiniteautomation.
the class MangoWebSocketConfigurer method handshakeHandler.
@Bean
public DefaultHandshakeHandler handshakeHandler() {
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
policy.setInputBufferSize(8192);
// We don't want timeouts..
policy.setIdleTimeout(Integer.MAX_VALUE);
WebSocketServerFactory factory = new WebSocketServerFactory(policy);
return new DefaultHandshakeHandler(new JettyRequestUpgradeStrategy(factory));
}
Aggregations