From cf3d8616f86bf9a4ff68d691e362e272956b96d0 Mon Sep 17 00:00:00 2001 From: Michel Jung Date: Sun, 7 Feb 2021 22:49:43 +0100 Subject: [PATCH 1/7] Simplify AnnotatedEndpointFactory --- .../annotated/AnnotatedEndpointFactory.java | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/websockets-jsr/src/main/java/io/undertow/websockets/jsr/annotated/AnnotatedEndpointFactory.java b/websockets-jsr/src/main/java/io/undertow/websockets/jsr/annotated/AnnotatedEndpointFactory.java index 7664c748c..6006c1a50 100644 --- a/websockets-jsr/src/main/java/io/undertow/websockets/jsr/annotated/AnnotatedEndpointFactory.java +++ b/websockets-jsr/src/main/java/io/undertow/websockets/jsr/annotated/AnnotatedEndpointFactory.java @@ -75,7 +75,6 @@ private AnnotatedEndpointFactory(final Class endpointClass, final BoundMethod public static AnnotatedEndpointFactory create(final Class endpointClass, final EncodingFactory encodingFactory, final Set paths) throws DeploymentException { - final Set> found = new HashSet<>(); BoundMethod onOpen = null; BoundMethod onClose = null; BoundMethod onError = null; @@ -87,40 +86,37 @@ public static AnnotatedEndpointFactory create(final Class endpointClass, fina do { for (final Method method : c.getDeclaredMethods()) { if (method.isAnnotationPresent(OnOpen.class)) { - if (found.contains(OnOpen.class)) { + if (onOpen != null) { if(!onOpen.overrides(method)) { throw JsrWebSocketMessages.MESSAGES.moreThanOneAnnotation(OnOpen.class); } else { continue; } } - found.add(OnOpen.class); onOpen = new BoundMethod(method, null, false, 0, new BoundSingleParameter(method, Session.class, true), new BoundSingleParameter(method, EndpointConfig.class, true), createBoundPathParameters(method, paths, endpointClass)); } if (method.isAnnotationPresent(OnClose.class)) { - if (found.contains(OnClose.class)) { + if (onClose != null) { if(!onClose.overrides(method)) { throw JsrWebSocketMessages.MESSAGES.moreThanOneAnnotation(OnClose.class); } else { continue; } } - found.add(OnClose.class); onClose = new BoundMethod(method, null, false, 0, new BoundSingleParameter(method, Session.class, true), new BoundSingleParameter(method, CloseReason.class, true), createBoundPathParameters(method, paths, endpointClass)); } if (method.isAnnotationPresent(OnError.class)) { - if (found.contains(OnError.class)) { + if (onError != null) { if(!onError.overrides(method)) { throw JsrWebSocketMessages.MESSAGES.moreThanOneAnnotation(OnError.class); } else { continue; } } - found.add(OnError.class); onError = new BoundMethod(method, null, false, 0, new BoundSingleParameter(method, Session.class, true), new BoundSingleParameter(method, Throwable.class, false), createBoundPathParameters(method, paths, endpointClass)); @@ -365,25 +361,21 @@ public Class getType() { */ private static class BoundPathParameters implements BoundParameter { - private final Class endpointClass; - private final Set paths; private final String[] positions; private final Encoding[] encoders; private final Class[] types; BoundPathParameters(final String[] positions, final Method method, Class endpointClass, Set paths) throws DeploymentException { this.positions = positions; - this.endpointClass = endpointClass; - this.paths = paths; this.encoders = new Encoding[positions.length]; this.types = new Class[positions.length]; for (int i = 0; i < positions.length; ++i) { Class type = method.getParameterTypes()[i]; Annotation[] annotations = method.getParameterAnnotations()[i]; - for(int j = 0; j < annotations.length; ++j) { - if(annotations[j] instanceof PathParam) { - PathParam param = (PathParam) annotations[j]; - if(!paths.contains(param.value())) { + for (Annotation annotation : annotations) { + if (annotation instanceof PathParam) { + PathParam param = (PathParam) annotation; + if (!paths.contains(param.value())) { JsrWebSocketLogger.ROOT_LOGGER.pathTemplateNotFound(endpointClass, param, method, paths); } } From 8403f588b68b74ee1610613153ad27095850a91a Mon Sep 17 00:00:00 2001 From: Michel Jung Date: Sun, 7 Feb 2021 22:56:19 +0100 Subject: [PATCH 2/7] Format source code --- .../annotated/AnnotatedEndpointFactory.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/websockets-jsr/src/main/java/io/undertow/websockets/jsr/annotated/AnnotatedEndpointFactory.java b/websockets-jsr/src/main/java/io/undertow/websockets/jsr/annotated/AnnotatedEndpointFactory.java index 6006c1a50..1af4e15a7 100644 --- a/websockets-jsr/src/main/java/io/undertow/websockets/jsr/annotated/AnnotatedEndpointFactory.java +++ b/websockets-jsr/src/main/java/io/undertow/websockets/jsr/annotated/AnnotatedEndpointFactory.java @@ -87,7 +87,7 @@ public static AnnotatedEndpointFactory create(final Class endpointClass, fina for (final Method method : c.getDeclaredMethods()) { if (method.isAnnotationPresent(OnOpen.class)) { if (onOpen != null) { - if(!onOpen.overrides(method)) { + if (!onOpen.overrides(method)) { throw JsrWebSocketMessages.MESSAGES.moreThanOneAnnotation(OnOpen.class); } else { continue; @@ -99,7 +99,7 @@ public static AnnotatedEndpointFactory create(final Class endpointClass, fina } if (method.isAnnotationPresent(OnClose.class)) { if (onClose != null) { - if(!onClose.overrides(method)) { + if (!onClose.overrides(method)) { throw JsrWebSocketMessages.MESSAGES.moreThanOneAnnotation(OnClose.class); } else { continue; @@ -111,7 +111,7 @@ public static AnnotatedEndpointFactory create(final Class endpointClass, fina } if (method.isAnnotationPresent(OnError.class)) { if (onError != null) { - if(!onError.overrides(method)) { + if (!onError.overrides(method)) { throw JsrWebSocketMessages.MESSAGES.moreThanOneAnnotation(OnError.class); } else { continue; @@ -121,14 +121,14 @@ public static AnnotatedEndpointFactory create(final Class endpointClass, fina new BoundSingleParameter(method, Throwable.class, false), createBoundPathParameters(method, paths, endpointClass)); } - if (method.isAnnotationPresent(OnMessage.class) && ! method.isBridge()) { - if(binaryMessage != null && binaryMessage.overrides(method)) { + if (method.isAnnotationPresent(OnMessage.class) && !method.isBridge()) { + if (binaryMessage != null && binaryMessage.overrides(method)) { continue; } - if(textMessage != null && textMessage.overrides(method)) { + if (textMessage != null && textMessage.overrides(method)) { continue; } - if(pongMessage != null && pongMessage.overrides(method)) { + if (pongMessage != null && pongMessage.overrides(method)) { continue; } long maxMessageSize = method.getAnnotation(OnMessage.class).maxMessageSize(); @@ -142,7 +142,7 @@ public static AnnotatedEndpointFactory create(final Class endpointClass, fina } final Class param = parameterTypes[i]; - if(param == boolean.class || param == Boolean.class) { + if (param == boolean.class || param == Boolean.class) { booleanLocation = i; } else if (encodingFactory.canDecodeText(param)) { if (textMessage != null) { @@ -286,7 +286,7 @@ private static boolean hasAnnotation(Class annotationType, } public AnnotatedEndpoint createInstance(InstanceHandle endpointInstance) { - if(!endpointClass.isInstance(endpointInstance.getInstance())) { + if (!endpointClass.isInstance(endpointInstance.getInstance())) { throw JsrWebSocketMessages.MESSAGES.endpointNotOfCorrectType(endpointInstance, endpointClass); } return new AnnotatedEndpoint(endpointInstance, OnOpen, OnClose, OnError, textMessage, binaryMessage, pongMessage); From 7c93d8e86e7c0628185e1ab6a680c3b7e69870d0 Mon Sep 17 00:00:00 2001 From: Michel Jung Date: Sun, 7 Feb 2021 23:20:53 +0100 Subject: [PATCH 3/7] Respect endpoint encoders/decoders for path parameters `PathParameters` could only make use of the default encoding factory, which allows primitive and String types. With this change, custom encoders/decoders are considered, too. Fixes GH-52 --- .../jsr/ServerWebSocketContainer.java | 45 ++++++++++--------- .../annotated/AnnotatedEndpointFactory.java | 36 +++++++-------- .../test/annotated/AnnotatedEndpointTest.java | 1 + .../jsr/test/annotated/UuidEndpoint.java | 44 ++++++++++++++++++ 4 files changed, 86 insertions(+), 40 deletions(-) create mode 100644 websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/UuidEndpoint.java diff --git a/websockets-jsr/src/main/java/io/undertow/websockets/jsr/ServerWebSocketContainer.java b/websockets-jsr/src/main/java/io/undertow/websockets/jsr/ServerWebSocketContainer.java index be5e76c78..6f65bb0fc 100644 --- a/websockets-jsr/src/main/java/io/undertow/websockets/jsr/ServerWebSocketContainer.java +++ b/websockets-jsr/src/main/java/io/undertow/websockets/jsr/ServerWebSocketContainer.java @@ -463,7 +463,7 @@ public InstanceHandle createInstance() throws InstantiationException { AnnotatedEndpointFactory annotatedEndpointFactory = null; if (!Endpoint.class.isAssignableFrom(sec.getEndpointClass())) { - annotatedEndpointFactory = AnnotatedEndpointFactory.create(sec.getEndpointClass(), encodingFactory, pt.getParameterNames()); + annotatedEndpointFactory = AnnotatedEndpointFactory.create(sec.getEndpointClass(), encodingFactory, pt.getParameterNames(), config); } @@ -686,24 +686,6 @@ private synchronized void addEndpointInternal(final Class endpoint, boolean r seenPaths.add(template); Class configuratorClass = serverEndpoint.configurator(); - EncodingFactory encodingFactory = EncodingFactory.createFactory(classIntrospecter, serverEndpoint.decoders(), serverEndpoint.encoders()); - AnnotatedEndpointFactory annotatedEndpointFactory = AnnotatedEndpointFactory.create(endpoint, encodingFactory, template.getParameterNames()); - InstanceFactory instanceFactory = null; - try { - instanceFactory = classIntrospecter.createInstanceFactory(endpoint); - } catch (Exception e) { - //so it is possible that this is still valid if a custom configurator is in use - if (configuratorClass == ServerEndpointConfig.Configurator.class) { - throw JsrWebSocketMessages.MESSAGES.couldNotDeploy(e); - } else { - instanceFactory = new InstanceFactory() { - @Override - public InstanceHandle createInstance() throws InstantiationException { - throw JsrWebSocketMessages.MESSAGES.endpointDoesNotHaveAppropriateConstructor(endpoint); - } - }; - } - } ServerEndpointConfig.Configurator configurator; if (configuratorClass != ServerEndpointConfig.Configurator.class) { try { @@ -719,10 +701,28 @@ public InstanceHandle createInstance() throws InstantiationException { .decoders(Arrays.asList(serverEndpoint.decoders())) .encoders(Arrays.asList(serverEndpoint.encoders())) .subprotocols(Arrays.asList(serverEndpoint.subprotocols())) - .extensions(Collections.emptyList()) + .extensions(Collections.emptyList()) .configurator(configurator) .build(); + EncodingFactory encodingFactory = EncodingFactory.createFactory(classIntrospecter, serverEndpoint.decoders(), serverEndpoint.encoders()); + AnnotatedEndpointFactory annotatedEndpointFactory = AnnotatedEndpointFactory.create(endpoint, encodingFactory, template.getParameterNames(), config); + InstanceFactory instanceFactory = null; + try { + instanceFactory = classIntrospecter.createInstanceFactory(endpoint); + } catch (Exception e) { + //so it is possible that this is still valid if a custom configurator is in use + if (configuratorClass == ServerEndpointConfig.Configurator.class) { + throw JsrWebSocketMessages.MESSAGES.couldNotDeploy(e); + } else { + instanceFactory = new InstanceFactory() { + @Override + public InstanceHandle createInstance() throws InstantiationException { + throw JsrWebSocketMessages.MESSAGES.endpointDoesNotHaveAppropriateConstructor(endpoint); + } + }; + } + } ConfiguredServerEndpoint confguredServerEndpoint = new ConfiguredServerEndpoint(config, instanceFactory, template, encodingFactory, annotatedEndpointFactory, installedExtensions); configuredServerEndpoints.add(confguredServerEndpoint); @@ -749,7 +749,6 @@ public InstanceHandle createInstance() throws InstantiationException { } } } - AnnotatedEndpointFactory factory = AnnotatedEndpointFactory.create(endpoint, encodingFactory, Collections.emptySet()); ClientEndpointConfig.Configurator configurator = null; try { @@ -764,6 +763,8 @@ public InstanceHandle createInstance() throws InstantiationException { .configurator(configurator) .build(); + AnnotatedEndpointFactory factory = AnnotatedEndpointFactory.create(endpoint, encodingFactory, Collections.emptySet(), config); + ConfiguredClientEndpoint configuredClientEndpoint = new ConfiguredClientEndpoint(config, factory, encodingFactory, instanceFactory); clientEndpoints.put(endpoint, configuredClientEndpoint); } else { @@ -803,7 +804,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); diff --git a/websockets-jsr/src/main/java/io/undertow/websockets/jsr/annotated/AnnotatedEndpointFactory.java b/websockets-jsr/src/main/java/io/undertow/websockets/jsr/annotated/AnnotatedEndpointFactory.java index 1af4e15a7..8b8580813 100644 --- a/websockets-jsr/src/main/java/io/undertow/websockets/jsr/annotated/AnnotatedEndpointFactory.java +++ b/websockets-jsr/src/main/java/io/undertow/websockets/jsr/annotated/AnnotatedEndpointFactory.java @@ -74,7 +74,7 @@ private AnnotatedEndpointFactory(final Class endpointClass, final BoundMethod } - public static AnnotatedEndpointFactory create(final Class endpointClass, final EncodingFactory encodingFactory, final Set paths) throws DeploymentException { + public static AnnotatedEndpointFactory create(final Class endpointClass, final EncodingFactory encodingFactory, final Set paths, final EndpointConfig endpointConfig) throws DeploymentException { BoundMethod onOpen = null; BoundMethod onClose = null; BoundMethod onError = null; @@ -95,7 +95,7 @@ public static AnnotatedEndpointFactory create(final Class endpointClass, fina } onOpen = new BoundMethod(method, null, false, 0, new BoundSingleParameter(method, Session.class, true), new BoundSingleParameter(method, EndpointConfig.class, true), - createBoundPathParameters(method, paths, endpointClass)); + createBoundPathParameters(method, paths, endpointClass, encodingFactory, endpointConfig)); } if (method.isAnnotationPresent(OnClose.class)) { if (onClose != null) { @@ -107,7 +107,7 @@ public static AnnotatedEndpointFactory create(final Class endpointClass, fina } onClose = new BoundMethod(method, null, false, 0, new BoundSingleParameter(method, Session.class, true), new BoundSingleParameter(method, CloseReason.class, true), - createBoundPathParameters(method, paths, endpointClass)); + createBoundPathParameters(method, paths, endpointClass, encodingFactory, endpointConfig)); } if (method.isAnnotationPresent(OnError.class)) { if (onError != null) { @@ -119,7 +119,7 @@ public static AnnotatedEndpointFactory create(final Class endpointClass, fina } onError = new BoundMethod(method, null, false, 0, new BoundSingleParameter(method, Session.class, true), new BoundSingleParameter(method, Throwable.class, false), - createBoundPathParameters(method, paths, endpointClass)); + createBoundPathParameters(method, paths, endpointClass, encodingFactory, endpointConfig)); } if (method.isAnnotationPresent(OnMessage.class) && !method.isBridge()) { if (binaryMessage != null && binaryMessage.overrides(method)) { @@ -150,7 +150,7 @@ public static AnnotatedEndpointFactory create(final Class endpointClass, fina } textMessage = new BoundMethod(method, param, true, maxMessageSize, new BoundSingleParameter(method, Session.class, true), new BoundSingleParameter(i, param), - createBoundPathParameters(method, paths, endpointClass)); + createBoundPathParameters(method, paths, endpointClass, encodingFactory, endpointConfig)); messageHandled = true; break; } else if (encodingFactory.canDecodeBinary(param)) { @@ -159,7 +159,7 @@ public static AnnotatedEndpointFactory create(final Class endpointClass, fina } binaryMessage = new BoundMethod(method, param, true, maxMessageSize, new BoundSingleParameter(method, Session.class, true), new BoundSingleParameter(i, param), - createBoundPathParameters(method, paths, endpointClass)); + createBoundPathParameters(method, paths, endpointClass, encodingFactory, endpointConfig)); messageHandled = true; break; } else if (param.equals(byte[].class)) { @@ -169,7 +169,7 @@ public static AnnotatedEndpointFactory create(final Class endpointClass, fina binaryMessage = new BoundMethod(method, byte[].class, false, maxMessageSize, new BoundSingleParameter(method, Session.class, true), new BoundSingleParameter(method, boolean.class, true), new BoundSingleParameter(i, byte[].class), - createBoundPathParameters(method, paths, endpointClass)); + createBoundPathParameters(method, paths, endpointClass, encodingFactory, endpointConfig)); messageHandled = true; break; } else if (param.equals(ByteBuffer.class)) { @@ -180,7 +180,7 @@ public static AnnotatedEndpointFactory create(final Class endpointClass, fina maxMessageSize, new BoundSingleParameter(method, Session.class, true), new BoundSingleParameter(method, boolean.class, true), new BoundSingleParameter(i, ByteBuffer.class), - createBoundPathParameters(method, paths, endpointClass)); + createBoundPathParameters(method, paths, endpointClass, encodingFactory, endpointConfig)); messageHandled = true; break; @@ -191,7 +191,7 @@ maxMessageSize, new BoundSingleParameter(method, Session.class, true), binaryMessage = new BoundMethod(method, InputStream.class, false, maxMessageSize, new BoundSingleParameter(method, Session.class, true), new BoundSingleParameter(i, InputStream.class), - createBoundPathParameters(method, paths, endpointClass)); + createBoundPathParameters(method, paths, endpointClass, encodingFactory, endpointConfig)); messageHandled = true; break; @@ -202,7 +202,7 @@ maxMessageSize, new BoundSingleParameter(method, Session.class, true), textMessage = new BoundMethod(method, String.class, false, maxMessageSize, new BoundSingleParameter(method, Session.class, true), new BoundSingleParameter(method, boolean.class, true), new BoundSingleParameter(i, String.class), - createBoundPathParameters(method, paths, endpointClass)); + createBoundPathParameters(method, paths, endpointClass, encodingFactory, endpointConfig)); messageHandled = true; break; @@ -213,7 +213,7 @@ maxMessageSize, new BoundSingleParameter(method, Session.class, true), textMessage = new BoundMethod(method, Reader.class, false, maxMessageSize, new BoundSingleParameter(method, Session.class, true), new BoundSingleParameter(i, Reader.class), - createBoundPathParameters(method, paths, endpointClass)); + createBoundPathParameters(method, paths, endpointClass, encodingFactory, endpointConfig)); messageHandled = true; break; @@ -223,7 +223,7 @@ maxMessageSize, new BoundSingleParameter(method, Session.class, true), } pongMessage = new BoundMethod(method, PongMessage.class, false, maxMessageSize, new BoundSingleParameter(method, Session.class, true), new BoundSingleParameter(i, PongMessage.class), - createBoundPathParameters(method, paths, endpointClass)); + createBoundPathParameters(method, paths, endpointClass, encodingFactory, endpointConfig)); messageHandled = true; break; } @@ -237,7 +237,7 @@ maxMessageSize, new BoundSingleParameter(method, Session.class, true), textMessage = new BoundMethod(method, boolClass, true, maxMessageSize, new BoundSingleParameter(method, Session.class, true), new BoundSingleParameter(method, boolean.class, true), new BoundSingleParameter(booleanLocation, boolClass), - createBoundPathParameters(method, paths, endpointClass)); + createBoundPathParameters(method, paths, endpointClass, encodingFactory, endpointConfig)); messageHandled = true; } if (!messageHandled) { @@ -250,8 +250,8 @@ maxMessageSize, new BoundSingleParameter(method, Session.class, true), return new AnnotatedEndpointFactory(endpointClass, onOpen, onClose, onError, textMessage, binaryMessage, pongMessage); } - private static BoundPathParameters createBoundPathParameters(final Method method, Set paths, Class endpointClass) throws DeploymentException { - return new BoundPathParameters(pathParams(method), method, endpointClass, paths); + private static BoundPathParameters createBoundPathParameters(final Method method, Set paths, Class endpointClass, final EncodingFactory encodingFactory, final EndpointConfig endpointConfig) throws DeploymentException { + return new BoundPathParameters(pathParams(method), method, endpointClass, paths, encodingFactory, endpointConfig); } @@ -365,7 +365,7 @@ private static class BoundPathParameters implements BoundParameter { private final Encoding[] encoders; private final Class[] types; - BoundPathParameters(final String[] positions, final Method method, Class endpointClass, Set paths) throws DeploymentException { + BoundPathParameters(final String[] positions, final Method method, Class endpointClass, Set paths, final EncodingFactory encodingFactory, final EndpointConfig endpointConfig) throws DeploymentException { this.positions = positions; this.encoders = new Encoding[positions.length]; this.types = new Class[positions.length]; @@ -383,8 +383,8 @@ private static class BoundPathParameters implements BoundParameter { if (positions[i] == null || type == null || type == String.class) { continue; } - if (EncodingFactory.DEFAULT.canEncodeText(type)) { - encoders[i] = EncodingFactory.DEFAULT.createEncoding(EmptyEndpointConfig.INSTANCE); + if (encodingFactory.canEncodeText(type)) { + encoders[i] = encodingFactory.createEncoding(endpointConfig); types[i] = type; } else { diff --git a/websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/AnnotatedEndpointTest.java b/websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/AnnotatedEndpointTest.java index 1d94407ee..bce29d6fe 100644 --- a/websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/AnnotatedEndpointTest.java +++ b/websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/AnnotatedEndpointTest.java @@ -87,6 +87,7 @@ public static void setup() throws Exception { .addEndpoint(AnnotatedClientEndpoint.class) .addEndpoint(AnnotatedClientEndpointWithConfigurator.class) .addEndpoint(IncrementEndpoint.class) + .addEndpoint(UuidEndpoint.class) .addEndpoint(EncodingEndpoint.class) .addEndpoint(EncodingGenericsEndpoint.class) .addEndpoint(TimeoutEndpoint.class) diff --git a/websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/UuidEndpoint.java b/websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/UuidEndpoint.java new file mode 100644 index 000000000..f11239bd8 --- /dev/null +++ b/websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/UuidEndpoint.java @@ -0,0 +1,44 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2014 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.undertow.websockets.jsr.test.annotated; + +import javax.websocket.EndpointConfig; +import javax.websocket.OnMessage; +import javax.websocket.OnOpen; +import javax.websocket.Session; +import javax.websocket.server.PathParam; +import javax.websocket.server.ServerEndpoint; +import java.util.UUID; + +@ServerEndpoint("/uuid/{id}") +public class UuidEndpoint { + + UUID id; + + @OnOpen + public void open(Session session, EndpointConfig config, @PathParam("id") UUID id) { + this.id = id; + } + + @OnMessage + public String handleMessage(String message) { + return message + id; + } + +} From 693c30cecbf0a4328345f4eeaf076af0d89359df Mon Sep 17 00:00:00 2001 From: Michel Jung Date: Mon, 8 Feb 2021 19:08:06 +0100 Subject: [PATCH 4/7] Fix decoding of non-text values I'm not sure how this worked for other decoders, but calling `canEncodeText()` when decoding a value seems wrong. --- .../annotated/AnnotatedEndpointFactory.java | 2 +- .../jsr/test/annotated/UuidDecoder.java | 33 +++++++++++++++++++ .../jsr/test/annotated/UuidEndpoint.java | 2 +- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/UuidDecoder.java diff --git a/websockets-jsr/src/main/java/io/undertow/websockets/jsr/annotated/AnnotatedEndpointFactory.java b/websockets-jsr/src/main/java/io/undertow/websockets/jsr/annotated/AnnotatedEndpointFactory.java index 8b8580813..888623b5b 100644 --- a/websockets-jsr/src/main/java/io/undertow/websockets/jsr/annotated/AnnotatedEndpointFactory.java +++ b/websockets-jsr/src/main/java/io/undertow/websockets/jsr/annotated/AnnotatedEndpointFactory.java @@ -383,7 +383,7 @@ private static class BoundPathParameters implements BoundParameter { if (positions[i] == null || type == null || type == String.class) { continue; } - if (encodingFactory.canEncodeText(type)) { + if (encodingFactory.canDecodeText(type)) { encoders[i] = encodingFactory.createEncoding(endpointConfig); types[i] = type; diff --git a/websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/UuidDecoder.java b/websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/UuidDecoder.java new file mode 100644 index 000000000..9e89c0f04 --- /dev/null +++ b/websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/UuidDecoder.java @@ -0,0 +1,33 @@ +package io.undertow.websockets.jsr.test.annotated; + +import javax.websocket.Decoder; +import javax.websocket.EndpointConfig; +import java.util.UUID; + +public class UuidDecoder implements Decoder.Text { + + @Override + public void init(EndpointConfig config) { + + } + + @Override + public void destroy() { + + } + + @Override + public UUID decode(String s) { + return UUID.fromString(s); + } + + @Override + public boolean willDecode(String s) { + try { + UUID.fromString(s); + return true; + } catch (IllegalArgumentException e) { + return false; + } + } +} \ No newline at end of file diff --git a/websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/UuidEndpoint.java b/websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/UuidEndpoint.java index f11239bd8..4a4f044d8 100644 --- a/websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/UuidEndpoint.java +++ b/websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/UuidEndpoint.java @@ -26,7 +26,7 @@ import javax.websocket.server.ServerEndpoint; import java.util.UUID; -@ServerEndpoint("/uuid/{id}") +@ServerEndpoint(value = "/uuid/{id}", decoders = UuidDecoder.class) public class UuidEndpoint { UUID id; From 88667d920f9da1d273fd07f8d5f794e2809537c6 Mon Sep 17 00:00:00 2001 From: Karel Vervaeke Date: Fri, 19 Mar 2021 16:41:42 +0100 Subject: [PATCH 5/7] Added test to make sure decoding is performed as expected + extracted method for creating ws test client --- .../test/annotated/AnnotatedEndpointTest.java | 36 +++++++++++++------ .../{UuidDecoder.java => UUIDDecoder.java} | 6 ++-- .../{UuidEndpoint.java => UUIDEndpoint.java} | 4 +-- 3 files changed, 30 insertions(+), 16 deletions(-) rename websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/{UuidDecoder.java => UUIDDecoder.java} (90%) rename websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/{UuidEndpoint.java => UUIDEndpoint.java} (93%) diff --git a/websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/AnnotatedEndpointTest.java b/websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/AnnotatedEndpointTest.java index bce29d6fe..29271644d 100644 --- a/websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/AnnotatedEndpointTest.java +++ b/websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/AnnotatedEndpointTest.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.net.URI; +import java.net.URISyntaxException; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.Set; @@ -87,7 +88,7 @@ public static void setup() throws Exception { .addEndpoint(AnnotatedClientEndpoint.class) .addEndpoint(AnnotatedClientEndpointWithConfigurator.class) .addEndpoint(IncrementEndpoint.class) - .addEndpoint(UuidEndpoint.class) + .addEndpoint(UUIDEndpoint.class) .addEndpoint(EncodingEndpoint.class) .addEndpoint(EncodingGenericsEndpoint.class) .addEndpoint(TimeoutEndpoint.class) @@ -128,19 +129,23 @@ public void testStringOnMessage() throws Exception { final byte[] payload = "hello".getBytes(); final CompletableFuture latch = new CompletableFuture(); - WebSocketTestClient client = new WebSocketTestClient(new URI("ws://" + DefaultServer.getHostAddress("default") + ":" + DefaultServer.getHostPort("default") + "/ws/chat/Stuart")); + WebSocketTestClient client = createTestClient("/ws/chat/Stuart"); client.connect(); client.send(new TextWebSocketFrame(Unpooled.wrappedBuffer(payload)), new FrameChecker(TextWebSocketFrame.class, "hello Stuart".getBytes(), latch)); latch.get(); client.destroy(); } + private WebSocketTestClient createTestClient(String s) throws URISyntaxException { + return new WebSocketTestClient(new URI("ws://" + DefaultServer.getHostAddress("default") + ":" + DefaultServer.getHostPort("default") + s)); + } + @Test public void testStringOnMessageAddedProgramatically() throws Exception { final byte[] payload = "foo".getBytes(); final CompletableFuture latch = new CompletableFuture(); - WebSocketTestClient client = new WebSocketTestClient(new URI("ws://" + DefaultServer.getHostAddress("default") + ":" + DefaultServer.getHostPort("default") + "/ws/programmatic")); + WebSocketTestClient client = createTestClient("/ws/programmatic"); client.connect(); client.send(new TextWebSocketFrame(Unpooled.wrappedBuffer(payload)), new FrameChecker(TextWebSocketFrame.class, "oof".getBytes(), latch)); latch.get(); @@ -165,7 +170,7 @@ public void testWebSocketInRootContext() throws Exception { final byte[] payload = "hello".getBytes(); final CompletableFuture latch = new CompletableFuture(); - WebSocketTestClient client = new WebSocketTestClient(new URI("ws://" + DefaultServer.getHostAddress("default") + ":" + DefaultServer.getHostPort("default") + "/ws")); + WebSocketTestClient client = createTestClient("/ws"); client.connect(); client.send(new TextWebSocketFrame(Unpooled.wrappedBuffer(payload)), new FrameChecker(TextWebSocketFrame.class, "hello".getBytes(), latch)); latch.get(); @@ -307,32 +312,43 @@ public void testImplicitIntegerConversion() throws Exception { final byte[] payload = "12".getBytes(); final CompletableFuture latch = new CompletableFuture(); - WebSocketTestClient client = new WebSocketTestClient(new URI("ws://" + DefaultServer.getHostAddress("default") + ":" + DefaultServer.getHostPort("default") + "/ws/increment/2")); + WebSocketTestClient client = createTestClient("/ws/increment/2"); client.connect(); client.send(new TextWebSocketFrame(Unpooled.wrappedBuffer(payload)), new FrameChecker(TextWebSocketFrame.class, "14".getBytes(), latch)); latch.get(); client.destroy(); } - @Test public void testEncodingAndDecodingText() throws Exception { final byte[] payload = "hello".getBytes(); final CompletableFuture latch = new CompletableFuture(); - WebSocketTestClient client = new WebSocketTestClient(new URI("ws://" + DefaultServer.getHostAddress("default") + ":" + DefaultServer.getHostPort("default") + "/ws/encoding/Stuart")); + WebSocketTestClient client = createTestClient("/ws/encoding/Stuart"); client.connect(); client.send(new TextWebSocketFrame(Unpooled.wrappedBuffer(payload)), new FrameChecker(TextWebSocketFrame.class, "hello Stuart".getBytes(), latch)); latch.get(); client.destroy(); } + @Test + public void testPathParamDecoder() throws Exception { + final byte[] payload = "hello".getBytes(); + final CompletableFuture latch = new CompletableFuture(); + + WebSocketTestClient client = createTestClient("/ws/uuid/40164304-B94D-4332-AC31-09D7F9A8B943"); + client.connect(); + client.send(new TextWebSocketFrame(Unpooled.wrappedBuffer(payload)), new FrameChecker(TextWebSocketFrame.class, "hello40164304-b94d-4332-ac31-09d7f9a8b943".getBytes(), latch)); + latch.get(); + client.destroy(); + } + @Test public void testEncodingAndDecodingBinary() throws Exception { final byte[] payload = "hello".getBytes(); final CompletableFuture latch = new CompletableFuture(); - WebSocketTestClient client = new WebSocketTestClient(new URI("ws://" + DefaultServer.getHostAddress("default") + ":" + DefaultServer.getHostPort("default") + "/ws/encoding/Stuart")); + WebSocketTestClient client = createTestClient("/ws/encoding/Stuart"); client.connect(); client.send(new BinaryWebSocketFrame(Unpooled.wrappedBuffer(payload)), new FrameChecker(TextWebSocketFrame.class, "hello Stuart".getBytes(), latch)); latch.get(); @@ -344,7 +360,7 @@ public void testEncodingWithGenericSuperclass() throws Exception { final byte[] payload = "hello".getBytes(); final CompletableFuture latch = new CompletableFuture(); - WebSocketTestClient client = new WebSocketTestClient(new URI("ws://" + DefaultServer.getHostAddress("default") + ":" + DefaultServer.getHostPort("default") + "/ws/encodingGenerics/Stuart")); + WebSocketTestClient client = createTestClient("/ws/encodingGenerics/Stuart"); client.connect(); client.send(new TextWebSocketFrame(Unpooled.wrappedBuffer(payload)), new FrameChecker(TextWebSocketFrame.class, "hello Stuart".getBytes(), latch)); latch.get(); @@ -356,7 +372,7 @@ public void testRequestUri() throws Exception { final byte[] payload = "hello".getBytes(); final CompletableFuture latch = new CompletableFuture(); - WebSocketTestClient client = new WebSocketTestClient(new URI("ws://" + DefaultServer.getHostAddress("default") + ":" + DefaultServer.getHostPort("default") + "/ws/request?a=b")); + WebSocketTestClient client = createTestClient("/ws/request?a=b"); client.connect(); client.send(new TextWebSocketFrame(Unpooled.wrappedBuffer(payload)), new FrameChecker(TextWebSocketFrame.class, "/ws/request?a=b".getBytes(), latch)); latch.get(); diff --git a/websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/UuidDecoder.java b/websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/UUIDDecoder.java similarity index 90% rename from websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/UuidDecoder.java rename to websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/UUIDDecoder.java index 9e89c0f04..57ca1dec1 100644 --- a/websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/UuidDecoder.java +++ b/websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/UUIDDecoder.java @@ -4,16 +4,14 @@ import javax.websocket.EndpointConfig; import java.util.UUID; -public class UuidDecoder implements Decoder.Text { +public class UUIDDecoder implements Decoder.Text { @Override public void init(EndpointConfig config) { - } @Override public void destroy() { - } @Override @@ -30,4 +28,4 @@ public boolean willDecode(String s) { return false; } } -} \ No newline at end of file +} diff --git a/websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/UuidEndpoint.java b/websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/UUIDEndpoint.java similarity index 93% rename from websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/UuidEndpoint.java rename to websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/UUIDEndpoint.java index 4a4f044d8..4f712b512 100644 --- a/websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/UuidEndpoint.java +++ b/websockets-jsr/src/test/java/io/undertow/websockets/jsr/test/annotated/UUIDEndpoint.java @@ -26,8 +26,8 @@ import javax.websocket.server.ServerEndpoint; import java.util.UUID; -@ServerEndpoint(value = "/uuid/{id}", decoders = UuidDecoder.class) -public class UuidEndpoint { +@ServerEndpoint(value = "/uuid/{id}", decoders = UUIDDecoder.class) +public class UUIDEndpoint { UUID id; From 13236a3b66effb79c1e3205c300161f46362714a Mon Sep 17 00:00:00 2001 From: Karel Vervaeke Date: Fri, 19 Mar 2021 17:03:10 +0100 Subject: [PATCH 6/7] Bring branch up to date with origin/main --- .../websockets/ServerWebSocketContainer.java | 89 +++++++++---------- .../ServletServerWebSocketContainer.java | 25 +++++- .../test/annotated/AnnotatedEndpointTest.java | 52 ++++++----- 3 files changed, 91 insertions(+), 75 deletions(-) diff --git a/websocket/core/src/main/java/io/undertow/websockets/ServerWebSocketContainer.java b/websocket/core/src/main/java/io/undertow/websockets/ServerWebSocketContainer.java index a752aeae6..fe046d265 100644 --- a/websocket/core/src/main/java/io/undertow/websockets/ServerWebSocketContainer.java +++ b/websocket/core/src/main/java/io/undertow/websockets/ServerWebSocketContainer.java @@ -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; @@ -74,6 +77,7 @@ import java.util.function.Supplier; import static java.lang.System.currentTimeMillis; +import static java.util.Collections.emptyMap; /** @@ -180,18 +184,6 @@ protected Supplier 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) { @@ -580,7 +572,8 @@ private synchronized void addEndpointInternal(final Class endpoint, boolean r Class 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); @@ -605,31 +598,13 @@ public ObjectHandle 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.emptyList()) - .configurator(configurator) - .build(); - - EncodingFactory encodingFactory = EncodingFactory.createFactory(classIntrospecter, serverEndpoint.decoders(), serverEndpoint.encoders()); - AnnotatedEndpointFactory annotatedEndpointFactory = AnnotatedEndpointFactory.create(endpoint, encodingFactory, template.getParameterNames(), config); - InstanceFactory instanceFactory = null; - try { - instanceFactory = classIntrospecter.createInstanceFactory(endpoint); - } catch (Exception e) { - //so it is possible that this is still valid if a custom configurator is in use - if (configuratorClass == ServerEndpointConfig.Configurator.class) { - throw JsrWebSocketMessages.MESSAGES.couldNotDeploy(e); - } else { - instanceFactory = new InstanceFactory() { - @Override - public InstanceHandle createInstance() throws InstantiationException { - throw JsrWebSocketMessages.MESSAGES.endpointDoesNotHaveAppropriateConstructor(endpoint); - } - }; - } - } + .decoders(Arrays.asList(serverEndpoint.decoders())) + .encoders(Arrays.asList(serverEndpoint.encoders())) + .subprotocols(Arrays.asList(serverEndpoint.subprotocols())) + .extensions(Collections.emptyList()) + .configurator(configurator) + .build(); + ConfiguredServerEndpoint confguredServerEndpoint = new ConfiguredServerEndpoint(config, ObjectFactory, template, encodingFactory, annotatedEndpointFactory, installedExtensions); configuredServerEndpoints.add(confguredServerEndpoint); @@ -657,17 +632,18 @@ public ObjectHandle createInstance() { } } + EndpointConfig endpointConfig = createEndpointConfig(clientEndpoint.encoders(), clientEndpoint.decoders()); + AnnotatedEndpointFactory factory = AnnotatedEndpointFactory.create(endpoint, encodingFactory, Collections.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(); - - AnnotatedEndpointFactory factory = AnnotatedEndpointFactory.create(endpoint, encodingFactory, Collections.emptySet(), config); + .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); @@ -676,6 +652,25 @@ public ObjectHandle createInstance() { } } + private EndpointConfig createEndpointConfig(Class[] encoders, Class[] decoders) { + return new EndpointConfig() { + @Override + public List> getEncoders() { + return Arrays.asList(encoders); + } + + @Override + public List> getDecoders() { + return Arrays.asList(decoders); + } + + @Override + public Map getUserProperties() { + return emptyMap(); + } + }; + } + protected void handleAddingFilterMapping() { } diff --git a/websocket/servlet/src/main/java/io/undertow/websockets/servlet/ServletServerWebSocketContainer.java b/websocket/servlet/src/main/java/io/undertow/websockets/servlet/ServletServerWebSocketContainer.java index cff2e90af..013034bf0 100644 --- a/websocket/servlet/src/main/java/io/undertow/websockets/servlet/ServletServerWebSocketContainer.java +++ b/websocket/servlet/src/main/java/io/undertow/websockets/servlet/ServletServerWebSocketContainer.java @@ -25,7 +25,10 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.websocket.Decoder; +import javax.websocket.Encoder; import javax.websocket.Endpoint; +import javax.websocket.EndpointConfig; import javax.websocket.Extension; import javax.websocket.server.ServerEndpointConfig; import java.io.IOException; @@ -101,7 +104,8 @@ public ObjectHandle createInstance() { AnnotatedEndpointFactory annotatedEndpointFactory = null; if (!Endpoint.class.isAssignableFrom(sec.getEndpointClass())) { - annotatedEndpointFactory = AnnotatedEndpointFactory.create(sec.getEndpointClass(), encodingFactory, pt.getParameterNames()); + annotatedEndpointFactory = AnnotatedEndpointFactory.create(sec.getEndpointClass(), encodingFactory, pt.getParameterNames(), + createEndpointConfigurationFromConfig(sec)); } @@ -148,6 +152,25 @@ public void accept(ChannelHandlerContext context) { } } + private EndpointConfig createEndpointConfigurationFromConfig(ServerEndpointConfig sec) { + return new EndpointConfig() { + @Override + public List> getEncoders() { + return sec.getEncoders(); + } + + @Override + public List> getDecoders() { + return sec.getDecoders(); + } + + @Override + public Map getUserProperties() { + return sec.getUserProperties(); + } + }; + } + protected void handleAddingFilterMapping() { if (contextToAddFilter != null) { diff --git a/websocket/servlet/src/test/java/io/undertow/websockets/jsr/test/annotated/AnnotatedEndpointTest.java b/websocket/servlet/src/test/java/io/undertow/websockets/jsr/test/annotated/AnnotatedEndpointTest.java index c49976ab2..23dbe438a 100644 --- a/websocket/servlet/src/test/java/io/undertow/websockets/jsr/test/annotated/AnnotatedEndpointTest.java +++ b/websocket/servlet/src/test/java/io/undertow/websockets/jsr/test/annotated/AnnotatedEndpointTest.java @@ -17,33 +17,6 @@ */ package io.undertow.websockets.jsr.test.annotated; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; -import java.util.Set; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.websocket.ClientEndpoint; -import javax.websocket.CloseReason; -import javax.websocket.OnClose; -import javax.websocket.Session; -import javax.websocket.server.ServerEndpointConfig; - -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; - import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; @@ -62,6 +35,31 @@ import io.undertow.websockets.WebSocketDeploymentInfo; import io.undertow.websockets.jsr.test.FrameChecker; import io.undertow.websockets.jsr.test.WebSocketTestClient; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.websocket.ClientEndpoint; +import javax.websocket.CloseReason; +import javax.websocket.OnClose; +import javax.websocket.Session; +import javax.websocket.server.ServerEndpointConfig; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; /** * @author Norman Maurer From bc26fac62d8b104d6207446ef8f31fa350909f37 Mon Sep 17 00:00:00 2001 From: Karel Vervaeke Date: Sat, 20 Mar 2021 09:39:28 +0100 Subject: [PATCH 7/7] Fixed the build --- .../test/streams/Http2InputStreamTestCase.java | 18 ------------------ .../vertx/VertxServerWebSocketContainer.java | 3 ++- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/servlet/src/test/java/io/undertow/servlet/test/streams/Http2InputStreamTestCase.java b/servlet/src/test/java/io/undertow/servlet/test/streams/Http2InputStreamTestCase.java index 68183eb7a..1667c3d4b 100644 --- a/servlet/src/test/java/io/undertow/servlet/test/streams/Http2InputStreamTestCase.java +++ b/servlet/src/test/java/io/undertow/servlet/test/streams/Http2InputStreamTestCase.java @@ -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; @@ -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; diff --git a/websocket/vertx/src/main/java/io/undertow/websockets/vertx/VertxServerWebSocketContainer.java b/websocket/vertx/src/main/java/io/undertow/websockets/vertx/VertxServerWebSocketContainer.java index 7dc28a4e8..4d0906bb6 100644 --- a/websocket/vertx/src/main/java/io/undertow/websockets/vertx/VertxServerWebSocketContainer.java +++ b/websocket/vertx/src/main/java/io/undertow/websockets/vertx/VertxServerWebSocketContainer.java @@ -21,6 +21,7 @@ import io.vertx.ext.web.RoutingContext; import javax.websocket.Endpoint; +import javax.websocket.EndpointConfig; import javax.websocket.Extension; import javax.websocket.server.ServerEndpointConfig; import java.net.InetSocketAddress; @@ -92,7 +93,7 @@ public ObjectHandle createInstance() { AnnotatedEndpointFactory annotatedEndpointFactory = null; if (!Endpoint.class.isAssignableFrom(sec.getEndpointClass())) { - annotatedEndpointFactory = AnnotatedEndpointFactory.create(sec.getEndpointClass(), encodingFactory, pt.getParameterNames()); + annotatedEndpointFactory = AnnotatedEndpointFactory.create(sec.getEndpointClass(), encodingFactory, pt.getParameterNames(), config); }