use of org.eclipse.jetty.websocket.servlet.WebSocketCreator in project jetty.project by eclipse.
the class NativeWebSocketConfiguration method removeMapping.
@Override
public boolean removeMapping(String rawspec) {
PathSpec pathSpec = toPathSpec(rawspec);
boolean removed = false;
for (Iterator<MappedResource<WebSocketCreator>> iterator = mappings.iterator(); iterator.hasNext(); ) {
MappedResource<WebSocketCreator> mapping = iterator.next();
if (mapping.getPathSpec().equals(pathSpec)) {
iterator.remove();
removed = true;
}
}
return removed;
}
use of org.eclipse.jetty.websocket.servlet.WebSocketCreator in project jetty.project by eclipse.
the class WebSocketUpgradeHandlerWrapper method handle.
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
if (configuration.getFactory().isUpgradeRequest(request, response)) {
MappedResource<WebSocketCreator> resource = configuration.getMatch(target);
if (resource == null) {
// no match.
response.sendError(HttpServletResponse.SC_NOT_FOUND, "No websocket endpoint matching path: " + target);
return;
}
WebSocketCreator creator = resource.getResource();
// Store PathSpec resource mapping as request attribute
request.setAttribute(PathSpec.class.getName(), resource);
// We have an upgrade request
if (configuration.getFactory().acceptWebSocket(creator, request, response)) {
// We have a socket instance created
return;
}
// due to incoming request constraints (controlled by WebSocketCreator)
if (response.isCommitted()) {
// not much we can do at this point.
return;
}
}
super.handle(target, baseRequest, request, response);
}
use of org.eclipse.jetty.websocket.servlet.WebSocketCreator 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);
}
}
}
Aggregations