Uploaded image for project: 'Red Hat Fuse'
  1. Red Hat Fuse
  2. ENTESB-8908

fabric8-cdi ability to use @Protocol annotation on @Factory method arguments

XMLWordPrintable

    • User Experience
    • % %

      Even when using @Factory, one has to define the @Protocol annotation on the Injection point.

      e.g.

      @Factory
      @ServiceName
      public FooHttpClient create(@ServiceName String url) {
          return new FooHttpClient(url);
      }
      
      @Inject
      @Protocol("http")
      @ServiceName("foo-service")
      FooHttpClient fooClient;
      

      This doesn't make much sense, since the protocol information is usually tied to the factory and client implementation.

      It would be nicer to be able to do this instead:

      @Factory
      @ServiceName
      public FooHttpClient create(@Protocol("http") @ServiceName String url) {
          return new FooHttpClient(url);
      }
      
      @Inject
      @ServiceName("foo-service")
      FooHttpClient fooClient;
      

      The current workaround used in the fabric8-cdi tests is to use Configuration to configure the port and hack it like the following ugly example:

          @Factory
          @ServiceName
          public URL toUrl(@ServiceName String service, @Configuration ProtocolConfig  protocolConfig) throws MalformedURLException {
              String protocol = protocolConfig.getProtocol();
              return new URL(protocol+"://" + service.substring(service.lastIndexOf("/")));
          }
      

              Unassigned Unassigned
              maschmid@redhat.com Marek Schmidt
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: