1 2 3 Previous Next 35 Replies Latest reply: Apr 17, 2013 11:02 AM by joshna_r RSS

How to make dependency on osgi bundle from war file

Adomas Greicius Newbie

There is little documentation on osgi integration with servlets. I have not found any working example. Can you help me.

How to make dependency on osgi bundle from war file. I need to use classes that are in osgi bundle but I do not want to add extra jar file in war.

I have founded that dependency tag in manifest,  should make class loading OK.

Dependencies:jbosgi.aaa:1.0.0.201201101753

Class (that is in bundle) is not loaded in servlet, even my war has manifest with dependencies tag.

What am I doing wrong?

Is there any other way to do this?

  • 1. Re: How to make dependency on osgi bundle from war file
    Adomas Greicius Newbie

    Can any one suggest where to search answer? 

  • 2. Re: How to make dependency on osgi bundle from war file
    Maciej Swiderski Master

    I think it should be something like this:

     

    Dependencies: deployment.{name-of-the-bundle}:{version}

     

    Considering that your bundle was deployed by dropping it into deployments folder.

     

    HTH

  • 3. Re: How to make dependency on osgi bundle from war file
    Adomas Greicius Newbie

    Thank you for your answer.

     

    How bundle name depends on deployment way?

    If you deploy with web console or copy into  the directory or deploy with the osgi console name of budle will be different?

  • 4. Re: How to make dependency on osgi bundle from war file
    Maciej Swiderski Master

    Once you mentioned the web console (admin console) I started to ask myself the same question - why it differs? I used dropping bundle into directory and osgi console. During my tests it looked that bundle deployed via osgi console was not available to the web application so that was the conclusion - as it turned out to quick one. After double check I noticed that Bundle Name in manifest was corrupted and that was the reason why it did not worked.

     

    So I tried out several possibilities (deployments directory, admin console and osgi console) and with proper manifest all of them were accessible from war. Apologies for confusion.

     

    Cheers

  • 5. Re: How to make dependency on osgi bundle from war file
    Adomas Greicius Newbie

    Does this work for you?

    I can not understand why manifest dependency management do not work for me.

    I have created bundle with manifest

     

    Manifest-Version: 1.0

    Bundle-ManifestVersion: 2

    Bundle-Name: aaa

    Bundle-SymbolicName: aaa

    Bundle-Version: 1.0.0

    Bundle-Activator: aaa.Activator

    Bundle-ActivationPolicy: lazy

    Bundle-RequiredExecutionEnvironment: JavaSE-1.6

    Import-Package: org.osgi.framework;version="1.3.0"

    Export-Package: aaa

     

    And servlet

     

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    PrintWriter writer = response.getWriter();

    writer.println("Hello world");

    writer.println(Activator.class.getName());

    writer.close();

    }

     

    with manifest:

     

    Manifest-Version: 1.0

    Dependencies:deployment.aaa:1.0.0

     

     

     

    Copied all into  dir jboss-as-7.0.2.Final\standalone\deployments

    Console shows that bundles and servlet is deployed and active.

     

    When I call servlet, I get exception.

     

    19:00:26,318 INFO  [org.jboss.as.server.controller] (HttpManagementService-threads - 11) Deployed "tempWeb7.war"

    19:00:31,423 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/tempWeb7].[lt.nomagic.servlet.firstServlet]] (http--127.0.0.1-8080-4) Servlet.service() for servlet lt.nomagic.servlet.firstServlet threw exception: java.lang.ClassNotFoundException: aaa.Activator from [Module "deployment.tempWeb7.war:main" from Service Module Loader]

              at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:191)

              at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:361)

              at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:333)

              at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:310)

              at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:103)

              at lt.nomagic.servlet.firstServlet.doGet(firstServlet.java:35) [classes:]

              at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]

              at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]

              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

              at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:139) [jboss-as-web-7.0.2.Final.jar:7.0.2.Final]

              at org.jboss.as.web.NamingValve.invoke(NamingValve.java:57) [jboss-as-web-7.0.2.Final.jar:7.0.2.Final]

              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:154) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

              at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:667) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:952) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

              at java.lang.Thread.run(Thread.java:662) [:1.6.0_29]

  • 6. Re: How to make dependency on osgi bundle from war file
    Adomas Greicius Newbie

    can you send me your working sample? adamsus [eta]  gmail.com

  • 7. Re: How to make dependency on osgi bundle from war file
    Maciej Swiderski Master

    Yes, it does work for me. Here are dependencies defined in manifest file of war:

    Dependencies: org.osgi.core,org.jboss.osgi.framework,deployment.test-osgi-bundle:0.0.1

     

    where the last part is the osgi bundle I use to test it. Please give it a try and let me know if that makes any difference. If not tomorrow will try to assemble an sample for you.

     

    HTH

  • 8. Re: How to make dependency on osgi bundle from war file
    Thomas Diesler Master

    First you need to make a decission on whether your webapp is OSGi web container compliant or J2EE compliant. Currently we support both with different levels of functionality. The recommended approach is to deploy an J2EE webapp on AS7 and bridge into OSGi for selected functionality - an example of which is here

     

    On OSGi webapp support, have a look at the enterprise-4.2 specification.

  • 9. Re: How to make dependency on osgi bundle from war file
    Lee Smith Newbie

    The link to the bridge into OSGi example is dead, is the example available elsewhere?

  • 11. Re: How to make dependency on osgi bundle from war file
    ulrichromahn Newbie

    This link does not work either (anymore) since someone decided to remove the entire jbossas folderand the examples with it. Any idea where we can find this now???

  • 13. Re: How to make dependency on osgi bundle from war file
    ulrichromahn Newbie

    The original examples (which I could find by resetting my local git repo to the version before those examples got removed) were showing how to access an OSGi service from a non-OSGi webapp (WAR) by injecting of the OSGi context. However, the example above you are pointing to seems to be showing a WAB which was not the original question.

     

    So the primary question remains: where are the "examples" for a WAR accessing one or multiple OSGi resources (bundles, services, etc) now and why did the "original" examples got removed?

  • 14. Re: How to make dependency on osgi bundle from war file
    Thomas Diesler Master

    One the fundamental goals of jbosgi is to enable modular enterprise applications that can leverage the middle ware services provided by AS.

     

    It should technically not make a difference whether you deploy a WAR, setup some module dependencies and work with services that come from other (bundle) deployments. Howerver, I strongly discourage an attempt to achive modularity by putting

     

    Dependencies: some.named.dependency

     

    in your manifest. This violates the fundamental principals of modularity, is the tightest form of coupling you can get and is not portable. If you still think you need a named direct dependency you can use Require-Bundle - that is at least standard.

     

    The approach I recommend is to develop your JavaEE WAR as you would normally and then add standard OSGi metadata to it to make it modular. The wiring of the classloaders is then controlled by the OSGi layer - otherwise it should not make a difference to the behaviour in the server. Specifically, JBossWeb should not need to know that it is dealing with an OSGi bundle deployment.

     

    In short, you should be able to use Import-Package or Require-Bundle (if you must) instead of the jboss-modules native approach above.

    BundleContext injection should of course work as before.

1 2 3 Previous Next