@Override
  public void register(Class<?> endpointClass, String contextPath) throws DeploymentException {

    final ErrorCollector collector = new ErrorCollector();

    AnnotatedEndpoint endpoint =
        AnnotatedEndpoint.fromClass(endpointClass, componentProviderService, true, collector);
    EndpointConfig config = endpoint.getEndpointConfig();

    TyrusEndpointWrapper ew =
        new TyrusEndpointWrapper(
            endpoint,
            config,
            componentProviderService,
            webSocketContainer,
            contextPath,
            config instanceof ServerEndpointConfig
                ? ((ServerEndpointConfig) config).getConfigurator()
                : null);

    if (collector.isEmpty()) {
      register(new TyrusEndpoint(ew));
    } else {
      throw collector.composeComprehensiveException();
    }
  }
  @Override
  public void register(ServerEndpointConfig serverConfig, String contextPath)
      throws DeploymentException {

    TyrusEndpointWrapper ew;

    Class<?> endpointClass = serverConfig.getEndpointClass();
    boolean isEndpointClass = false;

    do {
      endpointClass = endpointClass.getSuperclass();
      if (endpointClass.equals(Endpoint.class)) {
        isEndpointClass = true;
      }
    } while (!endpointClass.equals(Object.class));

    if (isEndpointClass) {
      // we are pretty sure that endpoint class is javax.websocket.Endpoint descendant.
      //noinspection unchecked
      ew =
          new TyrusEndpointWrapper(
              (Class<? extends Endpoint>) serverConfig.getEndpointClass(),
              serverConfig,
              componentProviderService,
              webSocketContainer,
              contextPath,
              serverConfig.getConfigurator());
    } else {
      final ErrorCollector collector = new ErrorCollector();

      final AnnotatedEndpoint endpoint =
          AnnotatedEndpoint.fromClass(
              serverConfig.getEndpointClass(), componentProviderService, true, collector);
      final EndpointConfig config = endpoint.getEndpointConfig();

      ew =
          new TyrusEndpointWrapper(
              endpoint,
              config,
              componentProviderService,
              webSocketContainer,
              contextPath,
              config instanceof ServerEndpointConfig
                  ? ((ServerEndpointConfig) config).getConfigurator()
                  : null);

      if (!collector.isEmpty()) {
        throw collector.composeComprehensiveException();
      }
    }

    register(new TyrusEndpoint(ew));
  }
  @Test
  public void testWebSocketInjectionAndInterception() throws Exception {
    AnnotatedClient.reset();
    AnnotatedEndpoint.reset();
    ComponentInterceptor.resetInterceptions();

    final ServerContainer serverContainer =
        (ServerContainer) new InitialContext().lookup(SERVER_CONTAINER_JNDI_NAME);
    serverContainer.connectToServer(
        AnnotatedClient.class,
        new URI(
            "ws",
            "",
            TestSuiteEnvironment.getServerAddress(),
            8080,
            "/websocket/websocket/cruel",
            "",
            ""));

    Assert.assertEquals("Hello cruel World", AnnotatedClient.getMessage());

    Assert.assertTrue("Client endpoint's injection not correct.", AnnotatedClient.injectionOK);
    Assert.assertTrue("Server endpoint's injection not correct.", AnnotatedEndpoint.injectionOK);

    Assert.assertTrue(
        "PostConstruct method on client endpoint instance not called.",
        AnnotatedClient.postConstructCalled);
    Assert.assertTrue(
        "PostConstruct method on server endpoint instance not called.",
        AnnotatedEndpoint.postConstructCalled);

    Assert.assertEquals(
        "AroundConstruct interceptor method not invoked for client endpoint.",
        "AroundConstructInterceptor#Joe#AnnotatedClient",
        AnnotatedClient.getName());
    Assert.assertEquals(
        "AroundConstruct interceptor method not invoked for server endpoint.",
        "AroundConstructInterceptor#Joe#AnnotatedEndpoint",
        AnnotatedEndpoint.getName());

    Assert.assertEquals(2, ComponentInterceptor.getInterceptions().size());
    Assert.assertEquals("open", ComponentInterceptor.getInterceptions().get(0).getMethodName());
    Assert.assertEquals("message", ComponentInterceptor.getInterceptions().get(1).getMethodName());
  }