Merge pull request #3310 from lachlan-roberts/jetty-10.0.x-3298-completableFutures
Issue #3298 - WebSocket UpgradeRequests and CompletableFutures
This commit is contained in:
commit
a41f270e47
|
@ -18,20 +18,21 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.javax.client;
|
||||
|
||||
import org.eclipse.jetty.websocket.javax.common.UpgradeRequest;
|
||||
|
||||
import java.net.URI;
|
||||
import java.security.Principal;
|
||||
|
||||
import org.eclipse.jetty.websocket.core.client.ClientUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.javax.common.UpgradeRequest;
|
||||
|
||||
/**
|
||||
* Representing the Jetty {@link org.eclipse.jetty.client.HttpClient}'s {@link org.eclipse.jetty.client.HttpRequest}
|
||||
* in the {@link UpgradeRequest} interface.
|
||||
*/
|
||||
public class DelegatedClientUpgradeRequest implements UpgradeRequest
|
||||
public class DelegatedJavaxClientUpgradeRequest implements UpgradeRequest
|
||||
{
|
||||
private final org.eclipse.jetty.websocket.core.client.UpgradeRequest delegate;
|
||||
private final ClientUpgradeRequest delegate;
|
||||
|
||||
public DelegatedClientUpgradeRequest(org.eclipse.jetty.websocket.core.client.UpgradeRequest delegate)
|
||||
public DelegatedJavaxClientUpgradeRequest(ClientUpgradeRequest delegate)
|
||||
{
|
||||
this.delegate = delegate;
|
||||
}
|
|
@ -18,24 +18,24 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.javax.client;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.jetty.client.HttpResponse;
|
||||
import org.eclipse.jetty.http.HttpHeader;
|
||||
import org.eclipse.jetty.websocket.core.ExtensionConfig;
|
||||
import org.eclipse.jetty.websocket.javax.common.UpgradeResponse;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Representing the Jetty {@link org.eclipse.jetty.client.HttpClient}'s {@link HttpResponse}
|
||||
* in the {@link UpgradeResponse} interface.
|
||||
*/
|
||||
public class DelegatedClientUpgradeResponse implements UpgradeResponse
|
||||
public class DelegatedJavaxClientUpgradeResponse implements UpgradeResponse
|
||||
{
|
||||
private HttpResponse delegate;
|
||||
|
||||
public DelegatedClientUpgradeResponse(HttpResponse response)
|
||||
public DelegatedJavaxClientUpgradeResponse(HttpResponse response)
|
||||
{
|
||||
this.delegate = response;
|
||||
}
|
|
@ -18,51 +18,53 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.javax.client;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import javax.websocket.Session;
|
||||
|
||||
import org.eclipse.jetty.client.HttpResponse;
|
||||
import org.eclipse.jetty.websocket.core.FrameHandler;
|
||||
import org.eclipse.jetty.websocket.core.client.ClientUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
|
||||
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketFrameHandler;
|
||||
import org.eclipse.jetty.websocket.javax.common.UpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.javax.common.UpgradeResponse;
|
||||
|
||||
import javax.websocket.Session;
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class ClientUpgradeRequestImpl extends org.eclipse.jetty.websocket.core.client.UpgradeRequest
|
||||
public class JavaxClientUpgradeRequest extends ClientUpgradeRequest
|
||||
{
|
||||
private final JavaxWebSocketClientContainer containerContext;
|
||||
private final Object websocketPojo;
|
||||
private final CompletableFuture<Session> futureJavaxSession;
|
||||
private final CompletableFuture<Session> futureSession;
|
||||
|
||||
public ClientUpgradeRequestImpl(JavaxWebSocketClientContainer clientContainer, WebSocketCoreClient coreClient, URI requestURI, Object websocketPojo)
|
||||
public JavaxClientUpgradeRequest(JavaxWebSocketClientContainer clientContainer, WebSocketCoreClient coreClient, URI requestURI, Object websocketPojo)
|
||||
{
|
||||
super(coreClient, requestURI);
|
||||
this.containerContext = clientContainer;
|
||||
this.websocketPojo = websocketPojo;
|
||||
this.futureJavaxSession = new CompletableFuture<>();
|
||||
this.futureSession = new CompletableFuture<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleException(Throwable failure)
|
||||
{
|
||||
super.handleException(failure);
|
||||
futureJavaxSession.completeExceptionally(failure);
|
||||
futureSession.completeExceptionally(failure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FrameHandler getFrameHandler(WebSocketCoreClient coreClient, HttpResponse response)
|
||||
{
|
||||
UpgradeRequest upgradeRequest = new DelegatedClientUpgradeRequest(this);
|
||||
UpgradeResponse upgradeResponse = new DelegatedClientUpgradeResponse(response);
|
||||
UpgradeRequest upgradeRequest = new DelegatedJavaxClientUpgradeRequest(this);
|
||||
UpgradeResponse upgradeResponse = new DelegatedJavaxClientUpgradeResponse(response);
|
||||
|
||||
JavaxWebSocketFrameHandler frameHandler = containerContext.newFrameHandler(websocketPojo, upgradeRequest, upgradeResponse, futureJavaxSession);
|
||||
JavaxWebSocketFrameHandler frameHandler = containerContext.newFrameHandler(websocketPojo, upgradeRequest, upgradeResponse, futureSession);
|
||||
|
||||
return frameHandler;
|
||||
}
|
||||
|
||||
public CompletableFuture<Session> getFutureSession()
|
||||
{
|
||||
return futureJavaxSession;
|
||||
return futureSession;
|
||||
}
|
||||
}
|
|
@ -125,7 +125,7 @@ public class JavaxWebSocketClientContainer extends JavaxWebSocketContainer imple
|
|||
* @param upgradeRequest the upgrade request information
|
||||
* @return the future for the session, available on success of connect
|
||||
*/
|
||||
private CompletableFuture<Session> connect(ClientUpgradeRequestImpl upgradeRequest)
|
||||
private CompletableFuture<Session> connect(JavaxClientUpgradeRequest upgradeRequest)
|
||||
{
|
||||
CompletableFuture<Session> fut = upgradeRequest.getFutureSession();
|
||||
try
|
||||
|
@ -145,7 +145,7 @@ public class JavaxWebSocketClientContainer extends JavaxWebSocketContainer imple
|
|||
Objects.requireNonNull(configuredEndpoint, "WebSocket configured endpoint cannot be null");
|
||||
Objects.requireNonNull(destURI, "Destination URI cannot be null");
|
||||
|
||||
ClientUpgradeRequestImpl upgradeRequest = new ClientUpgradeRequestImpl(this, getWebSocketCoreClient(), destURI, configuredEndpoint);
|
||||
JavaxClientUpgradeRequest upgradeRequest = new JavaxClientUpgradeRequest(this, getWebSocketCoreClient(), destURI, configuredEndpoint);
|
||||
|
||||
EndpointConfig config = configuredEndpoint.getConfig();
|
||||
if (config != null && config instanceof ClientEndpointConfig)
|
||||
|
|
|
@ -18,19 +18,20 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.javax.common;
|
||||
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.util.DecoratedObjectFactory;
|
||||
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
||||
import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry;
|
||||
|
||||
import javax.websocket.Extension;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.WebSocketContainer;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.websocket.Extension;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.WebSocketContainer;
|
||||
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.util.DecoratedObjectFactory;
|
||||
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
||||
import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry;
|
||||
|
||||
public abstract class JavaxWebSocketContainer extends ContainerLifeCycle implements javax.websocket.WebSocketContainer
|
||||
{
|
||||
private long defaultAsyncSendTimeout = -1;
|
||||
|
@ -105,7 +106,7 @@ public abstract class JavaxWebSocketContainer extends ContainerLifeCycle impleme
|
|||
public JavaxWebSocketFrameHandler newFrameHandler(Object websocketPojo, UpgradeRequest upgradeRequest, UpgradeResponse upgradeResponse,
|
||||
CompletableFuture<Session> futureSession)
|
||||
{
|
||||
return getFrameHandlerFactory().newJavaxFrameHandler(websocketPojo, upgradeRequest, upgradeResponse, futureSession);
|
||||
return getFrameHandlerFactory().newJavaxWebSocketFrameHandler(websocketPojo, upgradeRequest, upgradeResponse, futureSession);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -29,6 +29,7 @@ import java.util.Optional;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.websocket.CloseReason;
|
||||
import javax.websocket.Decoder;
|
||||
import javax.websocket.EndpointConfig;
|
||||
|
@ -229,16 +230,14 @@ public class JavaxWebSocketFrameHandler implements FrameHandler
|
|||
openHandle.invoke();
|
||||
|
||||
container.addBean(session, true);
|
||||
futureSession.complete(session);
|
||||
callback.succeeded();
|
||||
futureSession.complete(session);
|
||||
}
|
||||
catch (Throwable cause)
|
||||
{
|
||||
Exception wse = new WebSocketException(endpointInstance.getClass().getName() + " OPEN method error: " + cause.getMessage(), cause);
|
||||
|
||||
// TODO This feels like double handling of the exception? Review need for futureSession
|
||||
futureSession.completeExceptionally(wse);
|
||||
callback.failed(wse);
|
||||
futureSession.completeExceptionally(wse);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,32 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.javax.common;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.websocket.CloseReason;
|
||||
import javax.websocket.Decoder;
|
||||
import javax.websocket.EndpointConfig;
|
||||
import javax.websocket.OnClose;
|
||||
import javax.websocket.OnError;
|
||||
import javax.websocket.OnMessage;
|
||||
import javax.websocket.OnOpen;
|
||||
import javax.websocket.PongMessage;
|
||||
import javax.websocket.Session;
|
||||
|
||||
import org.eclipse.jetty.http.pathmap.UriTemplatePathSpec;
|
||||
import org.eclipse.jetty.websocket.javax.common.decoders.AvailableDecoders;
|
||||
import org.eclipse.jetty.websocket.javax.common.messages.ByteArrayMessageSink;
|
||||
|
@ -37,31 +63,6 @@ import org.eclipse.jetty.websocket.javax.common.util.InvalidSignatureException;
|
|||
import org.eclipse.jetty.websocket.javax.common.util.InvokerUtils;
|
||||
import org.eclipse.jetty.websocket.javax.common.util.ReflectUtils;
|
||||
|
||||
import javax.websocket.CloseReason;
|
||||
import javax.websocket.Decoder;
|
||||
import javax.websocket.EndpointConfig;
|
||||
import javax.websocket.OnClose;
|
||||
import javax.websocket.OnError;
|
||||
import javax.websocket.OnMessage;
|
||||
import javax.websocket.OnOpen;
|
||||
import javax.websocket.PongMessage;
|
||||
import javax.websocket.Session;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.eclipse.jetty.websocket.javax.common.JavaxWebSocketFrameHandlerMetadata.MessageMetadata;
|
||||
|
||||
|
@ -107,7 +108,8 @@ public abstract class JavaxWebSocketFrameHandlerFactory
|
|||
|
||||
public abstract JavaxWebSocketFrameHandlerMetadata createMetadata(Class<?> endpointClass, EndpointConfig endpointConfig);
|
||||
|
||||
public JavaxWebSocketFrameHandler newJavaxFrameHandler(Object endpointInstance, UpgradeRequest upgradeRequest, UpgradeResponse upgradeResponse,
|
||||
public JavaxWebSocketFrameHandler newJavaxWebSocketFrameHandler(Object endpointInstance, UpgradeRequest upgradeRequest,
|
||||
UpgradeResponse upgradeResponse,
|
||||
CompletableFuture<Session> futureSession)
|
||||
{
|
||||
Object endpoint;
|
||||
|
|
|
@ -69,7 +69,7 @@ public abstract class AbstractJavaxWebSocketFrameHandlerTest
|
|||
UpgradeRequest upgradeRequest = new UpgradeRequestAdapter();
|
||||
UpgradeResponse upgradeResponse = new UpgradeResponseAdapter();
|
||||
|
||||
JavaxWebSocketFrameHandler localEndpoint = factory.newJavaxFrameHandler(endpoint,
|
||||
JavaxWebSocketFrameHandler localEndpoint = factory.newJavaxWebSocketFrameHandler(endpoint,
|
||||
upgradeRequest, upgradeResponse, new CompletableFuture<>());
|
||||
|
||||
return localEndpoint;
|
||||
|
|
|
@ -18,23 +18,24 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.javax.server;
|
||||
|
||||
import org.eclipse.jetty.http.pathmap.UriTemplatePathSpec;
|
||||
import org.eclipse.jetty.websocket.core.FrameHandler;
|
||||
import org.eclipse.jetty.websocket.javax.server.internal.PathParamIdentifier;
|
||||
import org.eclipse.jetty.websocket.javax.server.internal.UpgradeRequestAdapter;
|
||||
import org.eclipse.jetty.websocket.javax.server.internal.UpgradeResponseAdapter;
|
||||
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.servlet.ServletUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
|
||||
import org.eclipse.jetty.websocket.servlet.FrameHandlerFactory;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import javax.websocket.Endpoint;
|
||||
import javax.websocket.EndpointConfig;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.eclipse.jetty.http.pathmap.UriTemplatePathSpec;
|
||||
import org.eclipse.jetty.websocket.core.FrameHandler;
|
||||
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketContainer;
|
||||
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketFrameHandlerFactory;
|
||||
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketFrameHandlerMetadata;
|
||||
import org.eclipse.jetty.websocket.javax.server.internal.DelegatedJavaxServletUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.javax.server.internal.PathParamIdentifier;
|
||||
import org.eclipse.jetty.websocket.javax.server.internal.UpgradeResponseAdapter;
|
||||
import org.eclipse.jetty.websocket.servlet.FrameHandlerFactory;
|
||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
|
||||
|
||||
public class JavaxWebSocketServerFrameHandlerFactory extends JavaxWebSocketFrameHandlerFactory implements FrameHandlerFactory
|
||||
{
|
||||
|
@ -68,6 +69,6 @@ public class JavaxWebSocketServerFrameHandlerFactory extends JavaxWebSocketFrame
|
|||
public FrameHandler newFrameHandler(Object websocketPojo, ServletUpgradeRequest upgradeRequest, ServletUpgradeResponse upgradeResponse)
|
||||
{
|
||||
CompletableFuture<Session> completableFuture = new CompletableFuture<>();
|
||||
return newJavaxFrameHandler(websocketPojo, new UpgradeRequestAdapter(upgradeRequest), new UpgradeResponseAdapter(upgradeResponse), completableFuture);
|
||||
return newJavaxWebSocketFrameHandler(websocketPojo, new DelegatedJavaxServletUpgradeRequest(upgradeRequest), new UpgradeResponseAdapter(upgradeResponse), completableFuture);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,17 +18,17 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.javax.server.internal;
|
||||
|
||||
import org.eclipse.jetty.websocket.javax.common.UpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
|
||||
|
||||
import java.net.URI;
|
||||
import java.security.Principal;
|
||||
|
||||
public class UpgradeRequestAdapter implements UpgradeRequest
|
||||
import org.eclipse.jetty.websocket.javax.common.UpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
|
||||
|
||||
public class DelegatedJavaxServletUpgradeRequest implements UpgradeRequest
|
||||
{
|
||||
private final ServletUpgradeRequest servletRequest;
|
||||
|
||||
public UpgradeRequestAdapter(ServletUpgradeRequest servletRequest)
|
||||
public DelegatedJavaxServletUpgradeRequest(ServletUpgradeRequest servletRequest)
|
||||
{
|
||||
this.servletRequest = servletRequest;
|
||||
}
|
|
@ -38,7 +38,7 @@ import org.eclipse.jetty.websocket.core.Behavior;
|
|||
import org.eclipse.jetty.websocket.core.CloseStatus;
|
||||
import org.eclipse.jetty.websocket.core.Frame;
|
||||
import org.eclipse.jetty.websocket.core.FrameHandler;
|
||||
import org.eclipse.jetty.websocket.core.client.UpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.core.client.ClientUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
|
||||
import org.eclipse.jetty.websocket.core.internal.Generator;
|
||||
|
||||
|
@ -184,7 +184,7 @@ public class NetworkFuzzer extends Fuzzer.Adapter implements Fuzzer, AutoCloseab
|
|||
}
|
||||
}
|
||||
|
||||
public static class RawUpgradeRequest extends UpgradeRequest
|
||||
public static class RawUpgradeRequest extends ClientUpgradeRequest
|
||||
{
|
||||
private final CompletableFuture<FrameCapture> futureCapture;
|
||||
private EndPoint endPoint;
|
||||
|
|
|
@ -84,7 +84,7 @@ public class SessionAddMessageHandlerTest
|
|||
|
||||
JavaxWebSocketFrameHandlerFactory frameHandlerFactory = new JavaxWebSocketClientFrameHandlerFactory(container);
|
||||
CompletableFuture<Session> futureSession = new CompletableFuture<>();
|
||||
frameHandler = frameHandlerFactory.newJavaxFrameHandler(ei, handshakeRequest, handshakeResponse, futureSession);
|
||||
frameHandler = frameHandlerFactory.newJavaxWebSocketFrameHandler(ei, handshakeRequest, handshakeResponse, futureSession);
|
||||
frameHandler.onOpen(new FrameHandler.CoreSession.Empty(), Callback.NOOP);
|
||||
|
||||
// Session
|
||||
|
|
|
@ -18,37 +18,6 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.javax.tests.server;
|
||||
|
||||
import org.eclipse.jetty.http.HttpHeader;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
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.client.UpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
|
||||
import org.eclipse.jetty.websocket.javax.server.internal.JavaxWebSocketCreator;
|
||||
import org.eclipse.jetty.websocket.javax.tests.LocalServer;
|
||||
import org.eclipse.jetty.websocket.javax.tests.Timeouts;
|
||||
import org.eclipse.jetty.websocket.javax.tests.framehandlers.FrameHandlerTracker;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.websocket.DecodeException;
|
||||
import javax.websocket.Decoder;
|
||||
import javax.websocket.EndpointConfig;
|
||||
import javax.websocket.Extension;
|
||||
import javax.websocket.HandshakeResponse;
|
||||
import javax.websocket.OnMessage;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.server.HandshakeRequest;
|
||||
import javax.websocket.server.ServerContainer;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
import javax.websocket.server.ServerEndpointConfig;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.net.InetSocketAddress;
|
||||
|
@ -69,6 +38,38 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.websocket.DecodeException;
|
||||
import javax.websocket.Decoder;
|
||||
import javax.websocket.EndpointConfig;
|
||||
import javax.websocket.Extension;
|
||||
import javax.websocket.HandshakeResponse;
|
||||
import javax.websocket.OnMessage;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.server.HandshakeRequest;
|
||||
import javax.websocket.server.ServerContainer;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
import javax.websocket.server.ServerEndpointConfig;
|
||||
|
||||
import org.eclipse.jetty.http.HttpHeader;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
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.client.ClientUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
|
||||
import org.eclipse.jetty.websocket.javax.server.internal.JavaxWebSocketCreator;
|
||||
import org.eclipse.jetty.websocket.javax.tests.LocalServer;
|
||||
import org.eclipse.jetty.websocket.javax.tests.Timeouts;
|
||||
import org.eclipse.jetty.websocket.javax.tests.framehandlers.FrameHandlerTracker;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
|
@ -430,7 +431,7 @@ public class ConfiguratorTest
|
|||
URI wsUri = server.getWsUri().resolve("/capture-request-headers");
|
||||
|
||||
FrameHandlerTracker clientSocket = new FrameHandlerTracker();
|
||||
UpgradeRequest upgradeRequest = UpgradeRequest.from(client, wsUri, clientSocket);
|
||||
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket);
|
||||
upgradeRequest.addExtensions("identity");
|
||||
Future<FrameHandler.CoreSession> clientConnectFuture = client.connect(upgradeRequest);
|
||||
|
||||
|
@ -454,7 +455,7 @@ public class ConfiguratorTest
|
|||
URI wsUri = server.getWsUri().resolve("/no-extensions");
|
||||
|
||||
FrameHandlerTracker clientSocket = new FrameHandlerTracker();
|
||||
UpgradeRequest upgradeRequest = UpgradeRequest.from(client, wsUri, clientSocket);
|
||||
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket);
|
||||
upgradeRequest.addExtensions("identity");
|
||||
Future<FrameHandler.CoreSession> clientConnectFuture = client.connect(upgradeRequest);
|
||||
|
||||
|
@ -478,7 +479,7 @@ public class ConfiguratorTest
|
|||
URI wsUri = server.getWsUri().resolve("/capture-request-headers");
|
||||
|
||||
FrameHandlerTracker clientSocket = new FrameHandlerTracker();
|
||||
UpgradeRequest upgradeRequest = UpgradeRequest.from(client, wsUri, clientSocket);
|
||||
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket);
|
||||
upgradeRequest.header("X-Dummy", "Bogus");
|
||||
Future<FrameHandler.CoreSession> clientConnectFuture = client.connect(upgradeRequest);
|
||||
|
||||
|
@ -503,7 +504,7 @@ public class ConfiguratorTest
|
|||
|
||||
// First Request
|
||||
FrameHandlerTracker clientSocket = new FrameHandlerTracker();
|
||||
UpgradeRequest upgradeRequest = UpgradeRequest.from(client, wsUri, clientSocket);
|
||||
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket);
|
||||
Future<FrameHandler.CoreSession> clientConnectFuture = client.connect(upgradeRequest);
|
||||
|
||||
FrameHandler.CoreSession channel = clientConnectFuture.get(Timeouts.CONNECT_MS, TimeUnit.MILLISECONDS);
|
||||
|
@ -522,7 +523,7 @@ public class ConfiguratorTest
|
|||
|
||||
// Second request
|
||||
clientSocket = new FrameHandlerTracker();
|
||||
upgradeRequest = UpgradeRequest.from(client, wsUri, clientSocket);
|
||||
upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket);
|
||||
clientConnectFuture = client.connect(upgradeRequest);
|
||||
|
||||
channel = clientConnectFuture.get(Timeouts.CONNECT_MS, TimeUnit.MILLISECONDS);
|
||||
|
@ -550,7 +551,7 @@ public class ConfiguratorTest
|
|||
URI wsUri = server.getWsUri().resolve("/addr");
|
||||
|
||||
FrameHandlerTracker clientSocket = new FrameHandlerTracker();
|
||||
UpgradeRequest upgradeRequest = UpgradeRequest.from(client, wsUri, clientSocket);
|
||||
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket);
|
||||
Future<FrameHandler.CoreSession> clientConnectFuture = client.connect(upgradeRequest);
|
||||
|
||||
FrameHandler.CoreSession channel = clientConnectFuture.get(Timeouts.CONNECT_MS, TimeUnit.MILLISECONDS);
|
||||
|
@ -591,7 +592,7 @@ public class ConfiguratorTest
|
|||
ProtocolsConfigurator.seenProtocols.set(null);
|
||||
|
||||
FrameHandlerTracker clientSocket = new FrameHandlerTracker();
|
||||
UpgradeRequest upgradeRequest = UpgradeRequest.from(client, wsUri, clientSocket);
|
||||
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket);
|
||||
upgradeRequest.setSubProtocols("status");
|
||||
Future<FrameHandler.CoreSession> clientConnectFuture = client.connect(upgradeRequest);
|
||||
|
||||
|
@ -610,7 +611,7 @@ public class ConfiguratorTest
|
|||
ProtocolsConfigurator.seenProtocols.set(null);
|
||||
|
||||
FrameHandlerTracker clientSocket = new FrameHandlerTracker();
|
||||
UpgradeRequest upgradeRequest = UpgradeRequest.from(client, wsUri, clientSocket);
|
||||
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket);
|
||||
upgradeRequest.setSubProtocols("echo", "chat", "status");
|
||||
Future<FrameHandler.CoreSession> clientConnectFuture = client.connect(upgradeRequest);
|
||||
|
||||
|
@ -629,7 +630,7 @@ public class ConfiguratorTest
|
|||
ProtocolsConfigurator.seenProtocols.set(null);
|
||||
|
||||
FrameHandlerTracker clientSocket = new FrameHandlerTracker();
|
||||
UpgradeRequest upgradeRequest = UpgradeRequest.from(client, wsUri, clientSocket);
|
||||
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket);
|
||||
upgradeRequest.header("sec-websocket-protocol", "echo, chat, status");
|
||||
Future<FrameHandler.CoreSession> clientConnectFuture = client.connect(upgradeRequest);
|
||||
|
||||
|
@ -648,7 +649,7 @@ public class ConfiguratorTest
|
|||
ProtocolsConfigurator.seenProtocols.set(null);
|
||||
|
||||
FrameHandlerTracker clientSocket = new FrameHandlerTracker();
|
||||
UpgradeRequest upgradeRequest = UpgradeRequest.from(client, wsUri, clientSocket);
|
||||
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket);
|
||||
// header name is not to spec (case wise)
|
||||
upgradeRequest.header("Sec-Websocket-Protocol", "echo, chat, status");
|
||||
Future<FrameHandler.CoreSession> clientConnectFuture = client.connect(upgradeRequest);
|
||||
|
@ -682,7 +683,7 @@ public class ConfiguratorTest
|
|||
URI wsUri = server.getWsUri().resolve("/timedecoder");
|
||||
|
||||
FrameHandlerTracker clientSocket = new FrameHandlerTracker();
|
||||
UpgradeRequest upgradeRequest = UpgradeRequest.from(client, wsUri, clientSocket);
|
||||
ClientUpgradeRequest upgradeRequest = ClientUpgradeRequest.from(client, wsUri, clientSocket);
|
||||
upgradeRequest.setSubProtocols("gmt");
|
||||
Future<FrameHandler.CoreSession> clientConnectFuture = client.connect(upgradeRequest);
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ import org.eclipse.jetty.websocket.api.UpgradeRequest;
|
|||
import org.eclipse.jetty.websocket.api.UpgradeResponse;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketBehavior;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.client.impl.ClientUpgradeRequestImpl;
|
||||
import org.eclipse.jetty.websocket.client.impl.JettyClientUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandler;
|
||||
import org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandlerFactory;
|
||||
import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry;
|
||||
|
@ -107,7 +107,7 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketPoli
|
|||
*/
|
||||
public CompletableFuture<Session> connect(Object websocket, URI toUri, UpgradeRequest request) throws IOException
|
||||
{
|
||||
ClientUpgradeRequestImpl upgradeRequest = new ClientUpgradeRequestImpl(this, coreClient, request, toUri, websocket);
|
||||
JettyClientUpgradeRequest upgradeRequest = new JettyClientUpgradeRequest(this, coreClient, request, toUri, websocket);
|
||||
coreClient.connect(upgradeRequest);
|
||||
return upgradeRequest.getFutureSession();
|
||||
}
|
||||
|
|
|
@ -18,14 +18,6 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.client.impl;
|
||||
|
||||
import org.eclipse.jetty.http.HttpField;
|
||||
import org.eclipse.jetty.http.HttpHeader;
|
||||
import org.eclipse.jetty.io.EndPoint;
|
||||
import org.eclipse.jetty.util.MultiMap;
|
||||
import org.eclipse.jetty.util.UrlEncoded;
|
||||
import org.eclipse.jetty.websocket.api.UpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
||||
|
||||
import java.net.HttpCookie;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.URI;
|
||||
|
@ -35,19 +27,28 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.jetty.http.HttpField;
|
||||
import org.eclipse.jetty.http.HttpHeader;
|
||||
import org.eclipse.jetty.io.EndPoint;
|
||||
import org.eclipse.jetty.util.MultiMap;
|
||||
import org.eclipse.jetty.util.UrlEncoded;
|
||||
import org.eclipse.jetty.websocket.api.UpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
||||
import org.eclipse.jetty.websocket.core.client.ClientUpgradeRequest;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
/**
|
||||
* Representing the Jetty {@link org.eclipse.jetty.client.HttpClient}'s {@link org.eclipse.jetty.client.HttpRequest}
|
||||
* in the {@link UpgradeRequest} interface.
|
||||
*/
|
||||
public class DelegatedClientUpgradeRequest implements UpgradeRequest
|
||||
public class DelegatedJettyClientUpgradeRequest implements UpgradeRequest
|
||||
{
|
||||
private final org.eclipse.jetty.websocket.core.client.UpgradeRequest delegate;
|
||||
private final ClientUpgradeRequest delegate;
|
||||
private SocketAddress localSocketAddress;
|
||||
private SocketAddress remoteSocketAddress;
|
||||
|
||||
public DelegatedClientUpgradeRequest(org.eclipse.jetty.websocket.core.client.UpgradeRequest delegate)
|
||||
public DelegatedJettyClientUpgradeRequest(ClientUpgradeRequest delegate)
|
||||
{
|
||||
this.delegate = delegate;
|
||||
}
|
|
@ -18,11 +18,6 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.client.impl;
|
||||
|
||||
import org.eclipse.jetty.client.HttpResponse;
|
||||
import org.eclipse.jetty.http.HttpHeader;
|
||||
import org.eclipse.jetty.websocket.api.UpgradeResponse;
|
||||
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -30,15 +25,20 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.jetty.client.HttpResponse;
|
||||
import org.eclipse.jetty.http.HttpHeader;
|
||||
import org.eclipse.jetty.websocket.api.UpgradeResponse;
|
||||
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
||||
|
||||
/**
|
||||
* Representing the Jetty {@link org.eclipse.jetty.client.HttpClient}'s {@link org.eclipse.jetty.client.HttpResponse}
|
||||
* in the {@link UpgradeResponse} interface.
|
||||
*/
|
||||
public class DelegatedClientUpgradeResponse implements UpgradeResponse
|
||||
public class DelegatedJettyClientUpgradeResponse implements UpgradeResponse
|
||||
{
|
||||
private HttpResponse delegate;
|
||||
|
||||
public DelegatedClientUpgradeResponse(HttpResponse response)
|
||||
public DelegatedJettyClientUpgradeResponse(HttpResponse response)
|
||||
{
|
||||
this.delegate = response;
|
||||
}
|
|
@ -18,41 +18,39 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.client.impl;
|
||||
|
||||
import java.net.HttpCookie;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.eclipse.jetty.client.HttpResponse;
|
||||
import org.eclipse.jetty.http.HttpFields;
|
||||
import org.eclipse.jetty.http.HttpHeader;
|
||||
import org.eclipse.jetty.http.HttpVersion;
|
||||
import org.eclipse.jetty.io.EndPoint;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.UpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.api.UpgradeResponse;
|
||||
import org.eclipse.jetty.websocket.client.WebSocketClient;
|
||||
import org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandler;
|
||||
import org.eclipse.jetty.websocket.core.FrameHandler;
|
||||
import org.eclipse.jetty.websocket.core.client.UpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.core.client.ClientUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
|
||||
|
||||
import java.net.HttpCookie;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class ClientUpgradeRequestImpl extends UpgradeRequest
|
||||
public class JettyClientUpgradeRequest extends ClientUpgradeRequest
|
||||
{
|
||||
private final WebSocketClient containerContext;
|
||||
private final Object websocketPojo;
|
||||
private final CompletableFuture<Session> onOpenFuture;
|
||||
private final CompletableFuture<Session> futureSession;
|
||||
private final DelegatedClientUpgradeRequest handshakeRequest;
|
||||
private final DelegatedJettyClientUpgradeRequest handshakeRequest;
|
||||
|
||||
public ClientUpgradeRequestImpl(WebSocketClient clientContainer, WebSocketCoreClient coreClient, org.eclipse.jetty.websocket.api.UpgradeRequest request,
|
||||
public JettyClientUpgradeRequest(WebSocketClient clientContainer, WebSocketCoreClient coreClient, UpgradeRequest request,
|
||||
URI requestURI, Object websocketPojo)
|
||||
{
|
||||
super(coreClient, requestURI);
|
||||
this.containerContext = clientContainer;
|
||||
this.websocketPojo = websocketPojo;
|
||||
|
||||
this.onOpenFuture = new CompletableFuture<>();
|
||||
this.futureSession = super.futureCoreSession.thenCombine(onOpenFuture, (channel, session) -> session);
|
||||
this.futureSession = new CompletableFuture<>();
|
||||
|
||||
if (request != null)
|
||||
{
|
||||
|
@ -89,7 +87,7 @@ public class ClientUpgradeRequestImpl extends UpgradeRequest
|
|||
version(HttpVersion.fromString(request.getHttpVersion()));
|
||||
}
|
||||
|
||||
handshakeRequest = new DelegatedClientUpgradeRequest(this);
|
||||
handshakeRequest = new DelegatedJettyClientUpgradeRequest(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -102,16 +100,16 @@ public class ClientUpgradeRequestImpl extends UpgradeRequest
|
|||
protected void handleException(Throwable failure)
|
||||
{
|
||||
super.handleException(failure);
|
||||
onOpenFuture.completeExceptionally(failure);
|
||||
futureSession.completeExceptionally(failure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FrameHandler getFrameHandler(WebSocketCoreClient coreClient, HttpResponse response)
|
||||
{
|
||||
UpgradeResponse upgradeResponse = new DelegatedClientUpgradeResponse(response);
|
||||
UpgradeResponse upgradeResponse = new DelegatedJettyClientUpgradeResponse(response);
|
||||
|
||||
JettyWebSocketFrameHandler frameHandler = containerContext.newFrameHandler(websocketPojo,
|
||||
handshakeRequest, upgradeResponse, onOpenFuture);
|
||||
handshakeRequest, upgradeResponse, futureSession);
|
||||
|
||||
return frameHandler;
|
||||
}
|
|
@ -141,13 +141,13 @@ public class JettyWebSocketFrameHandler implements FrameHandler
|
|||
if (openHandle != null)
|
||||
openHandle.invoke();
|
||||
|
||||
futureSession.complete(session);
|
||||
callback.succeeded();
|
||||
futureSession.complete(session);
|
||||
}
|
||||
catch (Throwable cause)
|
||||
{
|
||||
// TODO should futureSession be failed here?
|
||||
callback.failed(new WebSocketException(endpointInstance.getClass().getName() + " OPEN method error: " + cause.getMessage(), cause));
|
||||
futureSession.completeExceptionally(cause);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -236,7 +236,10 @@ public class JettyWebSocketFrameHandler implements FrameHandler
|
|||
{
|
||||
// No message sink is active
|
||||
if (activeMessageSink == null)
|
||||
{
|
||||
callback.succeeded();
|
||||
return;
|
||||
}
|
||||
|
||||
// Accept the payload into the message sink
|
||||
activeMessageSink.accept(frame, callback);
|
||||
|
|
|
@ -61,7 +61,6 @@ import org.eclipse.jetty.websocket.common.message.PartialTextMessageSink;
|
|||
import org.eclipse.jetty.websocket.common.message.ReaderMessageSink;
|
||||
import org.eclipse.jetty.websocket.common.message.StringMessageSink;
|
||||
import org.eclipse.jetty.websocket.common.util.ReflectUtils;
|
||||
import org.eclipse.jetty.websocket.core.Frame;
|
||||
|
||||
/**
|
||||
* Factory to create {@link JettyWebSocketFrameHandler} instances suitable for
|
||||
|
@ -351,7 +350,7 @@ public class JettyWebSocketFrameHandlerFactory extends ContainerLifeCycle
|
|||
{
|
||||
assertSignatureValid(endpointClass, onmethod, OnWebSocketFrame.class);
|
||||
final InvokerUtils.Arg SESSION = new InvokerUtils.Arg(Session.class);
|
||||
final InvokerUtils.Arg FRAME = new InvokerUtils.Arg(Frame.class).required();
|
||||
final InvokerUtils.Arg FRAME = new InvokerUtils.Arg(org.eclipse.jetty.websocket.api.extensions.Frame.class).required();
|
||||
MethodHandle methodHandle = InvokerUtils.mutatedInvoker(endpointClass, onmethod, SESSION, FRAME);
|
||||
metadata.setFrameHandler(methodHandle, onmethod);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ package org.eclipse.jetty.websocket.common.endpoints.annotated;
|
|||
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketFrame;
|
||||
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
|
||||
import org.eclipse.jetty.websocket.core.Frame;
|
||||
import org.eclipse.jetty.websocket.api.extensions.Frame;
|
||||
|
||||
@WebSocket
|
||||
public class FrameSocket
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.eclipse.jetty.servlet.ServletContextHandler;
|
|||
import org.eclipse.jetty.util.component.LifeCycle;
|
||||
import org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandlerFactory;
|
||||
import org.eclipse.jetty.websocket.core.FrameHandler;
|
||||
import org.eclipse.jetty.websocket.server.internal.UpgradeRequestAdapter;
|
||||
import org.eclipse.jetty.websocket.server.internal.DelegatedJettyServletUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.server.internal.UpgradeResponseAdapter;
|
||||
import org.eclipse.jetty.websocket.servlet.FrameHandlerFactory;
|
||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
|
||||
|
@ -67,7 +67,7 @@ public class JettyServerFrameHandlerFactory
|
|||
@Override
|
||||
public FrameHandler newFrameHandler(Object websocketPojo, ServletUpgradeRequest upgradeRequest, ServletUpgradeResponse upgradeResponse)
|
||||
{
|
||||
return super.newJettyFrameHandler(websocketPojo, new UpgradeRequestAdapter(upgradeRequest), new UpgradeResponseAdapter(upgradeResponse),
|
||||
return super.newJettyFrameHandler(websocketPojo, new DelegatedJettyServletUpgradeRequest(upgradeRequest), new UpgradeResponseAdapter(upgradeResponse),
|
||||
new CompletableFuture<>());
|
||||
}
|
||||
|
||||
|
|
|
@ -18,10 +18,6 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.server.internal;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.UpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
|
||||
|
||||
import java.net.HttpCookie;
|
||||
import java.net.URI;
|
||||
import java.security.Principal;
|
||||
|
@ -29,11 +25,15 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class UpgradeRequestAdapter implements UpgradeRequest
|
||||
import org.eclipse.jetty.websocket.api.UpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
|
||||
|
||||
public class DelegatedJettyServletUpgradeRequest implements UpgradeRequest
|
||||
{
|
||||
private final ServletUpgradeRequest servletRequest;
|
||||
|
||||
public UpgradeRequestAdapter(ServletUpgradeRequest servletRequest)
|
||||
public DelegatedJettyServletUpgradeRequest(ServletUpgradeRequest servletRequest)
|
||||
{
|
||||
this.servletRequest = servletRequest;
|
||||
}
|
|
@ -13,7 +13,7 @@
|
|||
<name>Jetty :: Websocket :: org.eclipse.jetty.websocket :: Tests</name>
|
||||
|
||||
<properties>
|
||||
<bundle-symbolic-name>${project.groupId}.jetty.tests</bundle-symbolic-name>
|
||||
<bundle-symbolic-name>${project.groupId}.jetty.websocket.tests</bundle-symbolic-name>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
@ -32,6 +32,11 @@
|
|||
<artifactId>jetty-websocket-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>jetty-http-tools</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-helper</artifactId>
|
||||
|
@ -42,37 +47,25 @@
|
|||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<extensions>true</extensions>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>ban-java-servlet-api</id>
|
||||
<goals>
|
||||
<goal>enforce</goal>
|
||||
<goal>manifest</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<rules>
|
||||
<bannedDependencies>
|
||||
<includes>
|
||||
<include>javax.servlet</include>
|
||||
<include>servletapi</include>
|
||||
<include>org.eclipse.jetty.orbit:javax.servlet</include>
|
||||
<include>org.mortbay.jetty:servlet-api</include>
|
||||
<include>jetty:servlet-api</include>
|
||||
</includes>
|
||||
</bannedDependencies>
|
||||
</rules>
|
||||
<instructions>
|
||||
<Bundle-Description>jetty.websocket Integration Tests</Bundle-Description>
|
||||
<Export-Package>
|
||||
org.eclipse.jetty.websocket.jetty.tests.*;version="${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}"
|
||||
</Export-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
|
@ -40,7 +40,7 @@ import org.junit.jupiter.api.Test;
|
|||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class JettyWebsocketTest
|
||||
public class JettyWebSocketTest
|
||||
{
|
||||
|
||||
@WebSocket
|
|
@ -27,7 +27,7 @@ import java.util.Map;
|
|||
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.websocket.core.client.UpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.core.client.ClientUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.core.server.Negotiation;
|
||||
|
||||
/**
|
||||
|
@ -42,8 +42,8 @@ import org.eclipse.jetty.websocket.core.server.Negotiation;
|
|||
* <li>On the server, the application layer must provide a {@link org.eclipse.jetty.websocket.core.server.WebSocketNegotiator} instance
|
||||
* to negotiate and accept websocket connections, which will return the FrameHandler instance to use from
|
||||
* {@link org.eclipse.jetty.websocket.core.server.WebSocketNegotiator#negotiate(Negotiation)}.</li>
|
||||
* <li>On the client, the application returns the FrameHandler instance to user from the {@link UpgradeRequest}
|
||||
* instance that it passes to the {@link org.eclipse.jetty.websocket.core.client.WebSocketCoreClient#connect(UpgradeRequest)} method/</li>
|
||||
* <li>On the client, the application returns the FrameHandler instance to user from the {@link ClientUpgradeRequest}
|
||||
* instance that it passes to the {@link org.eclipse.jetty.websocket.core.client.WebSocketCoreClient#connect(ClientUpgradeRequest)} method/</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* Once instantiated the FrameHandler follows is used as follows:
|
||||
|
|
|
@ -64,11 +64,11 @@ import org.eclipse.jetty.websocket.core.internal.WebSocketChannel;
|
|||
import org.eclipse.jetty.websocket.core.internal.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.core.internal.WebSocketCore;
|
||||
|
||||
public abstract class UpgradeRequest extends HttpRequest implements Response.CompleteListener, HttpConnectionUpgrader
|
||||
public abstract class ClientUpgradeRequest extends HttpRequest implements Response.CompleteListener, HttpConnectionUpgrader
|
||||
{
|
||||
public static UpgradeRequest from(WebSocketCoreClient webSocketClient, URI requestURI, FrameHandler frameHandler)
|
||||
public static ClientUpgradeRequest from(WebSocketCoreClient webSocketClient, URI requestURI, FrameHandler frameHandler)
|
||||
{
|
||||
return new UpgradeRequest(webSocketClient, requestURI)
|
||||
return new ClientUpgradeRequest(webSocketClient, requestURI)
|
||||
{
|
||||
@Override
|
||||
public FrameHandler getFrameHandler(WebSocketCoreClient coreClient, HttpResponse response)
|
||||
|
@ -78,7 +78,7 @@ public abstract class UpgradeRequest extends HttpRequest implements Response.Com
|
|||
};
|
||||
}
|
||||
|
||||
private static final Logger LOG = Log.getLogger(UpgradeRequest.class);
|
||||
private static final Logger LOG = Log.getLogger(ClientUpgradeRequest.class);
|
||||
protected final CompletableFuture<FrameHandler.CoreSession> futureCoreSession;
|
||||
private final WebSocketCoreClient wsClient;
|
||||
private List<UpgradeListener> upgradeListeners = new ArrayList<>();
|
||||
|
@ -91,7 +91,7 @@ public abstract class UpgradeRequest extends HttpRequest implements Response.Com
|
|||
*/
|
||||
private List<String> subProtocols = new ArrayList<>();
|
||||
|
||||
public UpgradeRequest(WebSocketCoreClient webSocketClient, URI requestURI)
|
||||
public ClientUpgradeRequest(WebSocketCoreClient webSocketClient, URI requestURI)
|
||||
{
|
||||
super(webSocketClient.getHttpClient(), new HttpConversation(), requestURI);
|
||||
|
||||
|
@ -347,11 +347,12 @@ public abstract class UpgradeRequest extends HttpRequest implements Response.Com
|
|||
try
|
||||
{
|
||||
endp.upgrade(wsConnection);
|
||||
}
|
||||
finally
|
||||
{
|
||||
futureCoreSession.complete(wsChannel);
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
futureCoreSession.completeExceptionally(t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
|
@ -83,11 +83,11 @@ public class WebSocketCoreClient extends ContainerLifeCycle implements FrameHand
|
|||
|
||||
public CompletableFuture<FrameHandler.CoreSession> connect(FrameHandler frameHandler, URI wsUri) throws IOException
|
||||
{
|
||||
UpgradeRequest request = UpgradeRequest.from(this, wsUri, frameHandler);
|
||||
ClientUpgradeRequest request = ClientUpgradeRequest.from(this, wsUri, frameHandler);
|
||||
return connect(request);
|
||||
}
|
||||
|
||||
public CompletableFuture<FrameHandler.CoreSession> connect(UpgradeRequest request) throws IOException
|
||||
public CompletableFuture<FrameHandler.CoreSession> connect(ClientUpgradeRequest request) throws IOException
|
||||
{
|
||||
if (!isStarted())
|
||||
{
|
||||
|
|
|
@ -18,13 +18,6 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.core.chat;
|
||||
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.websocket.core.MessageHandler;
|
||||
import org.eclipse.jetty.websocket.core.client.UpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URI;
|
||||
|
@ -34,6 +27,13 @@ import java.util.concurrent.TimeUnit;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.websocket.core.MessageHandler;
|
||||
import org.eclipse.jetty.websocket.core.client.ClientUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
|
||||
|
||||
public class ChatWebSocketClient
|
||||
{
|
||||
private static Logger LOG = Log.getLogger(ChatWebSocketClient.class);
|
||||
|
@ -51,7 +51,7 @@ public class ChatWebSocketClient
|
|||
|
||||
URI wsUri = baseWebsocketUri.resolve("/chat");
|
||||
handler = MessageHandler.from(this::onText, null);
|
||||
UpgradeRequest request = UpgradeRequest.from(client, wsUri, handler);
|
||||
ClientUpgradeRequest request = ClientUpgradeRequest.from(client, wsUri, handler);
|
||||
request.setSubProtocols("chat");
|
||||
client.connect(request).get(5, TimeUnit.SECONDS);
|
||||
handler.sendText("[" + name + ": has joined the room]", Callback.NOOP, false);
|
||||
|
|
|
@ -179,7 +179,7 @@ public class WebSocketClientServerTest
|
|||
|
||||
public void start() throws Exception
|
||||
{
|
||||
UpgradeRequest request = UpgradeRequest.from(client, baseWebSocketUri.resolve("/test"), handler);
|
||||
ClientUpgradeRequest request = ClientUpgradeRequest.from(client, baseWebSocketUri.resolve("/test"), handler);
|
||||
request.setSubProtocols("test");
|
||||
this.client.start();
|
||||
Future<FrameHandler.CoreSession> response = client.connect(request);
|
||||
|
|
Loading…
Reference in New Issue