Skip to content

Commit

Permalink
CreatorNegotiator should remain private, use from on WebSocketNegotiator
Browse files Browse the repository at this point in the history
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
  • Loading branch information
lachlan-roberts committed Jan 12, 2021
1 parent 0a944ac commit 78707ff
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.exception.WebSocketException;
import org.eclipse.jetty.websocket.core.server.internal.CreatorNegotiator;
import org.eclipse.jetty.websocket.core.server.internal.HandshakerSelector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -174,7 +175,7 @@ public WebSocketCreator getWebSocketCreator(PathSpec pathSpec)
*/
public void addMapping(PathSpec pathSpec, WebSocketCreator creator, FrameHandlerFactory factory, Configuration.Customizer customizer) throws WebSocketException
{
mappings.put(pathSpec, new CreatorNegotiator(creator, factory, customizer));
mappings.put(pathSpec, WebSocketNegotiator.from(creator, factory, customizer));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@

import org.eclipse.jetty.websocket.core.Configuration;
import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.server.internal.CreatorNegotiator;

public interface WebSocketNegotiator extends Configuration.Customizer
{
FrameHandler negotiate(WebSocketNegotiation negotiation) throws IOException;

@Override
default void customize(Configuration configurable)
{
}

static WebSocketNegotiator from(Function<WebSocketNegotiation, FrameHandler> negotiate)
{
return from(negotiate, null);
Expand All @@ -40,6 +46,16 @@ public FrameHandler negotiate(WebSocketNegotiation negotiation)
};
}

static WebSocketNegotiator from(WebSocketCreator creator, FrameHandlerFactory factory)
{
return from(creator, factory, null);
}

static WebSocketNegotiator from(WebSocketCreator creator, FrameHandlerFactory factory, Configuration.Customizer customizer)
{
return new CreatorNegotiator(creator, factory, customizer);
}

abstract class AbstractNegotiator extends Configuration.ConfigurationCustomizer implements WebSocketNegotiator
{
final Configuration.Customizer customizer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// ========================================================================
//

package org.eclipse.jetty.websocket.core.server;
package org.eclipse.jetty.websocket.core.server.internal;

import java.io.IOException;
import java.util.concurrent.atomic.AtomicReference;
Expand All @@ -20,6 +20,12 @@

import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.server.FrameHandlerFactory;
import org.eclipse.jetty.websocket.core.server.ServerUpgradeRequest;
import org.eclipse.jetty.websocket.core.server.ServerUpgradeResponse;
import org.eclipse.jetty.websocket.core.server.WebSocketCreator;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiation;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;

public class CreatorNegotiator extends WebSocketNegotiator.AbstractNegotiator
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.server.CreatorNegotiator;
import org.eclipse.jetty.websocket.core.server.FrameHandlerFactory;
import org.eclipse.jetty.websocket.core.server.Handshaker;
import org.eclipse.jetty.websocket.core.server.WebSocketCreator;
Expand Down Expand Up @@ -100,7 +99,7 @@ public void init(ServletConfig config) throws ServletException
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
WebSocketCreator creator = (req, resp) -> new EchoSocket();
WebSocketNegotiator negotiator = new CreatorNegotiator(creator, frameHandlerFactory);
WebSocketNegotiator negotiator = WebSocketNegotiator.from(creator, frameHandlerFactory);
handshaker.upgradeRequest(negotiator, request, response, components, null);
}
}
Expand Down

0 comments on commit 78707ff

Please sign in to comment.