Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-526

Custom configurator that creates endpoints is not supported

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 1.3.0.Beta11
    • 1.3.0.Beta10
    • Core
    • None

      I am trying to create a JSR websocket handler.

      @ServerEndpoint(
              value = Constants.JSON_ENDPOINT_PATH,
              configurator = GuiceServerEndpointConfigurator.class
      )
      public class JSONServerEndpoint {
         public JSONServerEndpoint(SomeDependency dep){...}
         ...
      }
      
      public class GuiceServerEndpointConfigurator extends ServerEndpointConfig.Configurator {
          @Override
          public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException {
              if(JSONServerEndpoint.class.equals(endpointClass){
                  return new JSONServerEndpoint(new SomeDependency());
              }
              // PROD use case: instantiate the given class with Guice, so that stuff is injected!
              // return ServerBootstrap.injector().getInstance(endpointClass);
          }
      }
      

      I would like to plug my own configurator to create the endpoint instance that is within my injector's lifecycle.

      With this code, I receive Caused by: java.lang.NoSuchMethodException: com.example.JSONServerEndpoint.<init>() because Undertow is trying to instantiate the endpoint itself with DefaultClassIntrospector#createInstanceFactory() and using that factory.

      However, it should ask the given configurator to instantiate an instance of the endpoint.

      Actually it happens before even configurator is read etc.

      Anyway, ServerEndpointConfig.Configurator#getEndpointInstance(...) is not called anywhere in Undertow.

              sdouglas1@redhat.com Stuart Douglas (Inactive)
              aliok_jira Ali Ok (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: