• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OSGi + Glassfish + JEE 6 howto?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am somewhat new to using pure JEE without Spring framework or dm/Virgo server. I've worked with OSGi using Spring framework and their XML based OSGi services/references declarations.

Is there any way to configure OSGi services in the same manner using pure JEE 6 on Glassfish?

I've found some examples of modular projects using beans from each other's context, but it was done directly in the code via references to container classes and resources, which I consider rather crude and unaesthetic solution.

I'd be grateful for any help and examples of such configuration.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
GlassFish supports OSGi bundle deployment and various OSGi enterprise technologies. So not only GlassFish allows one to use OSGi APIs, it also allows one to use OSGi and Java EE together. Check out
http://wikis.sun.com/display/GlassFish/BlogsGfOsgi

Feel free to send questions to users(at)glassfish.java.net

-- Sahoo
 
Szymon Pietrzak
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is true, but what I was thinking about was something similar to Spring OSGi context declaration, which allows you to declare beans, OSGi services and import them from the context of one module bundle to another.

Here the import seems easy using JEE dependency injection and annotations, but you still have to declare bundle activator and register your services in code, not in config file. I was wandering whether or not such way of bundle services declaration (one XML config file) is supported by JEE and whether or not it is possible to avoid declaring them in code.

BTW. great video tutorial, clarifies a lot!
 
Sanjeeb Sahoo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We do support various forms of declarative services. e.g., GlassFish includes an implementation of OSGi Declarative Service implementation (aka Service Component Runtime) which one can use to declaratively register services in OSGi service registry. GlassFish also supports an interesting concept called EJB based OSGi service. This is again a form of declarative service where in user does not have to explicitly register their services. User develops regular stateless EJBs with locan business interfaces makes them part of an OSGi bundle. GlassFish will automatically register those EJBs as OSGi services for consumption from any other OSGi bundle context using whichever means user choses to use. Look for EJB/OSGi support in that Wiki - you shall find some examples. The advantage of using an EJB based OSGi service is that you have access to a rich set of Java EE APIs as well as features like declarative transaction, security, dependency injection available to your OSGi service!

GlassFish also makes available Java EE resources like JDBC DataSources, JMS Queues and Topics as OSGi Services.
 
Szymon Pietrzak
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can see multitude of examples, but still have some questions:

1. Can an EJB be registered as OSGi service without use of BundleActivator and direct call to OSGi APIs (for instance via annotation)? From your reply I understand that each EJB is automatically registered as OSGi service on GlassFish - am I correct?

2. Can an OSGi service which is EJB be referred to from another module only via use of annotations (@Injected @OSGiService) or do I have to create BundleActivator and use ServiceTracked to find the service in the context?
 
Sanjeeb Sahoo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Szymon Pietrzak wrote:I can see multitude of examples, but still have some questions:

1. Can an EJB be registered as OSGi service without use of BundleActivator and direct call to OSGi APIs (for instance via annotation)? From your reply I understand that each EJB is automatically registered as OSGi service on GlassFish - am I correct?

2. Can an OSGi service which is EJB be referred to from another module only via use of annotations (@Injected @OSGiService) or do I have to create BundleActivator and use ServiceTracked to find the service in the context?



Answer to first question is YES - that's why I call it one kind of declarative service. To use this automatics registration feature, you have to package your EJBs in an OSGi bundle - you can basically turn your existing ejb-jar to an OSGi bundle. You then have to add a manifest entry called Export-EJB which can have values like "ALL" to indicate export all EJBs or comma separated names of EJBs that need to be exported. Currently the implementation supports only registration of Statelss or Singleton EJBs with local business interfaces, i.e, you can't export EJBs with remote interfaces or stateful EJBs.

Answer to second question is also yes. Once the EJB is exported as a service, you can consume it however you like including but not limited to via @Inject @OSGiService.

Please use users@glassfish.java.net while starting any new thread - you will get faster responses as well as responses from other users.

Thanks,
Sahoo
 
Ranch Hand
Posts: 686
Mac
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just curious to know why do you need to run JEE and OSGI together. I believe JEE 6 is more advanced and support same modularity which OSGI supports.

-Jignesh
 
reply
    Bookmark Topic Watch Topic
  • New Topic