tyrus
  1. tyrus
  2. TYRUS-166

@ClientEndpoint(configurator) is not honored

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0-rc3
    • Component/s: None
    • Labels:
      None

      Description

      if a ClientEndpointConfigurator is specified using @ClientEndpoint(configurator) attribute then it is not invoked. Specifying in an interface-based client endpoint works.

        Activity

        Hide
        jitu added a comment -

        Yes. AnnotatedEndpoint is not looking at
        ClientEndpointConfig.Configurator attribute in the annotation.
        However, on the server side ServerEndpointConfig.Configurator is taken into account while building the ServerEndpointConfig.

        Show
        jitu added a comment - Yes. AnnotatedEndpoint is not looking at ClientEndpointConfig.Configurator attribute in the annotation. However, on the server side ServerEndpointConfig.Configurator is taken into account while building the ServerEndpointConfig.
        Hide
        Pavel Bucek added a comment -
        Index: tests/e2e/src/test/java/org/glassfish/tyrus/test/e2e/ModifyRequestResponseHeadersTest.java
        ===================================================================
        --- tests/e2e/src/test/java/org/glassfish/tyrus/test/e2e/ModifyRequestResponseHeadersTest.java	(revision 585)
        +++ tests/e2e/src/test/java/org/glassfish/tyrus/test/e2e/ModifyRequestResponseHeadersTest.java	(working copy)
        @@ -47,12 +47,14 @@
         import java.util.concurrent.CountDownLatch;
         import java.util.concurrent.TimeUnit;
         
        +import javax.websocket.ClientEndpoint;
         import javax.websocket.ClientEndpointConfig;
         import javax.websocket.Endpoint;
         import javax.websocket.EndpointConfig;
         import javax.websocket.HandshakeResponse;
         import javax.websocket.MessageHandler;
         import javax.websocket.OnMessage;
        +import javax.websocket.OnOpen;
         import javax.websocket.Session;
         import javax.websocket.server.HandshakeRequest;
         import javax.websocket.server.ServerEndpoint;
        @@ -63,6 +65,7 @@
         
         import org.junit.Test;
         import static org.junit.Assert.assertEquals;
        +import static org.junit.Assert.assertTrue;
         
         /**
          * @author Pavel Bucek (pavel.bucek at oracle.com)
        @@ -94,8 +97,11 @@
             }
         
             public static class MyClientConfigurator extends ClientEndpointConfig.Configurator {
        +        static volatile boolean called = false;
        +
                 @Override
                 public void beforeRequest(Map<String, List<String>> headers) {
        +            called = true;
                     headers.put(HEADER_NAME, Arrays.asList(HEADER_VALUE));
                 }
         
        @@ -108,8 +114,9 @@
             }
         
             @Test
        -    public void testHeaders() {
        +    public void testHeadersProgrammatic() {
                 Server server = new Server(TestEndpoint.class);
        +        MyClientConfigurator.called = false;
         
                 final CountDownLatch messageLatch = new CountDownLatch(1);
         
        @@ -142,6 +149,7 @@
         
                     messageLatch.await(5, TimeUnit.SECONDS);
                     assertEquals(0, messageLatch.getCount());
        +            assertTrue(MyClientConfigurator.called);
                     assertEquals(SENT_MESSAGE, receivedMessage);
                 } catch (Exception e) {
                     e.printStackTrace();
        @@ -150,4 +158,44 @@
                     server.stop();
                 }
             }
        +
        +    @ClientEndpoint(configurator = MyClientConfigurator.class)
        +    public static class MyClientEndpoint {
        +        public static final CountDownLatch messageLatch = new CountDownLatch(1);
        +        public static volatile String receivedMessage;
        +
        +        @OnOpen
        +        public void onOpen(Session session) throws IOException {
        +            session.getBasicRemote().sendText(SENT_MESSAGE);
        +        }
        +
        +        @OnMessage
        +        public void onMessage(String message) {
        +            receivedMessage = message;
        +            messageLatch.countDown();
        +        }
        +    }
        +
        +    @Test
        +    public void testHeadersAnnotated() {
        +        Server server = new Server(TestEndpoint.class);
        +        MyClientConfigurator.called = false;
        +
        +        try {
        +            server.start();
        +
        +            ClientManager client = ClientManager.createClient();
        +            client.connectToServer(MyClientEndpoint.class, new URI("ws://localhost:8025/websockets/tests/echo"));
        +
        +            MyClientEndpoint.messageLatch.await(5, TimeUnit.SECONDS);
        +            assertTrue(MyClientConfigurator.called);
        +            assertEquals(0, MyClientEndpoint.messageLatch.getCount());
        +            assertEquals(SENT_MESSAGE, MyClientEndpoint.receivedMessage);
        +        } catch (Exception e) {
        +            e.printStackTrace();
        +            throw new RuntimeException(e.getMessage(), e);
        +        } finally {
        +            server.stop();
        +        }
        +    }
         }
        Index: core/src/main/java/org/glassfish/tyrus/core/AnnotatedEndpoint.java
        ===================================================================
        --- core/src/main/java/org/glassfish/tyrus/core/AnnotatedEndpoint.java	(revision 585)
        +++ core/src/main/java/org/glassfish/tyrus/core/AnnotatedEndpoint.java	(working copy)
        @@ -276,8 +276,6 @@
                         return null;
                     }
         
        -            // TODO - wscAnnotation.configuration()?
        -
                     List<Class<? extends Encoder>> encoderClasses = new ArrayList<Class<? extends Encoder>>();
                     List<Class<? extends Decoder>> decoderClasses = new ArrayList<Class<? extends Decoder>>();
                     String[] subProtocols;
        @@ -288,8 +286,10 @@
         
                     decoderClasses.addAll(EndpointWrapper.getDefaultDecoders());
         
        +            ClientEndpointConfig.Configurator configurator = ReflectionHelper.getInstance(wscAnnotation.configurator(), collector);
        +
                     return ClientEndpointConfig.Builder.create().encoders(encoderClasses).decoders(decoderClasses).
        -                    preferredSubprotocols(Arrays.asList(subProtocols)).build();
        +                    preferredSubprotocols(Arrays.asList(subProtocols)).configurator(configurator).build();
                 }
             }
        Show
        Pavel Bucek added a comment - Index: tests/e2e/src/test/java/org/glassfish/tyrus/test/e2e/ModifyRequestResponseHeadersTest.java =================================================================== --- tests/e2e/src/test/java/org/glassfish/tyrus/test/e2e/ModifyRequestResponseHeadersTest.java (revision 585) +++ tests/e2e/src/test/java/org/glassfish/tyrus/test/e2e/ModifyRequestResponseHeadersTest.java (working copy) @@ -47,12 +47,14 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; + import javax.websocket.ClientEndpoint; import javax.websocket.ClientEndpointConfig; import javax.websocket.Endpoint; import javax.websocket.EndpointConfig; import javax.websocket.HandshakeResponse; import javax.websocket.MessageHandler; import javax.websocket.OnMessage; + import javax.websocket.OnOpen; import javax.websocket.Session; import javax.websocket.server.HandshakeRequest; import javax.websocket.server.ServerEndpoint; @@ -63,6 +65,7 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; + import static org.junit.Assert.assertTrue; /** * @author Pavel Bucek (pavel.bucek at oracle.com) @@ -94,8 +97,11 @@ } public static class MyClientConfigurator extends ClientEndpointConfig.Configurator { + static volatile boolean called = false ; + @Override public void beforeRequest(Map< String , List< String >> headers) { + called = true ; headers.put(HEADER_NAME, Arrays.asList(HEADER_VALUE)); } @@ -108,8 +114,9 @@ } @Test - public void testHeaders() { + public void testHeadersProgrammatic() { Server server = new Server(TestEndpoint.class); + MyClientConfigurator.called = false ; final CountDownLatch messageLatch = new CountDownLatch(1); @@ -142,6 +149,7 @@ messageLatch.await(5, TimeUnit.SECONDS); assertEquals(0, messageLatch.getCount()); + assertTrue(MyClientConfigurator.called); assertEquals(SENT_MESSAGE, receivedMessage); } catch (Exception e) { e.printStackTrace(); @@ -150,4 +158,44 @@ server.stop(); } } + + @ClientEndpoint(configurator = MyClientConfigurator.class) + public static class MyClientEndpoint { + public static final CountDownLatch messageLatch = new CountDownLatch(1); + public static volatile String receivedMessage; + + @OnOpen + public void onOpen(Session session) throws IOException { + session.getBasicRemote().sendText(SENT_MESSAGE); + } + + @OnMessage + public void onMessage( String message) { + receivedMessage = message; + messageLatch.countDown(); + } + } + + @Test + public void testHeadersAnnotated() { + Server server = new Server(TestEndpoint.class); + MyClientConfigurator.called = false ; + + try { + server.start(); + + ClientManager client = ClientManager.createClient(); + client.connectToServer(MyClientEndpoint.class, new URI( "ws: //localhost:8025/websockets/tests/echo" )); + + MyClientEndpoint.messageLatch.await(5, TimeUnit.SECONDS); + assertTrue(MyClientConfigurator.called); + assertEquals(0, MyClientEndpoint.messageLatch.getCount()); + assertEquals(SENT_MESSAGE, MyClientEndpoint.receivedMessage); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException(e.getMessage(), e); + } finally { + server.stop(); + } + } } Index: core/src/main/java/org/glassfish/tyrus/core/AnnotatedEndpoint.java =================================================================== --- core/src/main/java/org/glassfish/tyrus/core/AnnotatedEndpoint.java (revision 585) +++ core/src/main/java/org/glassfish/tyrus/core/AnnotatedEndpoint.java (working copy) @@ -276,8 +276,6 @@ return null ; } - // TODO - wscAnnotation.configuration()? - List< Class <? extends Encoder>> encoderClasses = new ArrayList< Class <? extends Encoder>>(); List< Class <? extends Decoder>> decoderClasses = new ArrayList< Class <? extends Decoder>>(); String [] subProtocols; @@ -288,8 +286,10 @@ decoderClasses.addAll(EndpointWrapper.getDefaultDecoders()); + ClientEndpointConfig.Configurator configurator = ReflectionHelper.getInstance(wscAnnotation.configurator(), collector); + return ClientEndpointConfig.Builder.create().encoders(encoderClasses).decoders(decoderClasses). - preferredSubprotocols(Arrays.asList(subProtocols)).build(); + preferredSubprotocols(Arrays.asList(subProtocols)).configurator(configurator).build(); } }

          People

          • Assignee:
            Pavel Bucek
            Reporter:
            arungupta
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: