Skip to content

Commit

Permalink
Issue #4548 - clean up websocket removing duplicated and unused class…
Browse files Browse the repository at this point in the history
…es (#4549)

Create new module websocket-util which contains implementation classes shared by websocket-jetty and websocket-javax. Many of these classes had to be changed as the javax and jetty versions of them differed slightly.

Also includes general cleanups, removed unused interfaces and classes, etc..
  • Loading branch information
lachlan-roberts committed Feb 18, 2020
1 parent 59ae776 commit 5fe202f
Show file tree
Hide file tree
Showing 146 changed files with 657 additions and 4,386 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,17 @@ public static List<Option> coreJettyDependencies()
res.add(mavenBundle().groupId("org.eclipse.jetty").artifactId("jetty-plus").versionAsInProject().start());
res.add(mavenBundle().groupId("org.eclipse.jetty").artifactId("jetty-annotations").versionAsInProject().start());
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-core").versionAsInProject().start());
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-jetty-api").versionAsInProject().start());
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-jetty-common").versionAsInProject().start());
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-servlet").versionAsInProject().start());
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-util").versionAsInProject().start());
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-jetty-api").versionAsInProject().start());
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-jetty-server").versionAsInProject().start());
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-jetty-client").versionAsInProject().start());

res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-javax-common").versionAsInProject().noStart());
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-javax-client").versionAsInProject().noStart());
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-javax-server").versionAsInProject().noStart());
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-jetty-common").versionAsInProject().start());
res.add(mavenBundle().groupId("org.eclipse.jetty.toolchain").artifactId("jetty-javax-websocket-api").versionAsInProject().noStart());
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-javax-server").versionAsInProject().noStart());
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-javax-client").versionAsInProject().noStart());
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-javax-common").versionAsInProject().noStart());

res.add(mavenBundle().groupId("org.eclipse.jetty.osgi").artifactId("jetty-osgi-boot").versionAsInProject().start());
return res;
}
Expand Down
1 change: 1 addition & 0 deletions jetty-websocket/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<modules>
<module>websocket-core</module>
<module>websocket-servlet</module>
<module>websocket-util</module>
<!-- Jetty WebSocket Implementation -->
<module>websocket-jetty-api</module>
<module>websocket-jetty-common</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ public interface CoreSession extends OutgoingFrames, Configuration
*/
Behavior getBehavior();

/**
* TODO
* @return
*/
WebSocketComponents getWebSocketComponents();

/**
* @return The shared ByteBufferPool
*/
Expand Down Expand Up @@ -214,6 +220,12 @@ public Behavior getBehavior()
return null;
}

@Override
public WebSocketComponents getWebSocketComponents()
{
return null;
}

@Override
public ByteBufferPool getByteBufferPool()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ else if (values.length == 1)
extensionStack,
WebSocketConstants.SPEC_VERSION_STRING);

WebSocketCoreSession coreSession = new WebSocketCoreSession(frameHandler, Behavior.CLIENT, negotiated);
WebSocketCoreSession coreSession = new WebSocketCoreSession(frameHandler, Behavior.CLIENT, negotiated, wsClient.getWebSocketComponents());
customizer.customize(coreSession);

HttpClient httpClient = wsClient.getHttpClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.eclipse.jetty.websocket.core.IncomingFrames;
import org.eclipse.jetty.websocket.core.OpCode;
import org.eclipse.jetty.websocket.core.OutgoingFrames;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.WebSocketConstants;
import org.eclipse.jetty.websocket.core.exception.CloseException;
import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException;
Expand All @@ -63,6 +64,7 @@ public class WebSocketCoreSession implements IncomingFrames, CoreSession, Dumpab
private static final Logger LOG = Log.getLogger(WebSocketCoreSession.class);
private static final CloseStatus NO_CODE = new CloseStatus(CloseStatus.NO_CODE);

private final WebSocketComponents components;
private final Behavior behavior;
private final WebSocketSessionState sessionState = new WebSocketSessionState();
private final FrameHandler handler;
Expand All @@ -81,8 +83,9 @@ public class WebSocketCoreSession implements IncomingFrames, CoreSession, Dumpab
private Duration writeTimeout = WebSocketConstants.DEFAULT_WRITE_TIMEOUT;
private final ContextHandler contextHandler;

public WebSocketCoreSession(FrameHandler handler, Behavior behavior, Negotiated negotiated)
public WebSocketCoreSession(FrameHandler handler, Behavior behavior, Negotiated negotiated, WebSocketComponents components)
{
this.components = components;
this.handler = handler;
this.behavior = behavior;
this.negotiated = negotiated;
Expand Down Expand Up @@ -794,6 +797,12 @@ public Behavior getBehavior()
return behavior;
}

@Override
public WebSocketComponents getWebSocketComponents()
{
return components;
}

@Override
public String toString()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public boolean upgradeRequest(WebSocketNegotiator negotiator, HttpServletRequest
Negotiated negotiated = new Negotiated(baseRequest.getHttpURI().toURI(), protocol, baseRequest.isSecure(), extensionStack, WebSocketConstants.SPEC_VERSION_STRING);

// Create the Session
WebSocketCoreSession coreSession = newWebSocketCoreSession(handler, negotiated);
WebSocketCoreSession coreSession = newWebSocketCoreSession(handler, negotiated, components);
if (defaultCustomizer != null)
defaultCustomizer.customize(coreSession);
negotiator.customize(coreSession);
Expand Down Expand Up @@ -200,9 +200,9 @@ protected boolean validateNegotiation(Negotiation negotiation)
return true;
}

protected WebSocketCoreSession newWebSocketCoreSession(FrameHandler handler, Negotiated negotiated)
protected WebSocketCoreSession newWebSocketCoreSession(FrameHandler handler, Negotiated negotiated, WebSocketComponents components)
{
return new WebSocketCoreSession(handler, Behavior.SERVER, negotiated);
return new WebSocketCoreSession(handler, Behavior.SERVER, negotiated, components);
}

protected abstract WebSocketConnection createWebSocketConnection(Request baseRequest, WebSocketCoreSession coreSession);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void setup(Frame invalidFrame)
{
ExtensionStack exStack = new ExtensionStack(components, Behavior.SERVER);
exStack.negotiate(new LinkedList<>(), new LinkedList<>());
this.coreSession = new WebSocketCoreSession(new TestMessageHandler(), Behavior.CLIENT, Negotiated.from(exStack));
this.coreSession = new WebSocketCoreSession(new TestMessageHandler(), Behavior.CLIENT, Negotiated.from(exStack), components);
}

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ public class GeneratorTest

private static Generator generator = new Generator();
private static WebSocketCoreSession coreSession = newWebSocketCoreSession(Behavior.SERVER);
private static WebSocketComponents components = new WebSocketComponents();

private static WebSocketCoreSession newWebSocketCoreSession(Behavior behavior)
{
WebSocketComponents components = new WebSocketComponents();
ExtensionStack exStack = new ExtensionStack(components, Behavior.SERVER);
exStack.negotiate(new LinkedList<>(), new LinkedList<>());
return new WebSocketCoreSession(new TestMessageHandler(), behavior, Negotiated.from(exStack));
return new WebSocketCoreSession(new TestMessageHandler(), behavior, Negotiated.from(exStack), components);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public ParserCapture(boolean copy, Behavior behavior)
WebSocketComponents components = new WebSocketComponents();
ExtensionStack exStack = new ExtensionStack(components, Behavior.SERVER);
exStack.negotiate(new LinkedList<>(), new LinkedList<>());
this.coreSession = new WebSocketCoreSession(new TestMessageHandler(), behavior, Negotiated.from(exStack));
this.coreSession = new WebSocketCoreSession(new TestMessageHandler(), behavior, Negotiated.from(exStack), components);
coreSession.setAutoFragment(false);
coreSession.setMaxFrameSize(0);
this.parser = new Parser(components.getBufferPool(), coreSession);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private WebSocketCoreSession newWebSocketCoreSession()
{
ExtensionStack exStack = new ExtensionStack(components, Behavior.SERVER);
exStack.negotiate(new LinkedList<>(), new LinkedList<>());
WebSocketCoreSession coreSession = new WebSocketCoreSession(new TestMessageHandler(), Behavior.SERVER, Negotiated.from(exStack));
WebSocketCoreSession coreSession = new WebSocketCoreSession(new TestMessageHandler(), Behavior.SERVER, Negotiated.from(exStack), components);
return coreSession;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ private WebSocketCoreSession newSessionFromConfig(ConfigurationCustomizer config
ExtensionStack exStack = new ExtensionStack(components, Behavior.SERVER);
exStack.negotiate(new LinkedList<>(), new LinkedList<>());

WebSocketCoreSession coreSession = new WebSocketCoreSession(new TestMessageHandler(), Behavior.SERVER, Negotiated.from(exStack));
WebSocketCoreSession coreSession = new WebSocketCoreSession(new TestMessageHandler(), Behavior.SERVER, Negotiated.from(exStack), components);
configuration.customize(configuration);
return coreSession;
}
Expand Down
5 changes: 5 additions & 0 deletions jetty-websocket/websocket-javax-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
</properties>

<dependencies>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-javax-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
exports org.eclipse.jetty.websocket.javax.client;

requires transitive org.eclipse.jetty.client;
requires org.eclipse.jetty.websocket.core;
requires transitive org.eclipse.jetty.websocket.javax.common;
requires org.eclipse.jetty.websocket.core;
requires org.eclipse.jetty.websocket.util;

provides ContainerProvider with JavaxWebSocketClientContainerProvider;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import javax.websocket.ClientEndpointConfig;

import org.eclipse.jetty.websocket.javax.common.ClientEndpointConfigWrapper;
import org.eclipse.jetty.websocket.javax.common.InvalidWebSocketException;
import org.eclipse.jetty.websocket.util.InvalidWebSocketException;

public class AnnotatedClientEndpointConfig extends ClientEndpointConfigWrapper
{
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.eclipse.jetty.websocket.javax.client;

import java.net.URI;
import java.security.Principal;

import org.eclipse.jetty.client.HttpResponse;
import org.eclipse.jetty.io.EndPoint;
Expand All @@ -28,25 +29,20 @@
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketFrameHandler;
import org.eclipse.jetty.websocket.javax.common.UpgradeRequest;

public class JavaxClientUpgradeRequest extends ClientUpgradeRequest
public class JavaxClientUpgradeRequest extends ClientUpgradeRequest implements UpgradeRequest
{
private final JavaxWebSocketClientContainer containerContext;
private final JavaxWebSocketFrameHandler frameHandler;

public JavaxClientUpgradeRequest(JavaxWebSocketClientContainer clientContainer, WebSocketCoreClient coreClient, URI requestURI, Object websocketPojo)
{
super(coreClient, requestURI);
this.containerContext = clientContainer;

UpgradeRequest upgradeRequest = new DelegatedJavaxClientUpgradeRequest(this);
frameHandler = containerContext.newFrameHandler(websocketPojo, upgradeRequest);
frameHandler = clientContainer.newFrameHandler(websocketPojo, this);
}

@Override
public void upgrade(HttpResponse response, EndPoint endPoint)
{
frameHandler.setUpgradeRequest(new DelegatedJavaxClientUpgradeRequest(this));
frameHandler.setUpgradeResponse(new DelegatedJavaxClientUpgradeResponse(response));
frameHandler.setUpgradeRequest(this);
super.upgrade(response, endPoint);
}

Expand All @@ -55,4 +51,17 @@ public FrameHandler getFrameHandler()
{
return frameHandler;
}

@Override
public Principal getUserPrincipal()
{
// User Principal not available from Client API
return null;
}

@Override
public URI getRequestURI()
{
return getURI();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketContainer;
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketFrameHandlerFactory;
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketFrameHandlerMetadata;
import org.eclipse.jetty.websocket.javax.common.util.InvokerUtils;
import org.eclipse.jetty.websocket.util.InvokerUtils;

public class JavaxWebSocketClientFrameHandlerFactory extends JavaxWebSocketFrameHandlerFactory
{
Expand Down
5 changes: 5 additions & 0 deletions jetty-websocket/websocket-javax-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
<artifactId>websocket-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-javax-websocket-api</artifactId>
Expand Down
Loading

0 comments on commit 5fe202f

Please sign in to comment.