Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package io.undertow.servlet.test.streams;

import io.undertow.httpcore.StatusCodes;
import io.undertow.servlet.api.ServletInfo;
import io.undertow.servlet.test.util.DeploymentUtils;
import io.undertow.testutils.DefaultServer;
import io.undertow.testutils.HttpClientUtils;
import io.undertow.testutils.TestHttpClient;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
Expand All @@ -13,35 +11,19 @@
import io.vertx.core.http.HttpClientRequest;
import io.vertx.core.http.HttpClientResponse;
import io.vertx.core.http.HttpVersion;
import org.apache.commons.codec.binary.Hex;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,23 @@
import io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtensionHandshaker;
import io.undertow.websockets.annotated.AnnotatedEndpointFactory;
import io.undertow.websockets.handshake.Handshake;
import io.undertow.websockets.util.ObjectIntrospecter;
import io.undertow.websockets.util.ConstructorObjectFactory;
import io.undertow.websockets.util.ContextSetupHandler;
import io.undertow.websockets.util.ImmediateObjectHandle;
import io.undertow.websockets.util.ObjectFactory;
import io.undertow.websockets.util.ObjectHandle;
import io.undertow.websockets.util.ObjectIntrospecter;
import io.undertow.websockets.util.PathTemplate;
import io.undertow.websockets.util.ContextSetupHandler;

import javax.net.ssl.SSLContext;
import javax.websocket.ClientEndpoint;
import javax.websocket.ClientEndpointConfig;
import javax.websocket.CloseReason;
import javax.websocket.Decoder;
import javax.websocket.DeploymentException;
import javax.websocket.Encoder;
import javax.websocket.Endpoint;
import javax.websocket.EndpointConfig;
import javax.websocket.Extension;
import javax.websocket.HandshakeResponse;
import javax.websocket.Session;
Expand Down Expand Up @@ -74,6 +77,7 @@
import java.util.function.Supplier;

import static java.lang.System.currentTimeMillis;
import static java.util.Collections.emptyMap;


/**
Expand Down Expand Up @@ -180,18 +184,6 @@ protected Supplier<Executor> getExecutorSupplier() {
return executorSupplier;
}

public Session connectToServer(final Object annotatedEndpointInstance, WebsocketConnectionBuilder connectionBuilder) throws DeploymentException, IOException {
if (closed) {
throw new ClosedChannelException();
}
ConfiguredClientEndpoint config = getClientEndpoint(annotatedEndpointInstance.getClass(), false);
if (config == null) {
throw JsrWebSocketMessages.MESSAGES.notAValidClientEndpointType(annotatedEndpointInstance.getClass());
}
Endpoint instance = config.getFactory().createInstance(new ImmediateObjectHandle<>(annotatedEndpointInstance));
return connectToServerInternal(instance, config, connectionBuilder);
}

@Override
public Session connectToServer(final Object annotatedEndpointInstance, final URI path) throws DeploymentException, IOException {
if (closed) {
Expand Down Expand Up @@ -580,7 +572,8 @@ private synchronized void addEndpointInternal(final Class<?> endpoint, boolean r
Class<? extends ServerEndpointConfig.Configurator> configuratorClass = serverEndpoint.configurator();

EncodingFactory encodingFactory = EncodingFactory.createFactory(objectIntrospecter, serverEndpoint.decoders(), serverEndpoint.encoders());
AnnotatedEndpointFactory annotatedEndpointFactory = AnnotatedEndpointFactory.create(endpoint, encodingFactory, template.getParameterNames());
EndpointConfig endpointConfig = createEndpointConfig(serverEndpoint.encoders(), serverEndpoint.decoders());
AnnotatedEndpointFactory annotatedEndpointFactory = AnnotatedEndpointFactory.create(endpoint, encodingFactory, template.getParameterNames(), endpointConfig);
ObjectFactory<?> ObjectFactory = null;
try {
ObjectFactory = objectIntrospecter.createInstanceFactory(endpoint);
Expand All @@ -605,12 +598,12 @@ public ObjectHandle<Object> createInstance() {
}

ServerEndpointConfig config = ServerEndpointConfig.Builder.create(endpoint, serverEndpoint.value())
.decoders(Arrays.asList(serverEndpoint.decoders()))
.encoders(Arrays.asList(serverEndpoint.encoders()))
.subprotocols(Arrays.asList(serverEndpoint.subprotocols()))
.extensions(Collections.<Extension>emptyList())
.configurator(configurator)
.build();
.decoders(Arrays.asList(serverEndpoint.decoders()))
.encoders(Arrays.asList(serverEndpoint.encoders()))
.subprotocols(Arrays.asList(serverEndpoint.subprotocols()))
.extensions(Collections.<Extension>emptyList())
.configurator(configurator)
.build();


ConfiguredServerEndpoint confguredServerEndpoint = new ConfiguredServerEndpoint(config, ObjectFactory, template, encodingFactory, annotatedEndpointFactory, installedExtensions);
Expand Down Expand Up @@ -638,17 +631,19 @@ public ObjectHandle<Object> createInstance() {
}
}
}
AnnotatedEndpointFactory factory = AnnotatedEndpointFactory.create(endpoint, encodingFactory, Collections.<String>emptySet());

EndpointConfig endpointConfig = createEndpointConfig(clientEndpoint.encoders(), clientEndpoint.decoders());
AnnotatedEndpointFactory factory = AnnotatedEndpointFactory.create(endpoint, encodingFactory, Collections.<String>emptySet(), endpointConfig);

ClientEndpointConfig.Configurator configurator = null;
configurator = objectIntrospecter.createInstanceFactory(clientEndpoint.configurator()).createInstance().getInstance();

ClientEndpointConfig config = ClientEndpointConfig.Builder.create()
.decoders(Arrays.asList(clientEndpoint.decoders()))
.encoders(Arrays.asList(clientEndpoint.encoders()))
.preferredSubprotocols(Arrays.asList(clientEndpoint.subprotocols()))
.configurator(configurator)
.build();
.decoders(Arrays.asList(clientEndpoint.decoders()))
.encoders(Arrays.asList(clientEndpoint.encoders()))
.preferredSubprotocols(Arrays.asList(clientEndpoint.subprotocols()))
.configurator(configurator)
.build();

ConfiguredClientEndpoint configuredClientEndpoint = new ConfiguredClientEndpoint(config, factory, encodingFactory, ObjectFactory);
clientEndpoints.put(endpoint, configuredClientEndpoint);
Expand All @@ -657,6 +652,25 @@ public ObjectHandle<Object> createInstance() {
}
}

private EndpointConfig createEndpointConfig(Class<? extends Encoder>[] encoders, Class<? extends Decoder>[] decoders) {
return new EndpointConfig() {
@Override
public List<Class<? extends Encoder>> getEncoders() {
return Arrays.asList(encoders);
}

@Override
public List<Class<? extends Decoder>> getDecoders() {
return Arrays.asList(decoders);
}

@Override
public Map<String, Object> getUserProperties() {
return emptyMap();
}
};
}


protected void handleAddingFilterMapping() {
}
Expand Down Expand Up @@ -684,7 +698,7 @@ public void addEndpoint(final ServerEndpointConfig endpoint) throws DeploymentEx
AnnotatedEndpointFactory annotatedEndpointFactory = null;
if (!Endpoint.class.isAssignableFrom(endpoint.getEndpointClass())) {
// We may want to check that the path in @ServerEndpoint matches the specified path, and throw if they are not equivalent
annotatedEndpointFactory = AnnotatedEndpointFactory.create(endpoint.getEndpointClass(), encodingFactory, template.getParameterNames());
annotatedEndpointFactory = AnnotatedEndpointFactory.create(endpoint.getEndpointClass(), encodingFactory, template.getParameterNames(), endpoint);
}
ConfiguredServerEndpoint confguredServerEndpoint = new ConfiguredServerEndpoint(endpoint, null, template, encodingFactory, annotatedEndpointFactory, endpoint.getExtensions());
configuredServerEndpoints.add(confguredServerEndpoint);
Expand Down
Loading