Merge remote-tracking branch 'origin/jetty-10.0.x' into jetty-10.0.x-5086-review-scanner
This commit is contained in:
commit
c776eeb838
|
@ -29,7 +29,7 @@ jetty-9.4.35.v20201120 - 20 November 2020
|
|||
+ 5539 StatisticsServlet output is not valid
|
||||
+ 5562 ArrayTernaryTrie consumes too much memory
|
||||
+ 5575 Add SEARCH as a known HttpMethod
|
||||
+ 5605 java.io.IOException: unconsumed input during http request parsing
|
||||
+ 5605 CVE-2020-27218 java.io.IOException: unconsumed input during http request parsing
|
||||
+ 5633 Allow to configure HttpClient request authority
|
||||
|
||||
jetty-9.4.34.v20201102 - 02 November 2020
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.websocket</groupId>
|
||||
<artifactId>websocket-util-server</artifactId>
|
||||
<artifactId>websocket-servlet</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -359,7 +359,7 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.websocket</groupId>
|
||||
<artifactId>websocket-util-server</artifactId>
|
||||
<artifactId>websocket-servlet</artifactId>
|
||||
<version>10.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.websocket</groupId>
|
||||
<artifactId>websocket-util-server</artifactId>
|
||||
<artifactId>websocket-servlet</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
|
|
@ -620,7 +620,7 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.websocket</groupId>
|
||||
<artifactId>websocket-util-server</artifactId>
|
||||
<artifactId>websocket-servlet</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -63,10 +63,9 @@ public class HTTP2ClientSession extends HTTP2Session
|
|||
else
|
||||
{
|
||||
stream.process(frame, Callback.NOOP);
|
||||
boolean closed = stream.updateClose(frame.isEndStream(), CloseState.Event.RECEIVED);
|
||||
notifyHeaders(stream, frame);
|
||||
if (closed)
|
||||
if (stream.updateClose(frame.isEndStream(), CloseState.Event.RECEIVED))
|
||||
removeStream(stream);
|
||||
notifyHeaders(stream, frame);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -472,10 +472,9 @@ public class HTTP2Stream extends IdleTimeout implements IStream, Callback, Dumpa
|
|||
dataEntry = dataQueue.poll();
|
||||
}
|
||||
DataFrame frame = dataEntry.frame;
|
||||
boolean closed = updateClose(frame.isEndStream(), CloseState.Event.RECEIVED);
|
||||
notifyDataDemanded(this, frame, dataEntry.callback);
|
||||
if (closed)
|
||||
if (updateClose(frame.isEndStream(), CloseState.Event.RECEIVED))
|
||||
session.removeStream(this);
|
||||
notifyDataDemanded(this, frame, dataEntry.callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.eclipse.jetty.client.AbstractConnectionPool;
|
|||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.client.HttpDestination;
|
||||
import org.eclipse.jetty.client.HttpResponseException;
|
||||
import org.eclipse.jetty.client.MultiplexConnectionPool;
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.client.api.Response;
|
||||
import org.eclipse.jetty.client.api.Result;
|
||||
|
@ -336,12 +337,28 @@ public class MaxConcurrentStreamsTest extends AbstractTest
|
|||
}
|
||||
});
|
||||
|
||||
int parallelism = 4;
|
||||
int runs = 1;
|
||||
int iterations = 32;
|
||||
|
||||
client.setMaxConnectionsPerDestination(32768);
|
||||
client.setMaxRequestsQueuedPerDestination(1024 * 1024);
|
||||
client.getTransport().setConnectionPoolFactory(destination ->
|
||||
{
|
||||
try
|
||||
{
|
||||
MultiplexConnectionPool pool = new MultiplexConnectionPool(destination, client.getMaxConnectionsPerDestination(), false, destination, 1);
|
||||
pool.preCreateConnections(parallelism * 2).get();
|
||||
return pool;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
// Prime the destination to pre-create connections.
|
||||
client.GET("http://localhost:" + connector.getLocalPort());
|
||||
|
||||
int parallelism = 16;
|
||||
int runs = 1;
|
||||
int iterations = 256;
|
||||
int total = parallelism * runs * iterations;
|
||||
CountDownLatch latch = new CountDownLatch(total);
|
||||
Queue<Result> failures = new ConcurrentLinkedQueue<>();
|
||||
|
|
|
@ -115,11 +115,10 @@ public class HTTP2ServerSession extends HTTP2Session implements ServerParser.Lis
|
|||
}
|
||||
|
||||
stream.process(frame, Callback.NOOP);
|
||||
boolean closed = stream.updateClose(frame.isEndStream(), CloseState.Event.RECEIVED);
|
||||
if (stream.updateClose(frame.isEndStream(), CloseState.Event.RECEIVED))
|
||||
removeStream(stream);
|
||||
Stream.Listener listener = notifyNewStream(stream, frame);
|
||||
stream.setListener(listener);
|
||||
if (closed)
|
||||
removeStream(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -138,10 +137,9 @@ public class HTTP2ServerSession extends HTTP2Session implements ServerParser.Lis
|
|||
if (stream != null)
|
||||
{
|
||||
stream.process(frame, Callback.NOOP);
|
||||
boolean closed = stream.updateClose(frame.isEndStream(), CloseState.Event.RECEIVED);
|
||||
notifyHeaders(stream, frame);
|
||||
if (closed)
|
||||
if (stream.updateClose(frame.isEndStream(), CloseState.Event.RECEIVED))
|
||||
removeStream(stream);
|
||||
notifyHeaders(stream, frame);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -316,7 +316,7 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.websocket</groupId>
|
||||
<artifactId>websocket-util-server</artifactId>
|
||||
<artifactId>websocket-servlet</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
|
|
@ -186,8 +186,7 @@ public class TestOSGiUtil
|
|||
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-core-server").versionAsInProject().start());
|
||||
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-core-client").versionAsInProject().start());
|
||||
res.add(mavenBundle().groupId("org.eclipse.jetty.websocket").artifactId("websocket-core-common").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-util-server").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-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());
|
||||
|
|
|
@ -27,10 +27,23 @@
|
|||
</goals>
|
||||
<configuration>
|
||||
<includes>**</includes>
|
||||
<excludes>**/MANIFEST.MF,META-INF/*.RSA,META-INF/*.DSA,META-INF/*.SF,module-info.class</excludes>
|
||||
<excludes>
|
||||
**/MANIFEST.MF,
|
||||
META-INF/LICENSE,
|
||||
META-INF/*.RSA,
|
||||
META-INF/*.DSA,
|
||||
META-INF/*.SF,
|
||||
module-info.class,
|
||||
readme.txt,
|
||||
MANIFEST.MF,
|
||||
about.html,
|
||||
ecj.1
|
||||
</excludes>
|
||||
<outputDirectory>${project.build.directory}/classes</outputDirectory>
|
||||
<overWriteReleases>false</overWriteReleases>
|
||||
<overWriteSnapshots>true</overWriteSnapshots>
|
||||
<excludeScope>test</excludeScope>
|
||||
<includeScope>runtime</includeScope>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
|
@ -84,10 +97,12 @@
|
|||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestFile>src/main/resources/MANIFEST.MF</manifestFile>
|
||||
<manifest>
|
||||
<mainClass>org.eclipse.jetty.runner.Runner</mainClass>
|
||||
</manifest>
|
||||
<manifestEntries>
|
||||
<Comment>Jetty Runner</Comment>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
Comment: Jetty Runner
|
|
@ -29,6 +29,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.jetty.util.component.Dumpable;
|
||||
import org.eclipse.jetty.util.component.DumpableCollection;
|
||||
|
@ -166,16 +167,42 @@ public class Pool<T> implements AutoCloseable, Dumpable
|
|||
this.maxMultiplex = maxMultiplex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maximum number of times the entries of the pool
|
||||
* can be acquired.
|
||||
* @return the max usage count.
|
||||
*/
|
||||
public int getMaxUsageCount()
|
||||
{
|
||||
return maxUsageCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the max usage count of the pool's entries. All existing
|
||||
* idle entries over this new max usage are removed and closed.
|
||||
* @param maxUsageCount the max usage count.
|
||||
*/
|
||||
public final void setMaxUsageCount(int maxUsageCount)
|
||||
{
|
||||
if (maxUsageCount == 0)
|
||||
throw new IllegalArgumentException("Max usage count must be != 0");
|
||||
this.maxUsageCount = maxUsageCount;
|
||||
|
||||
// Iterate the entries, remove overused ones and collect a list of the closeable removed ones.
|
||||
List<Closeable> copy;
|
||||
try (AutoLock l = lock.lock())
|
||||
{
|
||||
if (closed)
|
||||
return;
|
||||
|
||||
copy = entries.stream()
|
||||
.filter(entry -> entry.isIdleAndOverUsed() && remove(entry) && entry.pooled instanceof Closeable)
|
||||
.map(entry -> (Closeable)entry.pooled)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// Iterate the copy and close the collected entries.
|
||||
copy.forEach(IO::close);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -429,6 +456,12 @@ public class Pool<T> implements AutoCloseable, Dumpable
|
|||
this.state = new AtomicBiInteger(Integer.MIN_VALUE, 0);
|
||||
}
|
||||
|
||||
// for testing only
|
||||
void setUsageCount(int usageCount)
|
||||
{
|
||||
this.state.getAndSetHi(usageCount);
|
||||
}
|
||||
|
||||
/** Enable a reserved entry {@link Entry}.
|
||||
* An entry returned from the {@link #reserve(int)} method must be enabled with this method,
|
||||
* once and only once, before it is usable by the pool.
|
||||
|
@ -507,7 +540,9 @@ public class Pool<T> implements AutoCloseable, Dumpable
|
|||
if (closed || multiplexingCount >= maxMultiplex || (currentMaxUsageCount > 0 && usageCount >= currentMaxUsageCount))
|
||||
return false;
|
||||
|
||||
if (state.compareAndSet(encoded, usageCount + 1, multiplexingCount + 1))
|
||||
// Prevent overflowing the usage counter by capping it at Integer.MAX_VALUE.
|
||||
int newUsageCount = usageCount == Integer.MAX_VALUE ? Integer.MAX_VALUE : usageCount + 1;
|
||||
if (state.compareAndSet(encoded, newUsageCount, multiplexingCount + 1))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -543,13 +578,6 @@ public class Pool<T> implements AutoCloseable, Dumpable
|
|||
return !(overUsed && newMultiplexingCount == 0);
|
||||
}
|
||||
|
||||
public boolean isOverUsed()
|
||||
{
|
||||
int currentMaxUsageCount = maxUsageCount;
|
||||
int usageCount = state.getHi();
|
||||
return currentMaxUsageCount > 0 && usageCount >= currentMaxUsageCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to mark the entry as removed.
|
||||
* @return true if the entry has to be removed from the containing pool, false otherwise.
|
||||
|
@ -590,6 +618,22 @@ public class Pool<T> implements AutoCloseable, Dumpable
|
|||
return AtomicBiInteger.getHi(encoded) >= 0 && AtomicBiInteger.getLo(encoded) > 0;
|
||||
}
|
||||
|
||||
public boolean isOverUsed()
|
||||
{
|
||||
int currentMaxUsageCount = maxUsageCount;
|
||||
int usageCount = state.getHi();
|
||||
return currentMaxUsageCount > 0 && usageCount >= currentMaxUsageCount;
|
||||
}
|
||||
|
||||
boolean isIdleAndOverUsed()
|
||||
{
|
||||
int currentMaxUsageCount = maxUsageCount;
|
||||
long encoded = state.get();
|
||||
int usageCount = AtomicBiInteger.getHi(encoded);
|
||||
int multiplexCount = AtomicBiInteger.getLo(encoded);
|
||||
return currentMaxUsageCount > 0 && usageCount >= currentMaxUsageCount && multiplexCount == 0;
|
||||
}
|
||||
|
||||
public int getUsageCount()
|
||||
{
|
||||
return Math.max(state.getHi(), 0);
|
||||
|
|
|
@ -538,6 +538,42 @@ public class PoolTest
|
|||
assertThat(e1.getUsageCount(), is(2));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource(value = "strategy")
|
||||
public void testDynamicMaxUsageCountChangeOverflowMaxInt(Factory factory)
|
||||
{
|
||||
Pool<String> pool = factory.getPool(1);
|
||||
Pool<String>.Entry entry = pool.reserve(-1);
|
||||
entry.enable("aaa", false);
|
||||
entry.setUsageCount(Integer.MAX_VALUE);
|
||||
|
||||
Pool<String>.Entry acquired1 = pool.acquire();
|
||||
assertThat(acquired1, notNullValue());
|
||||
assertThat(pool.release(acquired1), is(true));
|
||||
|
||||
pool.setMaxUsageCount(1);
|
||||
Pool<String>.Entry acquired2 = pool.acquire();
|
||||
assertThat(acquired2, nullValue());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource(value = "strategy")
|
||||
public void testDynamicMaxUsageCountChangeSweep(Factory factory)
|
||||
{
|
||||
Pool<String> pool = factory.getPool(2);
|
||||
Pool<String>.Entry entry1 = pool.reserve(-1);
|
||||
entry1.enable("aaa", false);
|
||||
Pool<String>.Entry entry2 = pool.reserve(-1);
|
||||
entry2.enable("bbb", false);
|
||||
|
||||
Pool<String>.Entry acquired1 = pool.acquire();
|
||||
assertThat(acquired1, notNullValue());
|
||||
assertThat(pool.release(acquired1), is(true));
|
||||
|
||||
pool.setMaxUsageCount(1);
|
||||
assertThat(pool.size(), is(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigLimits()
|
||||
{
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
|
||||
|
||||
This is the jetty websocket module that provides a websocket server and the skeleton of a websocket client.
|
||||
|
||||
By default websockets is included with a jetty release (with these classes either being in the jetty-websocket jar or in
|
||||
an aggregate jar (see below).
|
||||
|
||||
|
||||
In order to accept a websocket connection, the websocket handshake request is first routed to normal HTTP request
|
||||
handling, which must respond with a 101 response and an instance of WebSocketConnection set as the
|
||||
"org.eclipse.jetty.io.Connection" request attribute. The accepting behaviour is provided by WebSocketHandler or the
|
||||
WebSocketServlet class, both of which delegate to the WebSocketFactory class.
|
||||
|
||||
A TestServer and TestClient class are available, and can be run either directly from an IDE (if jetty source is
|
||||
imported), or from the command line with
|
||||
|
||||
|
||||
java -cp jetty-aggregate/jetty-all/target/jetty-all-7.x.y.jar:jetty-distribution/target/distribution/lib/servlet-api-2.5.jar
|
||||
org.eclipse.jetty.websocket.TestServer --help
|
||||
|
||||
java -cp jetty-aggregate/jetty-all/target/jetty-all-7.x.y.jar:jetty-distribution/target/distribution/lib/servlet-api-2.5.jar
|
||||
org.eclipse.jetty.websocket.TestClient --help
|
||||
|
||||
|
||||
Without a protocol specified, the client will just send/receive websocket PING/PONG packets. A protocol can be specified for testing other
|
||||
aspects of websocket. Specifically the server and client understand the following protocols:
|
||||
|
||||
org.ietf.websocket.test-echo
|
||||
Websocket messages are sent by the client and the server will echo every frame.
|
||||
|
||||
org.ietf.websocket.test-echo-broadcast
|
||||
Websocket messages are sent by the client and the server will echo every frame to every connection.
|
||||
|
||||
org.ietf.websocket.test-echo-assemble
|
||||
Websocket messages are sent by the client and the server will echo assembled messages as a single frame.
|
||||
|
||||
org.ietf.websocket.test-echo-fragment
|
||||
Websocket messages are sent and the server will echo each message fragmented into 2 frames.
|
||||
|
||||
|
|
@ -28,9 +28,8 @@
|
|||
<module>websocket-javax-client</module>
|
||||
<module>websocket-javax-server</module>
|
||||
<module>websocket-javax-tests</module>
|
||||
<!-- Common WebSocket Implementation -->
|
||||
<module>websocket-util</module>
|
||||
<module>websocket-util-server</module>
|
||||
<!-- Common Servlet WebSocket Implementation -->
|
||||
<module>websocket-servlet</module>
|
||||
</modules>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
@ -77,6 +77,24 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<extensions>true</extensions>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>generate-manifest</id>
|
||||
<goals>
|
||||
<goal>manifest</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Export-Package>*,org.eclipse.jetty.websocket.core.client.internal.*</Export-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
|
@ -52,6 +52,8 @@ import org.eclipse.jetty.websocket.core.CoreSession;
|
|||
import org.eclipse.jetty.websocket.core.ExtensionConfig;
|
||||
import org.eclipse.jetty.websocket.core.FrameHandler;
|
||||
import org.eclipse.jetty.websocket.core.WebSocketConstants;
|
||||
import org.eclipse.jetty.websocket.core.client.internal.HttpUpgraderOverHTTP;
|
||||
import org.eclipse.jetty.websocket.core.client.internal.HttpUpgraderOverHTTP2;
|
||||
import org.eclipse.jetty.websocket.core.exception.UpgradeException;
|
||||
import org.eclipse.jetty.websocket.core.exception.WebSocketException;
|
||||
import org.eclipse.jetty.websocket.core.internal.ExtensionStack;
|
||||
|
@ -281,7 +283,7 @@ public abstract class CoreClientUpgradeRequest extends HttpRequest implements Re
|
|||
|
||||
public abstract FrameHandler getFrameHandler();
|
||||
|
||||
void requestComplete()
|
||||
public void requestComplete()
|
||||
{
|
||||
// Add extensions header filtering out internal extensions and internal parameters.
|
||||
String extensionString = requestedExtensions.stream()
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.eclipse.jetty.websocket.core.ExtensionConfig;
|
|||
import org.eclipse.jetty.websocket.core.FrameHandler;
|
||||
import org.eclipse.jetty.websocket.core.WebSocketComponents;
|
||||
import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry;
|
||||
import org.eclipse.jetty.websocket.core.client.internal.HttpClientProvider;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.core.client;
|
||||
package org.eclipse.jetty.websocket.core.client.internal;
|
||||
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.core.client;
|
||||
package org.eclipse.jetty.websocket.core.client.internal;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
|
@ -34,6 +34,7 @@ import org.eclipse.jetty.http.PreEncodedHttpField;
|
|||
import org.eclipse.jetty.io.EndPoint;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.websocket.core.WebSocketConstants;
|
||||
import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.core.internal.WebSocketCore;
|
||||
|
||||
public class HttpUpgraderOverHTTP implements HttpUpgrader
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.core.client;
|
||||
package org.eclipse.jetty.websocket.core.client.internal;
|
||||
|
||||
import org.eclipse.jetty.client.HttpRequest;
|
||||
import org.eclipse.jetty.client.HttpResponse;
|
||||
|
@ -27,6 +27,7 @@ import org.eclipse.jetty.http.PreEncodedHttpField;
|
|||
import org.eclipse.jetty.io.EndPoint;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.websocket.core.WebSocketConstants;
|
||||
import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest;
|
||||
|
||||
public class HttpUpgraderOverHTTP2 implements HttpUpgrader
|
||||
{
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.core.client;
|
||||
package org.eclipse.jetty.websocket.core.client.internal;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
|
@ -26,7 +26,7 @@ import org.eclipse.jetty.xml.XmlConfiguration;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
class XmlHttpClientProvider implements HttpClientProvider
|
||||
public class XmlHttpClientProvider implements HttpClientProvider
|
||||
{
|
||||
private static final Logger LOG = LoggerFactory.getLogger(XmlHttpClientProvider.class);
|
||||
|
|
@ -26,7 +26,27 @@ module org.eclipse.jetty.websocket.core.common
|
|||
{
|
||||
exports org.eclipse.jetty.websocket.core;
|
||||
exports org.eclipse.jetty.websocket.core.exception;
|
||||
exports org.eclipse.jetty.websocket.core.internal to org.eclipse.jetty.websocket.core.client, org.eclipse.jetty.websocket.core.server, org.eclipse.jetty.util;
|
||||
|
||||
exports org.eclipse.jetty.websocket.core.internal to
|
||||
org.eclipse.jetty.websocket.core.client,
|
||||
org.eclipse.jetty.websocket.core.server;
|
||||
|
||||
// The Jetty & Javax API Layers need to access both access some internal utilities which we don't want to expose.
|
||||
exports org.eclipse.jetty.websocket.core.internal.util to
|
||||
org.eclipse.jetty.websocket.jetty.common,
|
||||
org.eclipse.jetty.websocket.jetty.client,
|
||||
org.eclipse.jetty.websocket.jetty.server,
|
||||
org.eclipse.jetty.websocket.javax.common,
|
||||
org.eclipse.jetty.websocket.javax.client,
|
||||
org.eclipse.jetty.websocket.javax.server;
|
||||
|
||||
exports org.eclipse.jetty.websocket.core.internal.messages to
|
||||
org.eclipse.jetty.websocket.jetty.common,
|
||||
org.eclipse.jetty.websocket.jetty.client,
|
||||
org.eclipse.jetty.websocket.jetty.server,
|
||||
org.eclipse.jetty.websocket.javax.common,
|
||||
org.eclipse.jetty.websocket.javax.client,
|
||||
org.eclipse.jetty.websocket.javax.server;
|
||||
|
||||
requires org.eclipse.jetty.http;
|
||||
requires transitive org.eclipse.jetty.io;
|
||||
|
|
|
@ -16,11 +16,13 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util;
|
||||
package org.eclipse.jetty.websocket.core.exception;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.eclipse.jetty.websocket.core.internal.util.ReflectUtils;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class DuplicateAnnotationException extends InvalidWebSocketException
|
||||
{
|
|
@ -16,12 +16,14 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util;
|
||||
package org.eclipse.jetty.websocket.core.exception;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.eclipse.jetty.websocket.core.internal.util.ReflectUtils;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class InvalidSignatureException extends InvalidWebSocketException
|
||||
{
|
|
@ -16,9 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util;
|
||||
|
||||
import org.eclipse.jetty.websocket.core.exception.WebSocketException;
|
||||
package org.eclipse.jetty.websocket.core.exception;
|
||||
|
||||
/**
|
||||
* Indicating that the provided Class is not a valid WebSocket per the chosen API.
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.core;
|
||||
package org.eclipse.jetty.websocket.core.internal;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
|
@ -27,6 +27,11 @@ import org.eclipse.jetty.util.Callback;
|
|||
import org.eclipse.jetty.util.IteratingNestedCallback;
|
||||
import org.eclipse.jetty.util.Utf8Appendable;
|
||||
import org.eclipse.jetty.util.Utf8StringBuilder;
|
||||
import org.eclipse.jetty.websocket.core.CloseStatus;
|
||||
import org.eclipse.jetty.websocket.core.CoreSession;
|
||||
import org.eclipse.jetty.websocket.core.Frame;
|
||||
import org.eclipse.jetty.websocket.core.FrameHandler;
|
||||
import org.eclipse.jetty.websocket.core.OpCode;
|
||||
import org.eclipse.jetty.websocket.core.exception.BadPayloadException;
|
||||
import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -87,7 +92,7 @@ public class MessageHandler implements FrameHandler
|
|||
};
|
||||
}
|
||||
|
||||
protected static final Logger LOG = LoggerFactory.getLogger(MessageHandler.class);
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MessageHandler.class);
|
||||
|
||||
private CoreSession coreSession;
|
||||
private Utf8StringBuilder textMessageBuffer;
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util.messages;
|
||||
package org.eclipse.jetty.websocket.core.internal.messages;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.util.Objects;
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util.messages;
|
||||
package org.eclipse.jetty.websocket.core.internal.messages;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -28,8 +28,8 @@ import org.eclipse.jetty.util.BufferUtil;
|
|||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.websocket.core.CoreSession;
|
||||
import org.eclipse.jetty.websocket.core.Frame;
|
||||
import org.eclipse.jetty.websocket.core.exception.InvalidSignatureException;
|
||||
import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException;
|
||||
import org.eclipse.jetty.websocket.util.InvalidSignatureException;
|
||||
|
||||
public class ByteArrayMessageSink extends AbstractMessageSink
|
||||
{
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util.messages;
|
||||
package org.eclipse.jetty.websocket.core.internal.messages;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -29,8 +29,8 @@ import org.eclipse.jetty.util.BufferUtil;
|
|||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.websocket.core.CoreSession;
|
||||
import org.eclipse.jetty.websocket.core.Frame;
|
||||
import org.eclipse.jetty.websocket.core.exception.InvalidSignatureException;
|
||||
import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException;
|
||||
import org.eclipse.jetty.websocket.util.InvalidSignatureException;
|
||||
|
||||
public class ByteBufferMessageSink extends AbstractMessageSink
|
||||
{
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util.messages;
|
||||
package org.eclipse.jetty.websocket.core.internal.messages;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.lang.invoke.MethodHandle;
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util.messages;
|
||||
package org.eclipse.jetty.websocket.core.internal.messages;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util.messages;
|
||||
package org.eclipse.jetty.websocket.core.internal.messages;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util.messages;
|
||||
package org.eclipse.jetty.websocket.core.internal.messages;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util.messages;
|
||||
package org.eclipse.jetty.websocket.core.internal.messages;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util.messages;
|
||||
package org.eclipse.jetty.websocket.core.internal.messages;
|
||||
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.websocket.core.Frame;
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util.messages;
|
||||
package org.eclipse.jetty.websocket.core.internal.messages;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util.messages;
|
||||
package org.eclipse.jetty.websocket.core.internal.messages;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util.messages;
|
||||
package org.eclipse.jetty.websocket.core.internal.messages;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util.messages;
|
||||
package org.eclipse.jetty.websocket.core.internal.messages;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.util.Objects;
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util.messages;
|
||||
package org.eclipse.jetty.websocket.core.internal.messages;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util.messages;
|
||||
package org.eclipse.jetty.websocket.core.internal.messages;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util;
|
||||
package org.eclipse.jetty.websocket.core.internal.util;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
|
@ -26,6 +26,7 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.websocket.core.exception.InvalidSignatureException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util;
|
||||
package org.eclipse.jetty.websocket.core.internal.util;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.invoke.MethodType;
|
||||
|
@ -31,6 +31,9 @@ import java.util.List;
|
|||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.eclipse.jetty.websocket.core.exception.DuplicateAnnotationException;
|
||||
import org.eclipse.jetty.websocket.core.exception.InvalidWebSocketException;
|
||||
|
||||
public class ReflectUtils
|
||||
{
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util;
|
||||
package org.eclipse.jetty.websocket.core.internal.util;
|
||||
|
||||
/**
|
||||
* Collection of utility methods for Text content
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util.server.internal;
|
||||
package org.eclipse.jetty.websocket.core.server;
|
||||
|
||||
import org.eclipse.jetty.websocket.core.FrameHandler;
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util.server.internal;
|
||||
package org.eclipse.jetty.websocket.core.server;
|
||||
|
||||
import java.net.HttpCookie;
|
||||
import java.net.InetSocketAddress;
|
||||
|
@ -41,22 +41,19 @@ import org.eclipse.jetty.http.HttpHeader;
|
|||
import org.eclipse.jetty.util.URIUtil;
|
||||
import org.eclipse.jetty.websocket.core.ExtensionConfig;
|
||||
import org.eclipse.jetty.websocket.core.WebSocketConstants;
|
||||
import org.eclipse.jetty.websocket.core.server.Negotiation;
|
||||
import org.eclipse.jetty.websocket.core.server.internal.UpgradeHttpServletRequest;
|
||||
|
||||
/**
|
||||
* Holder of request data for a WebSocket upgrade request.
|
||||
*/
|
||||
public class ServerUpgradeRequest
|
||||
{
|
||||
private final URI requestURI;
|
||||
private final String queryString;
|
||||
private final UpgradeHttpServletRequest request;
|
||||
private final boolean secure;
|
||||
private final Negotiation negotiation;
|
||||
private final WebSocketNegotiation negotiation;
|
||||
private List<HttpCookie> cookies;
|
||||
private Map<String, List<String>> parameterMap;
|
||||
|
||||
public ServerUpgradeRequest(Negotiation negotiation) throws BadMessageException
|
||||
public ServerUpgradeRequest(WebSocketNegotiation negotiation) throws BadMessageException
|
||||
{
|
||||
this.negotiation = negotiation;
|
||||
HttpServletRequest httpRequest = negotiation.getRequest();
|
||||
|
@ -114,7 +111,7 @@ public class ServerUpgradeRequest
|
|||
|
||||
/**
|
||||
* @return The extensions offered
|
||||
* @see Negotiation#getOfferedExtensions()
|
||||
* @see WebSocketNegotiation#getOfferedExtensions()
|
||||
*/
|
||||
public List<ExtensionConfig> getExtensions()
|
||||
{
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util.server.internal;
|
||||
package org.eclipse.jetty.websocket.core.server;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -31,17 +31,13 @@ import javax.servlet.http.HttpServletResponse;
|
|||
|
||||
import org.eclipse.jetty.http.HttpHeader;
|
||||
import org.eclipse.jetty.websocket.core.ExtensionConfig;
|
||||
import org.eclipse.jetty.websocket.core.server.Negotiation;
|
||||
|
||||
/**
|
||||
* Servlet Specific UpgradeResponse implementation.
|
||||
*/
|
||||
public class ServerUpgradeResponse
|
||||
{
|
||||
private final HttpServletResponse response;
|
||||
private final Negotiation negotiation;
|
||||
private final WebSocketNegotiation negotiation;
|
||||
|
||||
public ServerUpgradeResponse(Negotiation negotiation)
|
||||
public ServerUpgradeResponse(WebSocketNegotiation negotiation)
|
||||
{
|
||||
this.negotiation = negotiation;
|
||||
this.response = negotiation.getResponse();
|
|
@ -16,13 +16,13 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util.server.internal;
|
||||
package org.eclipse.jetty.websocket.core.server;
|
||||
|
||||
/**
|
||||
* Abstract WebSocket creator interface.
|
||||
* <p>
|
||||
* Should you desire filtering of the WebSocket object creation due to criteria such as origin or sub-protocol, then you will be required to implement a custom
|
||||
* WebSocketCreator implementation.
|
||||
* Should you desire filtering of the WebSocket object creation due to criteria such as origin or sub-protocol,
|
||||
* then you will be required to implement a custom WebSocketCreator implementation.
|
||||
* </p>
|
||||
*/
|
||||
public interface WebSocketCreator
|
|
@ -16,10 +16,9 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util.server.internal;
|
||||
package org.eclipse.jetty.websocket.core.server;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
@ -39,10 +38,9 @@ import org.eclipse.jetty.websocket.core.CoreSession;
|
|||
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.Handshaker;
|
||||
import org.eclipse.jetty.websocket.core.server.Negotiation;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketServerComponents;
|
||||
import org.eclipse.jetty.websocket.core.server.internal.CreatorNegotiator;
|
||||
import org.eclipse.jetty.websocket.core.server.internal.Handshaker;
|
||||
import org.eclipse.jetty.websocket.core.server.internal.HandshakerSelector;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -61,20 +59,14 @@ public class WebSocketMappings implements Dumpable, LifeCycle.Listener
|
|||
private static final Logger LOG = LoggerFactory.getLogger(WebSocketMappings.class);
|
||||
public static final String WEBSOCKET_MAPPING_ATTRIBUTE = WebSocketMappings.class.getName();
|
||||
|
||||
public static WebSocketMappings getMapping(ServletContext servletContext)
|
||||
public static WebSocketMappings getWebSocketNegotiator(ServletContext servletContext)
|
||||
{
|
||||
return (WebSocketMappings)servletContext.getAttribute(WEBSOCKET_MAPPING_ATTRIBUTE);
|
||||
}
|
||||
|
||||
public WebSocketCreator getMapping(PathSpec pathSpec)
|
||||
public static WebSocketMappings ensureMappings(ServletContext servletContext)
|
||||
{
|
||||
Negotiator cn = mappings.get(pathSpec);
|
||||
return cn == null ? null : cn.getWebSocketCreator();
|
||||
}
|
||||
|
||||
public static WebSocketMappings ensureMapping(ServletContext servletContext)
|
||||
{
|
||||
WebSocketMappings mapping = getMapping(servletContext);
|
||||
WebSocketMappings mapping = getWebSocketNegotiator(servletContext);
|
||||
if (mapping == null)
|
||||
{
|
||||
mapping = new WebSocketMappings(WebSocketServerComponents.getWebSocketComponents(servletContext));
|
||||
|
@ -123,9 +115,9 @@ public class WebSocketMappings implements Dumpable, LifeCycle.Listener
|
|||
throw new IllegalArgumentException("Unrecognized path spec syntax [" + rawSpec + "]");
|
||||
}
|
||||
|
||||
private final PathMappings<Negotiator> mappings = new PathMappings<>();
|
||||
private final PathMappings<WebSocketNegotiator> mappings = new PathMappings<>();
|
||||
private final WebSocketComponents components;
|
||||
private final Handshaker handshaker = Handshaker.newInstance();
|
||||
private final Handshaker handshaker = new HandshakerSelector();
|
||||
|
||||
public WebSocketMappings()
|
||||
{
|
||||
|
@ -161,6 +153,19 @@ public class WebSocketMappings implements Dumpable, LifeCycle.Listener
|
|||
Dumpable.dumpObjects(out, indent, this, mappings);
|
||||
}
|
||||
|
||||
public WebSocketNegotiator getWebSocketNegotiator(PathSpec pathSpec)
|
||||
{
|
||||
return mappings.get(pathSpec);
|
||||
}
|
||||
|
||||
public WebSocketCreator getWebSocketCreator(PathSpec pathSpec)
|
||||
{
|
||||
WebSocketNegotiator negotiator = getWebSocketNegotiator(pathSpec);
|
||||
if (negotiator instanceof CreatorNegotiator)
|
||||
return ((CreatorNegotiator)negotiator).getWebSocketCreator();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually add a WebSocket mapping.
|
||||
* <p>
|
||||
|
@ -171,12 +176,28 @@ public class WebSocketMappings implements Dumpable, LifeCycle.Listener
|
|||
*
|
||||
* @param pathSpec the pathspec to respond on
|
||||
* @param creator the websocket creator to activate on the provided mapping.
|
||||
* @param factory the factory to use to create a FrameHandler for the websocket
|
||||
* @param factory the factory to use to create a FrameHandler for the websocket.
|
||||
* @param customizer the customizer to use to customize the WebSocket session.
|
||||
*/
|
||||
public void addMapping(PathSpec pathSpec, WebSocketCreator creator, FrameHandlerFactory factory, Configuration.Customizer customizer) throws WebSocketException
|
||||
{
|
||||
mappings.put(pathSpec, new Negotiator(creator, factory, customizer));
|
||||
mappings.put(pathSpec, new CreatorNegotiator(creator, factory, customizer));
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually add a WebSocket mapping.
|
||||
* <p>
|
||||
* If mapping is added before this configuration is started, then it is persisted through
|
||||
* stop/start of this configuration's lifecycle. Otherwise it will be removed when
|
||||
* this configuration is stopped.
|
||||
* </p>
|
||||
*
|
||||
* @param pathSpec the pathspec to respond on
|
||||
* @param negotiator the WebSocketNegotiator to use to create a FrameHandler for the websocket.
|
||||
*/
|
||||
public void addMapping(PathSpec pathSpec, WebSocketNegotiator negotiator) throws WebSocketException
|
||||
{
|
||||
mappings.put(pathSpec, negotiator);
|
||||
}
|
||||
|
||||
public boolean removeMapping(PathSpec pathSpec)
|
||||
|
@ -193,7 +214,7 @@ public class WebSocketMappings implements Dumpable, LifeCycle.Listener
|
|||
*/
|
||||
public WebSocketNegotiator getMatchedNegotiator(String target, Consumer<PathSpec> pathSpecConsumer)
|
||||
{
|
||||
MappedResource<Negotiator> mapping = this.mappings.getMatch(target);
|
||||
MappedResource<WebSocketNegotiator> mapping = this.mappings.getMatch(target);
|
||||
if (mapping == null)
|
||||
return null;
|
||||
|
||||
|
@ -224,59 +245,6 @@ public class WebSocketMappings implements Dumpable, LifeCycle.Listener
|
|||
LOG.debug("WebSocket Negotiated detected on {} for endpoint {}", target, negotiator);
|
||||
|
||||
// We have an upgrade request
|
||||
return handshaker.upgradeRequest(negotiator, request, response, defaultCustomizer);
|
||||
}
|
||||
|
||||
private class Negotiator extends WebSocketNegotiator.AbstractNegotiator
|
||||
{
|
||||
private final WebSocketCreator creator;
|
||||
private final FrameHandlerFactory factory;
|
||||
|
||||
public Negotiator(WebSocketCreator creator, FrameHandlerFactory factory, Configuration.Customizer customizer)
|
||||
{
|
||||
super(components, customizer);
|
||||
this.creator = creator;
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
public WebSocketCreator getWebSocketCreator()
|
||||
{
|
||||
return creator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FrameHandler negotiate(Negotiation negotiation) throws IOException
|
||||
{
|
||||
ServletContext servletContext = negotiation.getRequest().getServletContext();
|
||||
if (servletContext == null)
|
||||
throw new IllegalStateException("null servletContext from request");
|
||||
|
||||
ServerUpgradeRequest upgradeRequest = new ServerUpgradeRequest(negotiation);
|
||||
ServerUpgradeResponse upgradeResponse = new ServerUpgradeResponse(negotiation);
|
||||
|
||||
AtomicReference<Object> result = new AtomicReference<>();
|
||||
((ContextHandler.Context)servletContext).getContextHandler().handle(() ->
|
||||
result.set(creator.createWebSocket(upgradeRequest, upgradeResponse)));
|
||||
Object websocketPojo = result.get();
|
||||
|
||||
// Handling for response forbidden (and similar paths)
|
||||
if (upgradeResponse.isCommitted())
|
||||
return null;
|
||||
|
||||
if (websocketPojo == null)
|
||||
{
|
||||
// no creation, sorry
|
||||
upgradeResponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "WebSocket Endpoint Creation Refused");
|
||||
return null;
|
||||
}
|
||||
|
||||
return factory.newFrameHandler(websocketPojo, upgradeRequest, upgradeResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("%s@%x{%s,%s,%s}", getClass().getSimpleName(), hashCode(), creator, factory, getCustomizer());
|
||||
}
|
||||
return handshaker.upgradeRequest(negotiator, request, response, components, defaultCustomizer);
|
||||
}
|
||||
}
|
|
@ -33,9 +33,8 @@ import org.eclipse.jetty.http.QuotedCSV;
|
|||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.websocket.core.ExtensionConfig;
|
||||
import org.eclipse.jetty.websocket.core.WebSocketComponents;
|
||||
import org.eclipse.jetty.websocket.core.internal.ExtensionStack;
|
||||
|
||||
public abstract class Negotiation
|
||||
public abstract class WebSocketNegotiation
|
||||
{
|
||||
private final Request baseRequest;
|
||||
private final HttpServletRequest request;
|
||||
|
@ -45,10 +44,9 @@ public abstract class Negotiation
|
|||
private List<ExtensionConfig> offeredExtensions;
|
||||
private List<ExtensionConfig> negotiatedExtensions;
|
||||
private List<String> offeredProtocols;
|
||||
private ExtensionStack extensionStack;
|
||||
private String protocol;
|
||||
|
||||
public Negotiation(Request baseRequest, HttpServletRequest request, HttpServletResponse response, WebSocketComponents webSocketComponents)
|
||||
public WebSocketNegotiation(Request baseRequest, HttpServletRequest request, HttpServletResponse response, WebSocketComponents webSocketComponents)
|
||||
{
|
||||
this.baseRequest = baseRequest;
|
||||
this.request = request;
|
||||
|
@ -180,7 +178,6 @@ public abstract class Negotiation
|
|||
if (extensions == offeredExtensions)
|
||||
return;
|
||||
negotiatedExtensions = extensions;
|
||||
extensionStack = null;
|
||||
}
|
||||
|
||||
@Override
|
|
@ -21,77 +21,41 @@ package org.eclipse.jetty.websocket.core.server;
|
|||
import java.io.IOException;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.util.DecoratedObjectFactory;
|
||||
import org.eclipse.jetty.websocket.core.Configuration;
|
||||
import org.eclipse.jetty.websocket.core.FrameHandler;
|
||||
import org.eclipse.jetty.websocket.core.WebSocketComponents;
|
||||
import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry;
|
||||
|
||||
public interface WebSocketNegotiator extends Configuration.Customizer
|
||||
{
|
||||
FrameHandler negotiate(Negotiation negotiation) throws IOException;
|
||||
FrameHandler negotiate(WebSocketNegotiation negotiation) throws IOException;
|
||||
|
||||
WebSocketExtensionRegistry getExtensionRegistry();
|
||||
|
||||
DecoratedObjectFactory getObjectFactory();
|
||||
|
||||
ByteBufferPool getByteBufferPool();
|
||||
|
||||
WebSocketComponents getWebSocketComponents();
|
||||
|
||||
static WebSocketNegotiator from(Function<Negotiation, FrameHandler> negotiate)
|
||||
static WebSocketNegotiator from(Function<WebSocketNegotiation, FrameHandler> negotiate)
|
||||
{
|
||||
return new AbstractNegotiator()
|
||||
return from(negotiate, null);
|
||||
}
|
||||
|
||||
static WebSocketNegotiator from(Function<WebSocketNegotiation, FrameHandler> negotiate, Configuration.Customizer customizer)
|
||||
{
|
||||
return new AbstractNegotiator(customizer)
|
||||
{
|
||||
@Override
|
||||
public FrameHandler negotiate(Negotiation negotiation)
|
||||
public FrameHandler negotiate(WebSocketNegotiation negotiation)
|
||||
{
|
||||
return negotiate.apply(negotiation);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static WebSocketNegotiator from(Function<Negotiation, FrameHandler> negotiate, Configuration.Customizer customizer)
|
||||
abstract class AbstractNegotiator extends Configuration.ConfigurationCustomizer implements WebSocketNegotiator
|
||||
{
|
||||
return new AbstractNegotiator(null, customizer)
|
||||
{
|
||||
@Override
|
||||
public FrameHandler negotiate(Negotiation negotiation)
|
||||
{
|
||||
return negotiate.apply(negotiation);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static WebSocketNegotiator from(
|
||||
Function<Negotiation, FrameHandler> negotiate,
|
||||
WebSocketComponents components,
|
||||
Configuration.Customizer customizer)
|
||||
{
|
||||
return new AbstractNegotiator(components, customizer)
|
||||
{
|
||||
@Override
|
||||
public FrameHandler negotiate(Negotiation negotiation)
|
||||
{
|
||||
return negotiate.apply(negotiation);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
abstract class AbstractNegotiator implements WebSocketNegotiator
|
||||
{
|
||||
final WebSocketComponents components;
|
||||
final Configuration.Customizer customizer;
|
||||
|
||||
public AbstractNegotiator()
|
||||
{
|
||||
this(null, null);
|
||||
this(null);
|
||||
}
|
||||
|
||||
public AbstractNegotiator(WebSocketComponents components, Configuration.Customizer customizer)
|
||||
public AbstractNegotiator(Configuration.Customizer customizer)
|
||||
{
|
||||
this.components = components == null ? new WebSocketComponents() : components;
|
||||
this.customizer = customizer;
|
||||
}
|
||||
|
||||
|
@ -100,35 +64,7 @@ public interface WebSocketNegotiator extends Configuration.Customizer
|
|||
{
|
||||
if (customizer != null)
|
||||
customizer.customize(configurable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebSocketExtensionRegistry getExtensionRegistry()
|
||||
{
|
||||
return components.getExtensionRegistry();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DecoratedObjectFactory getObjectFactory()
|
||||
{
|
||||
return components.getObjectFactory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBufferPool getByteBufferPool()
|
||||
{
|
||||
return components.getBufferPool();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebSocketComponents getWebSocketComponents()
|
||||
{
|
||||
return components;
|
||||
}
|
||||
|
||||
public Configuration.Customizer getCustomizer()
|
||||
{
|
||||
return customizer;
|
||||
super.customize(configurable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,65 +19,46 @@
|
|||
package org.eclipse.jetty.websocket.core.server;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.http.pathmap.PathSpecSet;
|
||||
import org.eclipse.jetty.http.pathmap.PathSpec;
|
||||
import org.eclipse.jetty.http.pathmap.ServletPathSpec;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.handler.HandlerWrapper;
|
||||
import org.eclipse.jetty.websocket.core.FrameHandler;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.eclipse.jetty.websocket.core.Configuration;
|
||||
import org.eclipse.jetty.websocket.core.WebSocketComponents;
|
||||
|
||||
public class WebSocketUpgradeHandler extends HandlerWrapper
|
||||
{
|
||||
private static final Logger LOG = LoggerFactory.getLogger(WebSocketUpgradeHandler.class);
|
||||
final Handshaker handshaker = Handshaker.newInstance();
|
||||
final PathSpecSet paths = new PathSpecSet();
|
||||
final WebSocketNegotiator negotiator;
|
||||
private final WebSocketMappings mappings;
|
||||
private final Configuration.ConfigurationCustomizer customizer = new Configuration.ConfigurationCustomizer();
|
||||
|
||||
public WebSocketUpgradeHandler(
|
||||
Function<Negotiation, FrameHandler> negotiate,
|
||||
String... pathSpecs)
|
||||
public WebSocketUpgradeHandler()
|
||||
{
|
||||
this(WebSocketNegotiator.from(negotiate), pathSpecs);
|
||||
this(new WebSocketComponents());
|
||||
}
|
||||
|
||||
public WebSocketUpgradeHandler(WebSocketNegotiator negotiator, String... pathSpecs)
|
||||
public WebSocketUpgradeHandler(WebSocketComponents components)
|
||||
{
|
||||
this.negotiator = Objects.requireNonNull(negotiator);
|
||||
addPathSpec(pathSpecs);
|
||||
this.mappings = new WebSocketMappings(components);
|
||||
}
|
||||
|
||||
public WebSocketNegotiator getWebSocketNegotiator()
|
||||
public void addMapping(String pathSpec, WebSocketNegotiator negotiator)
|
||||
{
|
||||
return negotiator;
|
||||
mappings.addMapping(new ServletPathSpec(pathSpec), negotiator);
|
||||
}
|
||||
|
||||
public void addPathSpec(String... pathSpecs)
|
||||
public void addMapping(PathSpec pathSpec, WebSocketNegotiator negotiator)
|
||||
{
|
||||
if (pathSpecs != null)
|
||||
{
|
||||
for (String spec : pathSpecs)
|
||||
{
|
||||
this.paths.add(spec);
|
||||
}
|
||||
}
|
||||
mappings.addMapping(pathSpec, negotiator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
if (!paths.isEmpty() && !paths.test(target))
|
||||
{
|
||||
super.handle(target, baseRequest, request, response);
|
||||
return;
|
||||
}
|
||||
|
||||
if (handshaker.upgradeRequest(negotiator, request, response, null))
|
||||
if (mappings.upgrade(request, response, customizer))
|
||||
return;
|
||||
|
||||
if (!baseRequest.isHandled())
|
||||
|
|
|
@ -47,8 +47,7 @@ import org.eclipse.jetty.websocket.core.internal.ExtensionStack;
|
|||
import org.eclipse.jetty.websocket.core.internal.Negotiated;
|
||||
import org.eclipse.jetty.websocket.core.internal.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession;
|
||||
import org.eclipse.jetty.websocket.core.server.Handshaker;
|
||||
import org.eclipse.jetty.websocket.core.server.Negotiation;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiation;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -59,13 +58,12 @@ public abstract class AbstractHandshaker implements Handshaker
|
|||
private static final HttpField SERVER_VERSION = new PreEncodedHttpField(HttpHeader.SERVER, HttpConfiguration.SERVER_VERSION);
|
||||
|
||||
@Override
|
||||
public boolean upgradeRequest(WebSocketNegotiator negotiator, HttpServletRequest request, HttpServletResponse response, Configuration.Customizer defaultCustomizer) throws IOException
|
||||
public boolean upgradeRequest(WebSocketNegotiator negotiator, HttpServletRequest request, HttpServletResponse response, WebSocketComponents components, Configuration.Customizer defaultCustomizer) throws IOException
|
||||
{
|
||||
if (!validateRequest(request))
|
||||
return false;
|
||||
|
||||
WebSocketComponents components = negotiator.getWebSocketComponents();
|
||||
Negotiation negotiation = newNegotiation(request, response, components);
|
||||
WebSocketNegotiation negotiation = newNegotiation(request, response, components);
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("negotiation {}", negotiation);
|
||||
negotiation.negotiate();
|
||||
|
@ -173,11 +171,11 @@ public abstract class AbstractHandshaker implements Handshaker
|
|||
|
||||
protected abstract boolean validateRequest(HttpServletRequest request);
|
||||
|
||||
protected abstract Negotiation newNegotiation(HttpServletRequest request, HttpServletResponse response, WebSocketComponents webSocketComponents);
|
||||
protected abstract WebSocketNegotiation newNegotiation(HttpServletRequest request, HttpServletResponse response, WebSocketComponents webSocketComponents);
|
||||
|
||||
protected abstract boolean validateFrameHandler(FrameHandler frameHandler, HttpServletResponse response);
|
||||
|
||||
protected boolean validateNegotiation(Negotiation negotiation)
|
||||
protected boolean validateNegotiation(WebSocketNegotiation negotiation)
|
||||
{
|
||||
if (!negotiation.validateHeaders())
|
||||
{
|
||||
|
@ -219,5 +217,5 @@ public abstract class AbstractHandshaker implements Handshaker
|
|||
return new WebSocketConnection(endPoint, executor, scheduler, byteBufferPool, coreSession);
|
||||
}
|
||||
|
||||
protected abstract void prepareResponse(Response response, Negotiation negotiation);
|
||||
protected abstract void prepareResponse(Response response, WebSocketNegotiation negotiation);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
|
||||
//
|
||||
// This program and the accompanying materials are made available under
|
||||
// the terms of the Eclipse Public License 2.0 which is available at
|
||||
// https://www.eclipse.org/legal/epl-2.0
|
||||
//
|
||||
// This Source Code may also be made available under the following
|
||||
// Secondary Licenses when the conditions for such availability set
|
||||
// forth in the Eclipse Public License, v. 2.0 are satisfied:
|
||||
// the Apache License v2.0 which is available at
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.core.server.internal;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
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
|
||||
{
|
||||
private final WebSocketCreator creator;
|
||||
private final FrameHandlerFactory factory;
|
||||
|
||||
public CreatorNegotiator(WebSocketCreator creator, FrameHandlerFactory factory, Customizer customizer)
|
||||
{
|
||||
super(customizer);
|
||||
this.creator = creator;
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
public WebSocketCreator getWebSocketCreator()
|
||||
{
|
||||
return creator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FrameHandler negotiate(WebSocketNegotiation negotiation) throws IOException
|
||||
{
|
||||
ServletContext servletContext = negotiation.getRequest().getServletContext();
|
||||
if (servletContext == null)
|
||||
throw new IllegalStateException("null servletContext from request");
|
||||
|
||||
ServerUpgradeRequest upgradeRequest = new ServerUpgradeRequest(negotiation);
|
||||
ServerUpgradeResponse upgradeResponse = new ServerUpgradeResponse(negotiation);
|
||||
|
||||
AtomicReference<Object> result = new AtomicReference<>();
|
||||
((ContextHandler.Context)servletContext).getContextHandler().handle(() ->
|
||||
result.set(creator.createWebSocket(upgradeRequest, upgradeResponse)));
|
||||
Object websocketPojo = result.get();
|
||||
|
||||
// Handling for response forbidden (and similar paths)
|
||||
if (upgradeResponse.isCommitted())
|
||||
return null;
|
||||
|
||||
if (websocketPojo == null)
|
||||
{
|
||||
// no creation, sorry
|
||||
upgradeResponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "WebSocket Endpoint Creation Refused");
|
||||
return null;
|
||||
}
|
||||
|
||||
return factory.newFrameHandler(websocketPojo, upgradeRequest, upgradeResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("%s@%x{%s,%s}", getClass().getSimpleName(), hashCode(), creator, factory);
|
||||
}
|
||||
}
|
|
@ -16,21 +16,17 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.core.server;
|
||||
package org.eclipse.jetty.websocket.core.server.internal;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.websocket.core.Configuration;
|
||||
import org.eclipse.jetty.websocket.core.server.internal.HandshakerSelector;
|
||||
import org.eclipse.jetty.websocket.core.WebSocketComponents;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
|
||||
|
||||
public interface Handshaker
|
||||
{
|
||||
static Handshaker newInstance()
|
||||
{
|
||||
return new HandshakerSelector();
|
||||
}
|
||||
|
||||
boolean upgradeRequest(WebSocketNegotiator negotiator, HttpServletRequest request, HttpServletResponse response, Configuration.Customizer defaultCustomizer) throws IOException;
|
||||
boolean upgradeRequest(WebSocketNegotiator negotiator, HttpServletRequest request, HttpServletResponse response, WebSocketComponents components, Configuration.Customizer defaultCustomizer) throws IOException;
|
||||
}
|
|
@ -23,7 +23,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.websocket.core.Configuration;
|
||||
import org.eclipse.jetty.websocket.core.server.Handshaker;
|
||||
import org.eclipse.jetty.websocket.core.WebSocketComponents;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
|
||||
|
||||
/**
|
||||
|
@ -37,10 +37,10 @@ public class HandshakerSelector implements Handshaker
|
|||
private final RFC8441Handshaker rfc8441 = new RFC8441Handshaker();
|
||||
|
||||
@Override
|
||||
public boolean upgradeRequest(WebSocketNegotiator negotiator, HttpServletRequest request, HttpServletResponse response, Configuration.Customizer defaultCustomizer) throws IOException
|
||||
public boolean upgradeRequest(WebSocketNegotiator negotiator, HttpServletRequest request, HttpServletResponse response, WebSocketComponents components, Configuration.Customizer defaultCustomizer) throws IOException
|
||||
{
|
||||
// Try HTTP/1.1 WS upgrade, if this fails try an HTTP/2 WS upgrade if no response was committed.
|
||||
return rfc6455.upgradeRequest(negotiator, request, response, defaultCustomizer) ||
|
||||
!response.isCommitted() && rfc8441.upgradeRequest(negotiator, request, response, defaultCustomizer);
|
||||
return rfc6455.upgradeRequest(negotiator, request, response, components, defaultCustomizer) ||
|
||||
!response.isCommitted() && rfc8441.upgradeRequest(negotiator, request, response, components, defaultCustomizer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ import org.eclipse.jetty.websocket.core.WebSocketComponents;
|
|||
import org.eclipse.jetty.websocket.core.internal.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.core.internal.WebSocketCore;
|
||||
import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession;
|
||||
import org.eclipse.jetty.websocket.core.server.Negotiation;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiation;
|
||||
|
||||
public final class RFC6455Handshaker extends AbstractHandshaker
|
||||
{
|
||||
|
@ -65,13 +65,13 @@ public final class RFC6455Handshaker extends AbstractHandshaker
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Negotiation newNegotiation(HttpServletRequest request, HttpServletResponse response, WebSocketComponents webSocketComponents)
|
||||
protected WebSocketNegotiation newNegotiation(HttpServletRequest request, HttpServletResponse response, WebSocketComponents webSocketComponents)
|
||||
{
|
||||
return new RFC6455Negotiation(Request.getBaseRequest(request), request, response, webSocketComponents);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean validateNegotiation(Negotiation negotiation)
|
||||
protected boolean validateNegotiation(WebSocketNegotiation negotiation)
|
||||
{
|
||||
boolean result = super.validateNegotiation(negotiation);
|
||||
if (!result)
|
||||
|
@ -103,7 +103,7 @@ public final class RFC6455Handshaker extends AbstractHandshaker
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void prepareResponse(Response response, Negotiation negotiation)
|
||||
protected void prepareResponse(Response response, WebSocketNegotiation negotiation)
|
||||
{
|
||||
response.setStatus(HttpServletResponse.SC_SWITCHING_PROTOCOLS);
|
||||
HttpFields.Mutable responseFields = response.getHttpFields();
|
||||
|
|
|
@ -27,9 +27,9 @@ import org.eclipse.jetty.http.HttpHeader;
|
|||
import org.eclipse.jetty.http.QuotedCSV;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.websocket.core.WebSocketComponents;
|
||||
import org.eclipse.jetty.websocket.core.server.Negotiation;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiation;
|
||||
|
||||
public class RFC6455Negotiation extends Negotiation
|
||||
public class RFC6455Negotiation extends WebSocketNegotiation
|
||||
{
|
||||
private boolean successful;
|
||||
private String key;
|
||||
|
|
|
@ -33,7 +33,7 @@ import org.eclipse.jetty.websocket.core.FrameHandler;
|
|||
import org.eclipse.jetty.websocket.core.WebSocketComponents;
|
||||
import org.eclipse.jetty.websocket.core.internal.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession;
|
||||
import org.eclipse.jetty.websocket.core.server.Negotiation;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiation;
|
||||
|
||||
public class RFC8441Handshaker extends AbstractHandshaker
|
||||
{
|
||||
|
@ -58,7 +58,7 @@ public class RFC8441Handshaker extends AbstractHandshaker
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Negotiation newNegotiation(HttpServletRequest request, HttpServletResponse response, WebSocketComponents webSocketComponents)
|
||||
protected WebSocketNegotiation newNegotiation(HttpServletRequest request, HttpServletResponse response, WebSocketComponents webSocketComponents)
|
||||
{
|
||||
return new RFC8441Negotiation(Request.getBaseRequest(request), request, response, webSocketComponents);
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ public class RFC8441Handshaker extends AbstractHandshaker
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void prepareResponse(Response response, Negotiation negotiation)
|
||||
protected void prepareResponse(Response response, WebSocketNegotiation negotiation)
|
||||
{
|
||||
response.setStatus(HttpStatus.OK_200);
|
||||
}
|
||||
|
|
|
@ -25,9 +25,9 @@ import org.eclipse.jetty.http.BadMessageException;
|
|||
import org.eclipse.jetty.http.MetaData;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.websocket.core.WebSocketComponents;
|
||||
import org.eclipse.jetty.websocket.core.server.Negotiation;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiation;
|
||||
|
||||
public class RFC8441Negotiation extends Negotiation
|
||||
public class RFC8441Negotiation extends WebSocketNegotiation
|
||||
{
|
||||
public RFC8441Negotiation(Request baseRequest, HttpServletRequest request, HttpServletResponse response, WebSocketComponents components) throws BadMessageException
|
||||
{
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util.server.internal;
|
||||
package org.eclipse.jetty.websocket.core.server.internal;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.net.InetSocketAddress;
|
|
@ -29,6 +29,11 @@ public class EchoFrameHandler extends TestAsyncFrameHandler
|
|||
throwOnFrame = true;
|
||||
}
|
||||
|
||||
public EchoFrameHandler()
|
||||
{
|
||||
super(EchoFrameHandler.class.getName());
|
||||
}
|
||||
|
||||
public EchoFrameHandler(String name)
|
||||
{
|
||||
super(name);
|
||||
|
@ -48,7 +53,7 @@ public class EchoFrameHandler extends TestAsyncFrameHandler
|
|||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("[{}] echoDataFrame {}", name, frame);
|
||||
Frame echo = Frame.copy(frame).setMask(null);
|
||||
Frame echo = new Frame(frame.getOpCode(), frame.isFin(), frame.getPayload());
|
||||
coreSession.sendFrame(echo, callback, false);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -48,7 +48,7 @@ public class FlushTest
|
|||
@BeforeEach
|
||||
public void startup() throws Exception
|
||||
{
|
||||
WebSocketNegotiator negotiator = WebSocketNegotiator.from((negotiation) -> serverHandler);
|
||||
WebSocketNegotiator negotiator = new TestWebSocketNegotiator(serverHandler);
|
||||
server = new WebSocketServer(negotiator);
|
||||
client = new WebSocketCoreClient(null, components);
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ public class FrameBufferTest extends WebSocketTester
|
|||
@BeforeEach
|
||||
public void startup() throws Exception
|
||||
{
|
||||
WebSocketNegotiator negotiator = WebSocketNegotiator.from((negotiation) -> serverHandler);
|
||||
WebSocketNegotiator negotiator = new TestWebSocketNegotiator(serverHandler);
|
||||
server = new WebSocketServer(negotiator);
|
||||
client = new WebSocketCoreClient(null, components);
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.eclipse.jetty.util.Callback;
|
|||
import org.eclipse.jetty.util.FutureCallback;
|
||||
import org.eclipse.jetty.websocket.core.exception.BadPayloadException;
|
||||
import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException;
|
||||
import org.eclipse.jetty.websocket.core.internal.MessageHandler;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.concurrent.CountDownLatch;
|
|||
|
||||
import org.eclipse.jetty.util.BlockingArrayQueue;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.websocket.core.internal.MessageHandler;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
|
||||
//
|
||||
// This program and the accompanying materials are made available under
|
||||
// the terms of the Eclipse Public License 2.0 which is available at
|
||||
// https://www.eclipse.org/legal/epl-2.0
|
||||
//
|
||||
// This Source Code may also be made available under the following
|
||||
// Secondary Licenses when the conditions for such availability set
|
||||
// forth in the Eclipse Public License, v. 2.0 are satisfied:
|
||||
// the Apache License v2.0 which is available at
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.core;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketUpgradeHandler;
|
||||
|
||||
public class TestUpgradeHandler extends WebSocketUpgradeHandler
|
||||
{
|
||||
public TestUpgradeHandler(WebSocketNegotiator negotiator)
|
||||
{
|
||||
super(negotiator);
|
||||
setHandler(new AbstractHandler()
|
||||
{
|
||||
@Override
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
|
||||
throws IOException, ServletException
|
||||
{
|
||||
response.setStatus(200);
|
||||
response.setContentType("text/plain");
|
||||
response.getOutputStream().println("Test WS Upgrade Handler!");
|
||||
baseRequest.setHandled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -21,29 +21,26 @@ package org.eclipse.jetty.websocket.core;
|
|||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.util.DecoratedObjectFactory;
|
||||
import org.eclipse.jetty.websocket.core.server.Negotiation;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiation;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
|
||||
|
||||
public class TestWebSocketNegotiator implements WebSocketNegotiator
|
||||
public class TestWebSocketNegotiator extends WebSocketNegotiator.AbstractNegotiator
|
||||
{
|
||||
final WebSocketComponents components;
|
||||
private final FrameHandler frameHandler;
|
||||
|
||||
public TestWebSocketNegotiator(FrameHandler frameHandler)
|
||||
{
|
||||
this (frameHandler, new WebSocketComponents());
|
||||
this(frameHandler, null);
|
||||
}
|
||||
|
||||
public TestWebSocketNegotiator(FrameHandler frameHandler, WebSocketComponents components)
|
||||
public TestWebSocketNegotiator(FrameHandler frameHandler, Configuration.Customizer customizer)
|
||||
{
|
||||
this.components = components;
|
||||
super(customizer);
|
||||
this.frameHandler = frameHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FrameHandler negotiate(Negotiation negotiation) throws IOException
|
||||
public FrameHandler negotiate(WebSocketNegotiation negotiation) throws IOException
|
||||
{
|
||||
List<String> offeredSubprotocols = negotiation.getOfferedSubprotocols();
|
||||
if (!offeredSubprotocols.isEmpty())
|
||||
|
@ -51,33 +48,4 @@ public class TestWebSocketNegotiator implements WebSocketNegotiator
|
|||
|
||||
return frameHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customize(Configuration configurable)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebSocketExtensionRegistry getExtensionRegistry()
|
||||
{
|
||||
return components.getExtensionRegistry();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DecoratedObjectFactory getObjectFactory()
|
||||
{
|
||||
return components.getObjectFactory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBufferPool getByteBufferPool()
|
||||
{
|
||||
return components.getBufferPool();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebSocketComponents getWebSocketComponents()
|
||||
{
|
||||
return components;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
|
||||
//
|
||||
// This program and the accompanying materials are made available under
|
||||
// the terms of the Eclipse Public License 2.0 which is available at
|
||||
// https://www.eclipse.org/legal/epl-2.0
|
||||
//
|
||||
// This Source Code may also be made available under the following
|
||||
// Secondary Licenses when the conditions for such availability set
|
||||
// forth in the Eclipse Public License, v. 2.0 are satisfied:
|
||||
// the Apache License v2.0 which is available at
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.core;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketUpgradeHandler;
|
||||
|
||||
public class TestWebSocketUpgradeHandler extends WebSocketUpgradeHandler
|
||||
{
|
||||
public TestWebSocketUpgradeHandler(WebSocketNegotiator negotiator)
|
||||
{
|
||||
super(negotiator);
|
||||
|
||||
setHandler(new AbstractHandler()
|
||||
{
|
||||
@Override
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
|
||||
throws IOException, ServletException
|
||||
{
|
||||
response.setStatus(200);
|
||||
response.setContentType("text/plain");
|
||||
response.getOutputStream().println("Hello World!");
|
||||
baseRequest.setHandled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -42,7 +42,7 @@ import org.eclipse.jetty.websocket.core.client.UpgradeListener;
|
|||
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
|
||||
import org.eclipse.jetty.websocket.core.exception.UpgradeException;
|
||||
import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession;
|
||||
import org.eclipse.jetty.websocket.core.server.Negotiation;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiation;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
@ -81,10 +81,10 @@ public class WebSocketNegotiationTest extends WebSocketTester
|
|||
@BeforeEach
|
||||
public void startup() throws Exception
|
||||
{
|
||||
WebSocketNegotiator negotiator = new WebSocketNegotiator.AbstractNegotiator(components, null)
|
||||
WebSocketNegotiator negotiator = new WebSocketNegotiator.AbstractNegotiator()
|
||||
{
|
||||
@Override
|
||||
public FrameHandler negotiate(Negotiation negotiation) throws IOException
|
||||
public FrameHandler negotiate(WebSocketNegotiation negotiation) throws IOException
|
||||
{
|
||||
if (negotiation.getOfferedSubprotocols().isEmpty())
|
||||
{
|
||||
|
@ -127,7 +127,7 @@ public class WebSocketNegotiationTest extends WebSocketTester
|
|||
}
|
||||
};
|
||||
|
||||
server = new WebSocketServer(negotiator);
|
||||
server = new WebSocketServer(components, negotiator, false);
|
||||
client = new WebSocketCoreClient(null, components);
|
||||
|
||||
server.start();
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.eclipse.jetty.server.Server;
|
|||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
import org.eclipse.jetty.websocket.core.server.Negotiation;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiation;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketUpgradeHandler;
|
||||
|
||||
|
@ -73,6 +73,11 @@ public class WebSocketServer
|
|||
}
|
||||
|
||||
public WebSocketServer(WebSocketNegotiator negotiator, boolean tls)
|
||||
{
|
||||
this(new WebSocketComponents(), negotiator, tls);
|
||||
}
|
||||
|
||||
public WebSocketServer(WebSocketComponents components, WebSocketNegotiator negotiator, boolean tls)
|
||||
{
|
||||
ServerConnector connector;
|
||||
if (tls)
|
||||
|
@ -84,7 +89,8 @@ public class WebSocketServer
|
|||
ContextHandler context = new ContextHandler("/");
|
||||
server.setHandler(context);
|
||||
|
||||
WebSocketUpgradeHandler upgradeHandler = new WebSocketUpgradeHandler(negotiator);
|
||||
WebSocketUpgradeHandler upgradeHandler = new WebSocketUpgradeHandler(components);
|
||||
upgradeHandler.addMapping("/*", negotiator);
|
||||
context.setHandler(upgradeHandler);
|
||||
}
|
||||
|
||||
|
@ -111,7 +117,7 @@ public class WebSocketServer
|
|||
}
|
||||
|
||||
@Override
|
||||
public FrameHandler negotiate(Negotiation negotiation) throws IOException
|
||||
public FrameHandler negotiate(WebSocketNegotiation negotiation) throws IOException
|
||||
{
|
||||
List<String> offeredSubprotocols = negotiation.getOfferedSubprotocols();
|
||||
if (!offeredSubprotocols.isEmpty())
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
|
||||
//
|
||||
// This program and the accompanying materials are made available under
|
||||
// the terms of the Eclipse Public License 2.0 which is available at
|
||||
// https://www.eclipse.org/legal/epl-2.0
|
||||
//
|
||||
// This Source Code may also be made available under the following
|
||||
// Secondary Licenses when the conditions for such availability set
|
||||
// forth in the Eclipse Public License, v. 2.0 are satisfied:
|
||||
// the Apache License v2.0 which is available at
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.core;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketUpgradeHandler;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class WebSocketUpgradeHandlerTest
|
||||
{
|
||||
private Server server;
|
||||
private WebSocketCoreClient client;
|
||||
private URI serverUri;
|
||||
|
||||
@BeforeEach
|
||||
public void before() throws Exception
|
||||
{
|
||||
server = new Server();
|
||||
ServerConnector connector = new ServerConnector(server);
|
||||
server.addConnector(connector);
|
||||
|
||||
WebSocketUpgradeHandler upgradeHandler = new WebSocketUpgradeHandler();
|
||||
upgradeHandler.addMapping("/path/echo", new TestWebSocketNegotiator(new EchoFrameHandler()));
|
||||
server.setHandler(upgradeHandler);
|
||||
server.start();
|
||||
|
||||
client = new WebSocketCoreClient();
|
||||
client.start();
|
||||
|
||||
serverUri = URI.create("ws://localhost:" + connector.getLocalPort());
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void after() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
client.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpgradeByWebSocketUpgradeHandler() throws Exception
|
||||
{
|
||||
TestMessageHandler clientEndpoint = new TestMessageHandler();
|
||||
CoreSession coreSession = client.connect(clientEndpoint, serverUri.resolve("/path/echo")).get(5, TimeUnit.SECONDS);
|
||||
assertNotNull(coreSession);
|
||||
coreSession.close(Callback.NOOP);
|
||||
assertTrue(clientEndpoint.closeLatch.await(5, TimeUnit.SECONDS));
|
||||
}
|
||||
}
|
|
@ -52,14 +52,12 @@ import org.testcontainers.junit.jupiter.Testcontainers;
|
|||
import org.testcontainers.utility.DockerImageName;
|
||||
import org.testcontainers.utility.DockerStatus;
|
||||
import org.testcontainers.utility.MountableFile;
|
||||
import org.testcontainers.utility.TestcontainersConfiguration;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@Testcontainers
|
||||
public class AutobahnTests
|
||||
{
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AutobahnTests.class);
|
||||
private static final Path USER_DIR = Paths.get(System.getProperty("user.dir"));
|
||||
|
||||
|
|
|
@ -28,10 +28,10 @@ import org.eclipse.jetty.util.Callback;
|
|||
import org.eclipse.jetty.util.Jetty;
|
||||
import org.eclipse.jetty.util.UrlEncoded;
|
||||
import org.eclipse.jetty.websocket.core.CoreSession;
|
||||
import org.eclipse.jetty.websocket.core.MessageHandler;
|
||||
import org.eclipse.jetty.websocket.core.TestMessageHandler;
|
||||
import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
|
||||
import org.eclipse.jetty.websocket.core.internal.MessageHandler;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@ package org.eclipse.jetty.websocket.core.autobahn;
|
|||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.websocket.core.TestWebSocketNegotiator;
|
||||
import org.eclipse.jetty.websocket.core.WebSocketComponents;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketUpgradeHandler;
|
||||
|
||||
/**
|
||||
|
@ -78,9 +80,11 @@ public class CoreAutobahnServer
|
|||
ContextHandler context = new ContextHandler("/");
|
||||
server.setHandler(context);
|
||||
|
||||
WebSocketUpgradeHandler handler = new WebSocketUpgradeHandler((neg) -> new AutobahnFrameHandler());
|
||||
context.setHandler(handler);
|
||||
WebSocketComponents components = new WebSocketComponents();
|
||||
WebSocketUpgradeHandler handler = new WebSocketUpgradeHandler(components);
|
||||
handler.addMapping("/*", new TestWebSocketNegotiator(new AutobahnFrameHandler()));
|
||||
|
||||
context.setHandler(handler);
|
||||
server.start();
|
||||
return server;
|
||||
}
|
||||
|
|
|
@ -28,9 +28,9 @@ import java.util.regex.Matcher;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.websocket.core.MessageHandler;
|
||||
import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
|
||||
import org.eclipse.jetty.websocket.core.internal.MessageHandler;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import javax.servlet.ServletException;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.http.pathmap.ServletPathSpec;
|
||||
import org.eclipse.jetty.server.HttpConnectionFactory;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
|
@ -36,18 +37,23 @@ import org.eclipse.jetty.util.Callback;
|
|||
import org.eclipse.jetty.websocket.core.CloseStatus;
|
||||
import org.eclipse.jetty.websocket.core.CoreSession;
|
||||
import org.eclipse.jetty.websocket.core.FrameHandler;
|
||||
import org.eclipse.jetty.websocket.core.MessageHandler;
|
||||
import org.eclipse.jetty.websocket.core.server.Negotiation;
|
||||
import org.eclipse.jetty.websocket.core.WebSocketComponents;
|
||||
import org.eclipse.jetty.websocket.core.internal.MessageHandler;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiation;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketUpgradeHandler;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static org.eclipse.jetty.util.Callback.NOOP;
|
||||
|
||||
public class ChatWebSocketServer
|
||||
{
|
||||
protected static final Logger LOG = LoggerFactory.getLogger(ChatWebSocketServer.class);
|
||||
|
||||
private final Set<MessageHandler> members = new HashSet<>();
|
||||
|
||||
private FrameHandler negotiate(Negotiation negotiation)
|
||||
private FrameHandler negotiate(WebSocketNegotiation negotiation)
|
||||
{
|
||||
// Finalize negotiations in API layer involves:
|
||||
// + MAY mutate the policy
|
||||
|
@ -113,7 +119,9 @@ public class ChatWebSocketServer
|
|||
server.setHandler(context);
|
||||
|
||||
ChatWebSocketServer chat = new ChatWebSocketServer();
|
||||
WebSocketUpgradeHandler upgradeHandler = new WebSocketUpgradeHandler(WebSocketNegotiator.from(chat::negotiate));
|
||||
WebSocketComponents components = new WebSocketComponents();
|
||||
WebSocketUpgradeHandler upgradeHandler = new WebSocketUpgradeHandler(components);
|
||||
upgradeHandler.addMapping(new ServletPathSpec("/*"), WebSocketNegotiator.from(chat::negotiate));
|
||||
context.setHandler(upgradeHandler);
|
||||
|
||||
upgradeHandler.setHandler(new AbstractHandler()
|
||||
|
|
|
@ -41,7 +41,7 @@ import org.eclipse.jetty.websocket.core.WebSocketServer;
|
|||
import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.core.client.UpgradeListener;
|
||||
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
|
||||
import org.eclipse.jetty.websocket.core.server.Negotiation;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiation;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
@ -69,7 +69,7 @@ public class PerMessageDeflaterBufferSizeTest
|
|||
int inflateBufferSize = -1;
|
||||
|
||||
@Override
|
||||
public FrameHandler negotiate(Negotiation negotiation) throws IOException
|
||||
public FrameHandler negotiate(WebSocketNegotiation negotiation) throws IOException
|
||||
{
|
||||
for (ExtensionConfig extensionConfig : negotiation.getOfferedExtensions())
|
||||
{
|
||||
|
|
|
@ -35,7 +35,7 @@ import org.eclipse.jetty.websocket.core.TestFrameHandler;
|
|||
import org.eclipse.jetty.websocket.core.TestWebSocketNegotiator;
|
||||
import org.eclipse.jetty.websocket.core.WebSocketServer;
|
||||
import org.eclipse.jetty.websocket.core.WebSocketTester;
|
||||
import org.eclipse.jetty.websocket.core.server.Negotiation;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiation;
|
||||
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
@ -58,7 +58,7 @@ public class ValidationExtensionTest extends WebSocketTester
|
|||
WebSocketNegotiator negotiator = new TestWebSocketNegotiator(serverHandler)
|
||||
{
|
||||
@Override
|
||||
public FrameHandler negotiate(Negotiation negotiation) throws IOException
|
||||
public FrameHandler negotiate(WebSocketNegotiation negotiation) throws IOException
|
||||
{
|
||||
List<ExtensionConfig> negotiatedExtensions = new ArrayList<>();
|
||||
negotiatedExtensions.add(ExtensionConfig.parse(
|
||||
|
|
|
@ -99,7 +99,7 @@ class WebSocketProxy
|
|||
break;
|
||||
|
||||
default:
|
||||
failure = new IllegalStateException();
|
||||
failure = new IllegalStateException(state.name());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ class WebSocketProxy
|
|||
break;
|
||||
|
||||
default:
|
||||
failure = new IllegalStateException();
|
||||
failure = new IllegalStateException(state.name());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ class WebSocketProxy
|
|||
break;
|
||||
|
||||
default:
|
||||
failure = new IllegalStateException();
|
||||
failure = new IllegalStateException(state.name());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ class WebSocketProxy
|
|||
break;
|
||||
|
||||
default:
|
||||
failure = new IllegalStateException();
|
||||
failure = new IllegalStateException(state.name());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -333,7 +333,7 @@ class WebSocketProxy
|
|||
break;
|
||||
|
||||
default:
|
||||
failure = new IllegalStateException();
|
||||
failure = new IllegalStateException(state.name());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -406,7 +406,7 @@ class WebSocketProxy
|
|||
|
||||
default:
|
||||
state = State.FAILED;
|
||||
error = new IllegalStateException();
|
||||
error = new IllegalStateException(state.name());
|
||||
failure = error;
|
||||
break;
|
||||
}
|
||||
|
@ -435,7 +435,7 @@ class WebSocketProxy
|
|||
|
||||
default:
|
||||
state = State.FAILED;
|
||||
error = new IllegalStateException();
|
||||
error = new IllegalStateException(state.name());
|
||||
failure = error;
|
||||
break;
|
||||
}
|
||||
|
@ -468,7 +468,7 @@ class WebSocketProxy
|
|||
|
||||
default:
|
||||
state = State.FAILED;
|
||||
error = new IllegalStateException();
|
||||
error = new IllegalStateException(state.name());
|
||||
failure = error;
|
||||
break;
|
||||
}
|
||||
|
@ -498,7 +498,7 @@ class WebSocketProxy
|
|||
break;
|
||||
|
||||
default:
|
||||
failure = new IllegalStateException();
|
||||
failure = new IllegalStateException(state.name());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -541,7 +541,7 @@ class WebSocketProxy
|
|||
break;
|
||||
|
||||
default:
|
||||
failure = new IllegalStateException();
|
||||
failure = new IllegalStateException(state.name());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -671,7 +671,7 @@ class WebSocketProxy
|
|||
break;
|
||||
|
||||
default:
|
||||
failure = new IllegalStateException();
|
||||
failure = new IllegalStateException(state.name());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,11 +21,11 @@ package org.eclipse.jetty.websocket.core.proxy;
|
|||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.time.Duration;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
@ -45,6 +45,7 @@ import org.eclipse.jetty.websocket.core.EchoFrameHandler;
|
|||
import org.eclipse.jetty.websocket.core.Frame;
|
||||
import org.eclipse.jetty.websocket.core.OpCode;
|
||||
import org.eclipse.jetty.websocket.core.TestAsyncFrameHandler;
|
||||
import org.eclipse.jetty.websocket.core.TestWebSocketNegotiator;
|
||||
import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
|
||||
import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession;
|
||||
|
@ -58,23 +59,22 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
|||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class WebSocketProxyTest
|
||||
{
|
||||
// Port chosen to (hopefully) not conflict with existing servers on your test machine.
|
||||
// So don't choose ports like 8080, 9090, 8888, etc.
|
||||
private static final int PROXY_PORT = 49999;
|
||||
private Server _server;
|
||||
private WebSocketCoreClient _client;
|
||||
private WebSocketProxy proxy;
|
||||
private EchoFrameHandler serverFrameHandler;
|
||||
private TestHandler testHandler;
|
||||
Configuration.ConfigurationCustomizer defaultCustomizer;
|
||||
private Configuration.ConfigurationCustomizer defaultCustomizer;
|
||||
private URI proxyUri;
|
||||
|
||||
private class TestHandler extends AbstractHandler
|
||||
private static class TestHandler extends AbstractHandler
|
||||
{
|
||||
public void blockServerUpgradeRequests()
|
||||
{
|
||||
|
@ -84,7 +84,7 @@ public class WebSocketProxyTest
|
|||
public boolean blockServerUpgradeRequests = false;
|
||||
|
||||
@Override
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
|
||||
{
|
||||
if (baseRequest.getHeader("Upgrade") != null)
|
||||
{
|
||||
|
@ -102,7 +102,6 @@ public class WebSocketProxyTest
|
|||
{
|
||||
_server = new Server();
|
||||
ServerConnector connector = new ServerConnector(_server);
|
||||
connector.setPort(PROXY_PORT);
|
||||
_server.addConnector(connector);
|
||||
|
||||
HandlerList handlers = new HandlerList();
|
||||
|
@ -114,24 +113,27 @@ public class WebSocketProxyTest
|
|||
|
||||
ContextHandler serverContext = new ContextHandler("/server");
|
||||
serverFrameHandler = new EchoFrameHandler("SERVER");
|
||||
WebSocketNegotiator negotiator = WebSocketNegotiator.from((negotiation) -> serverFrameHandler, defaultCustomizer);
|
||||
WebSocketUpgradeHandler upgradeHandler = new WebSocketUpgradeHandler(negotiator);
|
||||
WebSocketNegotiator negotiator = new TestWebSocketNegotiator(serverFrameHandler, defaultCustomizer);
|
||||
WebSocketUpgradeHandler upgradeHandler = new WebSocketUpgradeHandler();
|
||||
upgradeHandler.addMapping("/*", negotiator);
|
||||
serverContext.setHandler(upgradeHandler);
|
||||
handlers.addHandler(serverContext);
|
||||
|
||||
_client = new WebSocketCoreClient();
|
||||
_client.start();
|
||||
URI uri = new URI("ws://localhost:" + PROXY_PORT + "/server/");
|
||||
|
||||
ContextHandler proxyContext = new ContextHandler("/proxy");
|
||||
proxy = new WebSocketProxy(_client, uri);
|
||||
negotiator = WebSocketNegotiator.from((negotiation) -> proxy.client2Proxy, defaultCustomizer);
|
||||
upgradeHandler = new WebSocketUpgradeHandler(negotiator);
|
||||
negotiator = WebSocketNegotiator.from(negotiation -> proxy.client2Proxy, defaultCustomizer);
|
||||
upgradeHandler = new WebSocketUpgradeHandler();
|
||||
upgradeHandler.addMapping("/*", negotiator);
|
||||
proxyContext.setHandler(upgradeHandler);
|
||||
handlers.addHandler(proxyContext);
|
||||
|
||||
_server.setHandler(handlers);
|
||||
_server.start();
|
||||
_client = new WebSocketCoreClient();
|
||||
_client.start();
|
||||
|
||||
URI uri = new URI("ws://localhost:" + connector.getLocalPort());
|
||||
proxyUri = uri.resolve("/proxy");
|
||||
proxy = new WebSocketProxy(_client, uri.resolve("/server"));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
|
@ -144,14 +146,10 @@ public class WebSocketProxyTest
|
|||
public void awaitProxyClose(WebSocketProxy.Client2Proxy client2Proxy, WebSocketProxy.Server2Proxy server2Proxy) throws Exception
|
||||
{
|
||||
if (client2Proxy != null && !client2Proxy.closed.await(5, TimeUnit.SECONDS))
|
||||
{
|
||||
throw new TimeoutException("client2Proxy close timeout");
|
||||
}
|
||||
|
||||
if (server2Proxy != null && !server2Proxy.closed.await(5, TimeUnit.SECONDS))
|
||||
{
|
||||
throw new TimeoutException("server2Proxy close timeout");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -161,7 +159,7 @@ public class WebSocketProxyTest
|
|||
WebSocketProxy.Client2Proxy proxyClientSide = proxy.client2Proxy;
|
||||
WebSocketProxy.Server2Proxy proxyServerSide = proxy.server2Proxy;
|
||||
|
||||
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(_client, new URI("ws://localhost:" + PROXY_PORT + "/proxy/"), clientFrameHandler);
|
||||
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(_client, proxyUri, clientFrameHandler);
|
||||
upgradeRequest.setConfiguration(defaultCustomizer);
|
||||
CompletableFuture<CoreSession> response = _client.connect(upgradeRequest);
|
||||
|
||||
|
@ -175,10 +173,10 @@ public class WebSocketProxyTest
|
|||
assertThat(proxyClientSide.getState(), is(WebSocketProxy.State.CLOSED));
|
||||
assertThat(proxyServerSide.getState(), is(WebSocketProxy.State.CLOSED));
|
||||
|
||||
assertThat(proxyClientSide.receivedFrames.poll().getPayloadAsUTF8(), is("hello world"));
|
||||
assertThat(serverFrameHandler.receivedFrames.poll().getPayloadAsUTF8(), is("hello world"));
|
||||
assertThat(proxyServerSide.receivedFrames.poll().getPayloadAsUTF8(), is("hello world"));
|
||||
assertThat(clientFrameHandler.receivedFrames.poll().getPayloadAsUTF8(), is("hello world"));
|
||||
assertThat(Objects.requireNonNull(proxyClientSide.receivedFrames.poll()).getPayloadAsUTF8(), is("hello world"));
|
||||
assertThat(Objects.requireNonNull(serverFrameHandler.receivedFrames.poll()).getPayloadAsUTF8(), is("hello world"));
|
||||
assertThat(Objects.requireNonNull(proxyServerSide.receivedFrames.poll()).getPayloadAsUTF8(), is("hello world"));
|
||||
assertThat(Objects.requireNonNull(clientFrameHandler.receivedFrames.poll()).getPayloadAsUTF8(), is("hello world"));
|
||||
|
||||
assertThat(CloseStatus.getCloseStatus(proxyClientSide.receivedFrames.poll()).getReason(), is("standard close"));
|
||||
assertThat(CloseStatus.getCloseStatus(serverFrameHandler.receivedFrames.poll()).getReason(), is("standard close"));
|
||||
|
@ -199,9 +197,9 @@ public class WebSocketProxyTest
|
|||
WebSocketProxy.Server2Proxy proxyServerSide = proxy.server2Proxy;
|
||||
|
||||
TestAsyncFrameHandler clientFrameHandler = new TestAsyncFrameHandler("CLIENT");
|
||||
try (StacklessLogging stacklessLogging = new StacklessLogging(WebSocketCoreSession.class))
|
||||
try (StacklessLogging ignored = new StacklessLogging(WebSocketCoreSession.class))
|
||||
{
|
||||
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(_client, new URI("ws://localhost:" + PROXY_PORT + "/proxy/"), clientFrameHandler);
|
||||
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(_client, proxyUri, clientFrameHandler);
|
||||
upgradeRequest.setConfiguration(defaultCustomizer);
|
||||
CompletableFuture<CoreSession> response = _client.connect(upgradeRequest);
|
||||
response.get(5, TimeUnit.SECONDS);
|
||||
|
@ -238,9 +236,9 @@ public class WebSocketProxyTest
|
|||
WebSocketProxy.Client2Proxy proxyClientSide = proxy.client2Proxy;
|
||||
WebSocketProxy.Server2Proxy proxyServerSide = proxy.server2Proxy;
|
||||
|
||||
try (StacklessLogging stacklessLogging = new StacklessLogging(WebSocketCoreSession.class))
|
||||
try (StacklessLogging ignored = new StacklessLogging(WebSocketCoreSession.class))
|
||||
{
|
||||
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(_client, new URI("ws://localhost:" + PROXY_PORT + "/proxy/"), clientFrameHandler);
|
||||
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(_client, proxyUri, clientFrameHandler);
|
||||
upgradeRequest.setConfiguration(defaultCustomizer);
|
||||
CompletableFuture<CoreSession> response = _client.connect(upgradeRequest);
|
||||
Exception e = assertThrows(ExecutionException.class, () -> response.get(5, TimeUnit.SECONDS));
|
||||
|
@ -271,7 +269,7 @@ public class WebSocketProxyTest
|
|||
WebSocketProxy.Server2Proxy proxyServerSide = proxy.server2Proxy;
|
||||
|
||||
TestAsyncFrameHandler clientFrameHandler = new TestAsyncFrameHandler("CLIENT");
|
||||
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(_client, new URI("ws://localhost:" + PROXY_PORT + "/proxy/"), clientFrameHandler);
|
||||
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(_client, proxyUri, clientFrameHandler);
|
||||
upgradeRequest.setConfiguration(defaultCustomizer);
|
||||
CompletableFuture<CoreSession> response = _client.connect(upgradeRequest);
|
||||
|
||||
|
@ -286,11 +284,13 @@ public class WebSocketProxyTest
|
|||
|
||||
// Client2Proxy
|
||||
frame = proxyClientSide.receivedFrames.poll();
|
||||
assertNotNull(frame);
|
||||
assertThat(frame.getOpCode(), is(OpCode.TEXT));
|
||||
assertThat(frame.getPayloadAsUTF8(), is("hello world"));
|
||||
|
||||
// Server
|
||||
frame = serverFrameHandler.receivedFrames.poll();
|
||||
assertNotNull(frame);
|
||||
assertThat(frame.getOpCode(), is(OpCode.TEXT));
|
||||
assertThat(frame.getPayloadAsUTF8(), is("hello world"));
|
||||
frame = serverFrameHandler.receivedFrames.poll();
|
||||
|
@ -298,12 +298,14 @@ public class WebSocketProxyTest
|
|||
|
||||
// Server2Proxy
|
||||
frame = proxyServerSide.receivedFrames.poll();
|
||||
assertNotNull(frame);
|
||||
closeStatus = CloseStatus.getCloseStatus(frame);
|
||||
assertThat(closeStatus.getCode(), is(CloseStatus.SERVER_ERROR));
|
||||
assertThat(closeStatus.getReason(), is("intentionally throwing in server onFrame()"));
|
||||
|
||||
// Client
|
||||
frame = clientFrameHandler.receivedFrames.poll();
|
||||
assertNotNull(frame);
|
||||
closeStatus = CloseStatus.getCloseStatus(frame);
|
||||
assertThat(closeStatus.getCode(), is(CloseStatus.SERVER_ERROR));
|
||||
assertThat(closeStatus.getReason(), is("intentionally throwing in server onFrame()"));
|
||||
|
@ -335,7 +337,7 @@ public class WebSocketProxyTest
|
|||
}
|
||||
};
|
||||
|
||||
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(_client, new URI("ws://localhost:" + PROXY_PORT + "/proxy/"), clientFrameHandler);
|
||||
CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(_client, proxyUri, clientFrameHandler);
|
||||
upgradeRequest.setConfiguration(defaultCustomizer);
|
||||
CompletableFuture<CoreSession> response = _client.connect(upgradeRequest);
|
||||
response.get(5, TimeUnit.SECONDS);
|
||||
|
@ -349,11 +351,13 @@ public class WebSocketProxyTest
|
|||
|
||||
// Client2Proxy
|
||||
frame = proxyClientSide.receivedFrames.poll();
|
||||
assertNotNull(frame);
|
||||
assertThat(frame.getOpCode(), is(OpCode.TEXT));
|
||||
assertThat(frame.getPayloadAsUTF8(), is("hello world"));
|
||||
|
||||
// Server
|
||||
frame = serverFrameHandler.receivedFrames.poll();
|
||||
assertNotNull(frame);
|
||||
assertThat(frame.getOpCode(), is(OpCode.TEXT));
|
||||
assertThat(frame.getPayloadAsUTF8(), is("hello world"));
|
||||
assertNull(serverFrameHandler.receivedFrames.poll());
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util;
|
||||
package org.eclipse.jetty.websocket.core.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
@ -31,7 +31,7 @@ import org.eclipse.jetty.util.IO;
|
|||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.websocket.core.Frame;
|
||||
import org.eclipse.jetty.websocket.core.OpCode;
|
||||
import org.eclipse.jetty.websocket.util.messages.MessageReader;
|
||||
import org.eclipse.jetty.websocket.core.internal.messages.MessageReader;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util;
|
||||
package org.eclipse.jetty.websocket.core.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.MalformedInputException;
|
||||
|
@ -32,7 +32,7 @@ import org.eclipse.jetty.util.Utf8StringBuilder;
|
|||
import org.eclipse.jetty.websocket.core.CoreSession;
|
||||
import org.eclipse.jetty.websocket.core.Frame;
|
||||
import org.eclipse.jetty.websocket.core.OpCode;
|
||||
import org.eclipse.jetty.websocket.util.messages.MessageWriter;
|
||||
import org.eclipse.jetty.websocket.core.internal.messages.MessageWriter;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util;
|
||||
package org.eclipse.jetty.websocket.core.util;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
|
@ -34,7 +34,7 @@ import org.eclipse.jetty.util.Utf8Appendable;
|
|||
import org.eclipse.jetty.websocket.core.CoreSession;
|
||||
import org.eclipse.jetty.websocket.core.Frame;
|
||||
import org.eclipse.jetty.websocket.core.OpCode;
|
||||
import org.eclipse.jetty.websocket.util.messages.PartialStringMessageSink;
|
||||
import org.eclipse.jetty.websocket.core.internal.messages.PartialStringMessageSink;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.util;
|
||||
package org.eclipse.jetty.websocket.core.util;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
|
@ -32,7 +32,7 @@ import org.eclipse.jetty.websocket.core.CoreSession;
|
|||
import org.eclipse.jetty.websocket.core.Frame;
|
||||
import org.eclipse.jetty.websocket.core.OpCode;
|
||||
import org.eclipse.jetty.websocket.core.exception.MessageTooLargeException;
|
||||
import org.eclipse.jetty.websocket.util.messages.StringMessageSink;
|
||||
import org.eclipse.jetty.websocket.core.internal.messages.StringMessageSink;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
|
@ -24,11 +24,6 @@
|
|||
<artifactId>websocket-javax-common</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.websocket</groupId>
|
||||
<artifactId>websocket-core-client</artifactId>
|
||||
|
|
|
@ -23,8 +23,8 @@ import java.util.List;
|
|||
import javax.websocket.ClientEndpoint;
|
||||
import javax.websocket.ClientEndpointConfig;
|
||||
|
||||
import org.eclipse.jetty.websocket.core.exception.InvalidWebSocketException;
|
||||
import org.eclipse.jetty.websocket.javax.common.ClientEndpointConfigWrapper;
|
||||
import org.eclipse.jetty.websocket.util.InvalidWebSocketException;
|
||||
|
||||
public class AnnotatedClientEndpointConfig extends ClientEndpointConfigWrapper
|
||||
{
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.eclipse.jetty.client.HttpClient;
|
|||
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||
import org.eclipse.jetty.websocket.core.WebSocketComponents;
|
||||
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
|
||||
import org.eclipse.jetty.websocket.core.exception.InvalidWebSocketException;
|
||||
import org.eclipse.jetty.websocket.core.exception.UpgradeException;
|
||||
import org.eclipse.jetty.websocket.core.exception.WebSocketTimeoutException;
|
||||
import org.eclipse.jetty.websocket.javax.common.ConfiguredEndpoint;
|
||||
|
@ -47,7 +48,6 @@ import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketContainer;
|
|||
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketExtensionConfig;
|
||||
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketFrameHandler;
|
||||
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketFrameHandlerFactory;
|
||||
import org.eclipse.jetty.websocket.util.InvalidWebSocketException;
|
||||
|
||||
/**
|
||||
* Container for Client use of the javax.websocket API.
|
||||
|
|
|
@ -21,10 +21,10 @@ package org.eclipse.jetty.websocket.javax.client.internal;
|
|||
import javax.websocket.ClientEndpoint;
|
||||
import javax.websocket.EndpointConfig;
|
||||
|
||||
import org.eclipse.jetty.websocket.core.internal.util.InvokerUtils;
|
||||
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.util.InvokerUtils;
|
||||
|
||||
public class JavaxWebSocketClientFrameHandlerFactory extends JavaxWebSocketFrameHandlerFactory
|
||||
{
|
||||
|
|
|
@ -70,11 +70,6 @@
|
|||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-javax-websocket-api</artifactId>
|
||||
</dependency>
|
||||
<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-core-client</artifactId>
|
||||
|
|
|
@ -26,5 +26,4 @@ module org.eclipse.jetty.websocket.javax.common
|
|||
requires org.slf4j;
|
||||
requires transitive jetty.websocket.api;
|
||||
requires transitive org.eclipse.jetty.websocket.core.client;
|
||||
requires transitive org.eclipse.jetty.websocket.util;
|
||||
}
|
||||
|
|
|
@ -31,9 +31,9 @@ import org.eclipse.jetty.util.FutureCallback;
|
|||
import org.eclipse.jetty.websocket.core.CoreSession;
|
||||
import org.eclipse.jetty.websocket.core.Frame;
|
||||
import org.eclipse.jetty.websocket.core.OpCode;
|
||||
import org.eclipse.jetty.websocket.util.TextUtils;
|
||||
import org.eclipse.jetty.websocket.util.messages.MessageOutputStream;
|
||||
import org.eclipse.jetty.websocket.util.messages.MessageWriter;
|
||||
import org.eclipse.jetty.websocket.core.internal.messages.MessageOutputStream;
|
||||
import org.eclipse.jetty.websocket.core.internal.messages.MessageWriter;
|
||||
import org.eclipse.jetty.websocket.core.internal.util.TextUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.eclipse.jetty.util.FutureCallback;
|
|||
import org.eclipse.jetty.websocket.core.CoreSession;
|
||||
import org.eclipse.jetty.websocket.core.Frame;
|
||||
import org.eclipse.jetty.websocket.core.OpCode;
|
||||
import org.eclipse.jetty.websocket.util.TextUtils;
|
||||
import org.eclipse.jetty.websocket.core.internal.util.TextUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
|
@ -45,17 +45,17 @@ import org.eclipse.jetty.websocket.core.FrameHandler;
|
|||
import org.eclipse.jetty.websocket.core.OpCode;
|
||||
import org.eclipse.jetty.websocket.core.exception.ProtocolException;
|
||||
import org.eclipse.jetty.websocket.core.exception.WebSocketException;
|
||||
import org.eclipse.jetty.websocket.core.internal.messages.MessageSink;
|
||||
import org.eclipse.jetty.websocket.core.internal.messages.PartialByteArrayMessageSink;
|
||||
import org.eclipse.jetty.websocket.core.internal.messages.PartialByteBufferMessageSink;
|
||||
import org.eclipse.jetty.websocket.core.internal.messages.PartialStringMessageSink;
|
||||
import org.eclipse.jetty.websocket.core.internal.util.InvokerUtils;
|
||||
import org.eclipse.jetty.websocket.javax.common.decoders.AvailableDecoders;
|
||||
import org.eclipse.jetty.websocket.javax.common.decoders.RegisteredDecoder;
|
||||
import org.eclipse.jetty.websocket.javax.common.messages.DecodedBinaryMessageSink;
|
||||
import org.eclipse.jetty.websocket.javax.common.messages.DecodedBinaryStreamMessageSink;
|
||||
import org.eclipse.jetty.websocket.javax.common.messages.DecodedTextMessageSink;
|
||||
import org.eclipse.jetty.websocket.javax.common.messages.DecodedTextStreamMessageSink;
|
||||
import org.eclipse.jetty.websocket.util.InvokerUtils;
|
||||
import org.eclipse.jetty.websocket.util.messages.MessageSink;
|
||||
import org.eclipse.jetty.websocket.util.messages.PartialByteArrayMessageSink;
|
||||
import org.eclipse.jetty.websocket.util.messages.PartialByteBufferMessageSink;
|
||||
import org.eclipse.jetty.websocket.util.messages.PartialStringMessageSink;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
|
@ -43,20 +43,20 @@ import javax.websocket.Session;
|
|||
|
||||
import org.eclipse.jetty.http.pathmap.UriTemplatePathSpec;
|
||||
import org.eclipse.jetty.websocket.core.CoreSession;
|
||||
import org.eclipse.jetty.websocket.core.exception.InvalidSignatureException;
|
||||
import org.eclipse.jetty.websocket.core.exception.InvalidWebSocketException;
|
||||
import org.eclipse.jetty.websocket.core.internal.messages.MessageSink;
|
||||
import org.eclipse.jetty.websocket.core.internal.messages.PartialByteArrayMessageSink;
|
||||
import org.eclipse.jetty.websocket.core.internal.messages.PartialByteBufferMessageSink;
|
||||
import org.eclipse.jetty.websocket.core.internal.messages.PartialStringMessageSink;
|
||||
import org.eclipse.jetty.websocket.core.internal.util.InvokerUtils;
|
||||
import org.eclipse.jetty.websocket.core.internal.util.ReflectUtils;
|
||||
import org.eclipse.jetty.websocket.javax.common.decoders.RegisteredDecoder;
|
||||
import org.eclipse.jetty.websocket.javax.common.messages.AbstractDecodedMessageSink;
|
||||
import org.eclipse.jetty.websocket.javax.common.messages.DecodedBinaryMessageSink;
|
||||
import org.eclipse.jetty.websocket.javax.common.messages.DecodedBinaryStreamMessageSink;
|
||||
import org.eclipse.jetty.websocket.javax.common.messages.DecodedTextMessageSink;
|
||||
import org.eclipse.jetty.websocket.javax.common.messages.DecodedTextStreamMessageSink;
|
||||
import org.eclipse.jetty.websocket.util.InvalidSignatureException;
|
||||
import org.eclipse.jetty.websocket.util.InvalidWebSocketException;
|
||||
import org.eclipse.jetty.websocket.util.InvokerUtils;
|
||||
import org.eclipse.jetty.websocket.util.ReflectUtils;
|
||||
import org.eclipse.jetty.websocket.util.messages.MessageSink;
|
||||
import org.eclipse.jetty.websocket.util.messages.PartialByteArrayMessageSink;
|
||||
import org.eclipse.jetty.websocket.util.messages.PartialByteBufferMessageSink;
|
||||
import org.eclipse.jetty.websocket.util.messages.PartialStringMessageSink;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
|
|
|
@ -23,9 +23,9 @@ import javax.websocket.Encoder;
|
|||
import javax.websocket.EndpointConfig;
|
||||
|
||||
import org.eclipse.jetty.http.pathmap.UriTemplatePathSpec;
|
||||
import org.eclipse.jetty.websocket.core.exception.InvalidWebSocketException;
|
||||
import org.eclipse.jetty.websocket.javax.common.decoders.AvailableDecoders;
|
||||
import org.eclipse.jetty.websocket.javax.common.encoders.AvailableEncoders;
|
||||
import org.eclipse.jetty.websocket.util.InvalidWebSocketException;
|
||||
|
||||
public class JavaxWebSocketFrameHandlerMetadata
|
||||
{
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue