glassfish
  1. glassfish
  2. GLASSFISH-19423

Using custom Qualifier on a @Publish class failed

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Critical Critical
    • Resolution: Unresolved
    • Affects Version/s: future release
    • Fix Version/s: None
    • Component/s: OSGi-JavaEE
    • Labels:
      None

      Description

      [Problem Description]
      While using the following custom Qualifier(@Blue) on a @Publish class to register OSGi service,

      @Publish(contracts =

      {MyServiceInf.class}

      )
      @Blue
      public class MyService implements MyServiceInf{
      ...
      }

      The following exception will happen,

      [#|2012-12-10T19:32:50.421+0900|SEVERE|44.0|javax.enterprise.logging.stderr|_ThreadID=12;_ThreadName=admin-listener(1);_TimeMillis=1355135570421;_LevelValue=1000;|org.jboss.weld.exceptions.UnsatisfiedResolutionException: WELD-001308 Unable to resolve any beans for Types: [class org.acme.myservice.MyService]; Bindings: [QualifierInstance{annotationClass=interface javax.enterprise.inject.Default, values={}, hashCode=477945538}, QualifierInstance{annotationClass=interface javax.enterprise.inject.Any, values={}, hashCode=249261545}, QualifierInstance{annotationClass=interface org.acme.myservice.api.Blue, values={}, hashCode=668150471}]
      at org.jboss.weld.manager.BeanManagerImpl.getBean(BeanManagerImpl.java:699)
      at org.jboss.weld.bean.builtin.InstanceImpl.get(InstanceImpl.java:102)
      at org.glassfish.osgicdi.impl.OSGiServicePublisher.registerOSGiService(OSGiServicePublisher.java:86)
      at org.glassfish.osgicdi.impl.OSGiServiceExtension.publishOSGiService(OSGiServiceExtension.java:332)
      at org.glassfish.osgicdi.impl.OSGiServiceExtension.afterDeploymentValidation(OSGiServiceExtension.java:264)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:267)
      at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52)
      at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:137)
      at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:263)
      at org.jboss.weld.introspector.jlr.WeldMethodImpl.invokeOnInstance(WeldMethodImpl.java:170)
      at org.jboss.weld.introspector.ForwardingWeldMethod.invokeOnInstance(ForwardingWeldMethod.java:51)
      at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:154)
      at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:245)
      at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:233)
      at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:213)
      at org.jboss.weld.bootstrap.events.AbstractContainerEvent.fire(AbstractContainerEvent.java:75)
      at org.jboss.weld.bootstrap.events.AbstractDeploymentContainerEvent.fire(AbstractDeploymentContainerEvent.java:46)
      at org.jboss.weld.bootstrap.events.AfterDeploymentValidationImpl.fire(AfterDeploymentValidationImpl.java:31)
      at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:382)
      at org.glassfish.osgicdi.impl.OSGiCDIExtender$BeanBundleTrackerCustomizer.addingBundle(OSGiCDIExtender.java:235)
      at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:482)
      at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:424)
      at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:262)
      at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:234)
      at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:457)
      at org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:868)
      at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:789)
      at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:514)
      at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4244)
      at org.apache.felix.framework.Felix.startBundle(Felix.java:1923)
      at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:944)
      at org.glassfish.extras.osgicontainer.OSGiDeployedBundle.startBundle(OSGiDeployedBundle.java:107)
      at org.glassfish.extras.osgicontainer.OSGiDeployedBundle.resume(OSGiDeployedBundle.java:83)
      at org.glassfish.extras.osgicontainer.OSGiDeployedBundle.start(OSGiDeployedBundle.java:67)
      at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122)
      at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:278)
      at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:299)
      at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:507)
      at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:229)
      at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:489)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:539)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:535)
      at java.security.AccessController.doPrivileged(Native Method)
      at javax.security.auth.Subject.doAs(Subject.java:337)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:534)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:565)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1449)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1500(CommandRunnerImpl.java:119)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1759)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1709)
      at org.glassfish.admin.rest.resources.admin.CommandResource.executeCommand(CommandResource.java:487)
      at org.glassfish.admin.rest.resources.admin.CommandResource.execCommandSimpInMultOut(CommandResource.java:255)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.glassfish.jersey.server.model.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:80)
      at org.glassfish.jersey.server.model.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:107)
      at org.glassfish.jersey.server.model.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:146)
      at org.glassfish.jersey.server.model.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:80)
      at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:354)
      at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:349)
      at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:97)
      at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:204)
      at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:316)
      at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:180)
      at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:796)
      at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.service(GrizzlyHttpContainer.java:306)
      at org.glassfish.admin.rest.adapter.RestAdapter$1.service(RestAdapter.java:327)
      at org.glassfish.admin.rest.adapter.RestAdapter.service(RestAdapter.java:189)
      at com.sun.enterprise.v3.server.HK2Dispatcher.dispatch(HK2Dispatcher.java:113)
      at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:236)
      at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:164)
      at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:175)
      at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:265)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:134)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
      at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
      at org.glassfish.grizzly.nio.transport.TCPNI|#]

        Activity

        Hide
        TangYong added a comment -

        This problem has been fixed and fixing way is to use the following way to resolve bean and get bean instance object,

        private <T> T getContextualInstance(BeanManager manager, Class<T> type, Annotation... qualifiers) {
        T result = null;
        Bean<T> bean = null;
        if (qualifiers.length == 0)

        { bean = (Bean<T>) manager.resolve(manager.getBeans(type)); }

        else

        { bean = (Bean<T>) manager.resolve(manager.getBeans(type, qualifiers)); }

        if (bean != null) {
        CreationalContext<T> context = manager.createCreationalContext(bean);
        if (context != null)

        { result = (T) manager.getReference(bean, type, context); }

        }
        return result;
        }

        1 the above method applies in OSGiServicePublisher class
        2 in order to use the above method, needing to use Bean Manager rather than Instance<Object>, So,current patch needing to be modified. Fixed patch will be placed in Glassfish-19215.
        3 using the above way rather than Instance<Object> will bring a big advantage for patch: not using Weld Implementation related features, and only using CDI SPI Spec.

        Show
        TangYong added a comment - This problem has been fixed and fixing way is to use the following way to resolve bean and get bean instance object, private <T> T getContextualInstance(BeanManager manager, Class<T> type, Annotation... qualifiers) { T result = null; Bean<T> bean = null; if (qualifiers.length == 0) { bean = (Bean<T>) manager.resolve(manager.getBeans(type)); } else { bean = (Bean<T>) manager.resolve(manager.getBeans(type, qualifiers)); } if (bean != null) { CreationalContext<T> context = manager.createCreationalContext(bean); if (context != null) { result = (T) manager.getReference(bean, type, context); } } return result; } 1 the above method applies in OSGiServicePublisher class 2 in order to use the above method, needing to use Bean Manager rather than Instance<Object>, So,current patch needing to be modified. Fixed patch will be placed in Glassfish-19215. 3 using the above way rather than Instance<Object> will bring a big advantage for patch: not using Weld Implementation related features, and only using CDI SPI Spec.
        Hide
        TangYong added a comment -

        While testing in hybrid javaee bundle scene, the same problem happened.

        [Direct Reason]
        TypeSafeBeanResolver's resolved field is empty and this caused that while calling "resolve(R resolvable, boolean cache)" method, "resolved.get(wrappedResolvable)" returned null.

        [Initial Analyze]
        While registering a @Publish class, I used Instance<Object> to select bean instance with qualify and try to get the object. However, The WeldContainer.instance() method returns an instance with the @Default and @Any qualifiers[1], and maybe can not get @Blue bean instance.

        So, according to [2], I need to confirm the point.
        [1]:https://community.jboss.org/thread/179988
        [2]:https://github.com/seam/persistence/blob/master/impl/src/main/java/org/jboss/seam/persistence/util/InstanceResolver.java

        Show
        TangYong added a comment - While testing in hybrid javaee bundle scene, the same problem happened. [Direct Reason] TypeSafeBeanResolver's resolved field is empty and this caused that while calling "resolve(R resolvable, boolean cache)" method, "resolved.get(wrappedResolvable)" returned null. [Initial Analyze] While registering a @Publish class, I used Instance<Object> to select bean instance with qualify and try to get the object. However, The WeldContainer.instance() method returns an instance with the @Default and @Any qualifiers [1] , and maybe can not get @Blue bean instance. So, according to [2] , I need to confirm the point. [1] : https://community.jboss.org/thread/179988 [2] : https://github.com/seam/persistence/blob/master/impl/src/main/java/org/jboss/seam/persistence/util/InstanceResolver.java
        Hide
        TangYong added a comment -

        The feature is very important and once implementing the feature, an user can use custom qualifier to register a OSGi Service, and the qualifier plays a role of Service Property.

        Currently, because of some problem, the custom qualifier can not be resolved by cdi container.

        Needing to investigate the reason in depth.

        In addition, the feature is related to OSGiServicePublisher.getServiceProperties().

        Show
        TangYong added a comment - The feature is very important and once implementing the feature, an user can use custom qualifier to register a OSGi Service, and the qualifier plays a role of Service Property. Currently, because of some problem, the custom qualifier can not be resolved by cdi container. Needing to investigate the reason in depth. In addition, the feature is related to OSGiServicePublisher.getServiceProperties().

          People

          • Assignee:
            Sanjeeb Sahoo
            Reporter:
            TangYong
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: