glassfish
  1. glassfish
  2. GLASSFISH-18344

@OSGiService annotation causing OSGi fragments containing ResourceBundles to fail (works w/ ServiceTracker)

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: 3.1.2_b22
    • Fix Version/s: None
    • Component/s: cdi, classloader, OSGi, OSGi-JavaEE
    • Labels:
      None
    • Environment:

      Windows 7 x64
      java version "1.6.0_29"
      Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
      Oracle JRockit(R) (build R28.2.0-79-146777-1.6.0_29-20111005-1808-windows-x86_64, compiled mode)

      Description

      This applies to 3.1.2b21 but it's not an option above.

      I have a very simple Servlet contained in a WAB that consumes a simple OSGi service. In addition the WAB has 3 fragments associated with it that contain ResourceBundles for different languages.

      For some reason the ResourceBundle's fail to load if I use the @OSGiService annotation. It works fine if I use the ServiceTracker utility. The service itself loads either way but the ResourceBundles disappear from the classloader if I use the annotation.

      Doesn't work:

      //	@Inject 
      //	@OSGiService(dynamic = true) // Glassfish specific extension :(
      	private HelloService helloService;
      

      Works:

      	@Override
      	public void init() {
      		helloServiceLocator = new HelloServiceLocator(getBundleContext());
      		helloService = helloServiceLocator.getHelloService(0);
      	}
      	
      	@Override
      	public void destroy() {
      		if (helloServiceLocator != null) {
      			helloServiceLocator.close();
      		}
      	}	
      
      
      	@Override
      	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      		PrintWriter writer = response.getWriter();
      		Locale locale = request.getLocale();
      		System.out.println("request locale = " + locale);
      		String bundleName = "cpms.resources.i18n.messages";
      // fails to find when using annotation
      		ResourceBundle resources = ResourceBundle.getBundle(bundleName, locale);
      		String greeting = resources.getString("SayHello.hello");
      		writer.append(greeting);		
      		writer.append(helloService.sayHello());
      		writer.close();
      	}
      

      Results in:
      com.textura.cpms.web.servlet.SayHello]: PWC1406: Servlet.service() for servlet com.textura.cpms.web.servlet.SayHello threw exception
      java.util.MissingResourceException: Can't find bundle for base name cpms.resources.i18n.messages, locale en_US

      Here's the overall structure:

      299|Resolved | 1|CPMS English language resources (1.0.0)
      300|Resolved | 1|CPMS French language resources (1.0.0)
      301|Resolved | 1|CPMS Default language resources (1.0.0)
      302|Active | 1|CPMS Hello Web Application (1.0.0)
      305|Active | 1|CPMS Hello Service SPI (1.0.0)
      307|Active | 1|CPMS Hello Service Provider (1.0.0)

        Activity

        Hide
        Sivakumar Thyagarajan added a comment -

        Could you please share the bundles/artifacts as well? I am not able to build the gradle project. Thanks.

        Show
        Sivakumar Thyagarajan added a comment - Could you please share the bundles/artifacts as well? I am not able to build the gradle project. Thanks.
        Hide
        blackbeltdev added a comment -

        Will do. Sorry I missed this update

        Show
        blackbeltdev added a comment - Will do. Sorry I missed this update
        Hide
        Sanjeeb Sahoo added a comment -

        PFA a modified project that works. I have copies SayHello servlet to SayHello2 and this new servlet uses @Inject @OSGiService. It is mapped to servlet path 2, so invoke sayhello/2 to use it.

        I didn't try building graddle; just wrote a simple shell script (SayHello/build.sh) to build the artifacts. I hand coded the manifests and they are in respective project folders. Start glassfish, unzip this attachment and run
        SayHello/build.sh <path to glassgish/>

        Build it and see the generated manifest and compare with what you have got. May be you got something wrong in your manifest.

        Show
        Sanjeeb Sahoo added a comment - PFA a modified project that works. I have copies SayHello servlet to SayHello2 and this new servlet uses @Inject @OSGiService. It is mapped to servlet path 2, so invoke sayhello/2 to use it. I didn't try building graddle; just wrote a simple shell script (SayHello/build.sh) to build the artifacts. I hand coded the manifests and they are in respective project folders. Start glassfish, unzip this attachment and run SayHello/build.sh <path to glassgish/> Build it and see the generated manifest and compare with what you have got. May be you got something wrong in your manifest.
        Hide
        Sanjeeb Sahoo added a comment -

        See the new file attached. I could not reproduce.

        Show
        Sanjeeb Sahoo added a comment - See the new file attached. I could not reproduce.
        Hide
        blackbeltdev added a comment -

        Here are the pre-built bundles. To recreate (I just retried on 3.1.2-b23):

        1) deploy the bundles in 'works' folder to Glassfish autodeploy folder.

        This is the version that uses the ServiceTracker API

        2) Visit http://localhost:8080/sayhello/. It works!

        3) Replace the cpms.web.hello-1.0.0.war bundle from 'fails' folder that uses the CDI inject method

        4) Reload page in browser results in 500 Error. The server logs contain:

        [#|2012-02-20T11:47:17.074-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=23;_ThreadName=Thread-4;|request locale = en_US|#]

        [#|2012-02-20T11:47:17.079-0600|WARNING|glassfish3.1.2|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=23;_ThreadName=Thread-4;|StandardWrapperValve[com.textura.cpms.web.servlet.SayHello]: PWC1406: Servlet.service() for servlet com.textura.cpms.web.servlet.SayHello threw exception
        java.lang.NullPointerException
        at com.textura.cpms.web.servlet.SayHello.doGet(SayHello.java:77)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
        at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
        at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
        at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
        at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
        at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
        at java.lang.Thread.run(Thread.java:662)

        #]
        Show
        blackbeltdev added a comment - Here are the pre-built bundles. To recreate (I just retried on 3.1.2-b23): 1) deploy the bundles in 'works' folder to Glassfish autodeploy folder. This is the version that uses the ServiceTracker API 2) Visit http://localhost:8080/sayhello/ . It works! 3) Replace the cpms.web.hello-1.0.0.war bundle from 'fails' folder that uses the CDI inject method 4) Reload page in browser results in 500 Error. The server logs contain: [#|2012-02-20T11:47:17.074-0600|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=23;_ThreadName=Thread-4;|request locale = en_US|#] [#|2012-02-20T11:47:17.079-0600|WARNING|glassfish3.1.2|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=23;_ThreadName=Thread-4;|StandardWrapperValve [com.textura.cpms.web.servlet.SayHello] : PWC1406: Servlet.service() for servlet com.textura.cpms.web.servlet.SayHello threw exception java.lang.NullPointerException at com.textura.cpms.web.servlet.SayHello.doGet(SayHello.java:77) at javax.servlet.http.HttpServlet.service(HttpServlet.java:668) at javax.servlet.http.HttpServlet.service(HttpServlet.java:770) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231) at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849) at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045) at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) at com.sun.grizzly.ContextTask.run(ContextTask.java:71) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) at java.lang.Thread.run(Thread.java:662) #]
        Hide
        blackbeltdev added a comment -

        Thanks Sahoo. I posted my bundles before I saw your response. I'll try and look for differences.

        Show
        blackbeltdev added a comment - Thanks Sahoo. I posted my bundles before I saw your response. I'll try and look for differences.
        Hide
        blackbeltdev added a comment -

        I haven't tracked down which one was bad but it was definitely one of the manifest entries causing it to fail. It's still weird that ServiceTracker worked but CDI failed. I have them now both working.

        I'll see if I can find out which one was bad.

        Show
        blackbeltdev added a comment - I haven't tracked down which one was bad but it was definitely one of the manifest entries causing it to fail. It's still weird that ServiceTracker worked but CDI failed. I have them now both working. I'll see if I can find out which one was bad.
        Hide
        blackbeltdev added a comment - - edited

        Argh this is embarrassing to admit but underscores some of the challenges of using OSGi since two other OSGi developers didn't catch it either

        I had forgotten to include both
        'org.glassfish.osgicdi' and 'javax.inject' in my Import-Package statement for the WAB.

        It was:

        'Import-Package': 'com.textura.cpms.service.hello,org.osgi.framework,org.osgi.util.tracker,javax.servlet,javax.servlet.annotation,javax.servlet.http',
        

        Fixed:

        'Import-Package': 'com.textura.cpms.service.hello,org.osgi.framework,org.osgi.util.tracker,javax.servlet,javax.servlet.annotation,javax.servlet.http,org.glassfish.osgicdi, javax.inject',
        

        Simply as that.

        I wonder if you could enhance logging so that if unknown annotations are found in the class that Glassflish could maybe log a warning or something along those lines?

        Show
        blackbeltdev added a comment - - edited Argh this is embarrassing to admit but underscores some of the challenges of using OSGi since two other OSGi developers didn't catch it either I had forgotten to include both 'org.glassfish.osgicdi' and 'javax.inject' in my Import-Package statement for the WAB. It was: 'Import-Package': 'com.textura.cpms.service.hello,org.osgi.framework,org.osgi.util.tracker,javax.servlet,javax.servlet.annotation,javax.servlet.http', Fixed: 'Import-Package': 'com.textura.cpms.service.hello,org.osgi.framework,org.osgi.util.tracker,javax.servlet,javax.servlet.annotation,javax.servlet.http,org.glassfish.osgicdi, javax.inject', Simply as that. I wonder if you could enhance logging so that if unknown annotations are found in the class that Glassflish could maybe log a warning or something along those lines?

          People

          • Assignee:
            Sivakumar Thyagarajan
            Reporter:
            blackbeltdev
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: