Search in sources :

Example 11 with WebSocketCreator

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;
}
Also used : WebSocketCreator(org.eclipse.jetty.websocket.servlet.WebSocketCreator) RegexPathSpec(org.eclipse.jetty.http.pathmap.RegexPathSpec) ServletPathSpec(org.eclipse.jetty.http.pathmap.ServletPathSpec) UriTemplatePathSpec(org.eclipse.jetty.http.pathmap.UriTemplatePathSpec) PathSpec(org.eclipse.jetty.http.pathmap.PathSpec) MappedResource(org.eclipse.jetty.http.pathmap.MappedResource)

Example 12 with WebSocketCreator

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);
}
Also used : WebSocketCreator(org.eclipse.jetty.websocket.servlet.WebSocketCreator) PathSpec(org.eclipse.jetty.http.pathmap.PathSpec)

Example 13 with WebSocketCreator

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);
        }
    }
}
Also used : WebSocketServerFactory(org.eclipse.jetty.websocket.server.WebSocketServerFactory) WebSocketCreator(org.eclipse.jetty.websocket.servlet.WebSocketCreator) ServletUpgradeRequest(org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest) ServletUpgradeResponse(org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse)

Aggregations

WebSocketCreator (org.eclipse.jetty.websocket.servlet.WebSocketCreator)13 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 PathSpec (org.eclipse.jetty.http.pathmap.PathSpec)3 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)3 WebSocketUpgradeFilter (org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter)3 ServletUpgradeRequest (org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest)3 ServletUpgradeResponse (org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse)3 WebSocketServletFactory (org.eclipse.jetty.websocket.servlet.WebSocketServletFactory)3 Server (org.eclipse.jetty.server.Server)2 WebSocketServerFactory (org.eclipse.jetty.websocket.server.WebSocketServerFactory)2 PathMappings (org.eclipse.jetty.websocket.server.pathmap.PathMappings)2 PathSpec (org.eclipse.jetty.websocket.server.pathmap.PathSpec)2 WebSocketServlet (org.eclipse.jetty.websocket.servlet.WebSocketServlet)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 InstrumentedQueuedThreadPool (com.codahale.metrics.jetty9.InstrumentedQueuedThreadPool)1 BuckEventExternalInterface (com.facebook.buck.event.external.events.BuckEventExternalInterface)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Maps (com.google.common.collect.Maps)1 InstrumentedHandler (com.kixeye.chassis.transport.http.InstrumentedHandler)1