Foros de discusión

RE: Call OSGi service from portlet

Chris Zosel, modificado hace 10 años.

Call OSGi service from portlet

New Member Mensajes: 8 Fecha de incorporación: 30/01/14 Mensajes recientes
Dear Liferay community,

since version 6.2 Liferay features OSGi support, which i am trying to make use of. I don't need to deploy my portlets as OSGi bundles (even though that would be the best), but i do need to access an OSGi service from my (non-OSGi) portlets.

As i am pretty new to both Liferay and OSGi, i started out with this OSGi tutorial. This left me with three very basic OSGi bundles, that i want to try to reach from my portlet. First, i installed and started the bundles using the Liferay OSGi shell:

START LEVEL 20
   ID|State      |Level|Name
    0|Active     |    0|OSGi System Bundle (3.8.0.v20120529-1548)
    1|Active     |    6|Apache Felix File Install (3.1.10)
    2|Active     |    1|Apache Felix Declarative Services (1.6.2)
    3|Active     |    1|osgi.enterprise (4.2.0.201003190513)
    4|Active     |    1|OSGi Release 4.2.0 Utility Classes (3.2.300.v20120522-1822)
    5|Active     |    1|Gemini Management (1.0.1.RELEASE)
    6|Active     |    1|OSGi Release 4.2.0 Services (3.3.100.v20120522-1822)
   10|Active     |    6|Apache Felix Gogo Command (0.12.0)
   11|Active     |    6|Apache Felix Gogo Runtime (0.10.0)
   12|Active     |    6|Apache Felix Gogo Shell (0.10.0)
   13|Active     |    6|Console plug-in (1.0.0.v20120522-1841)
   15|Active     |    1|org.example.api (0.0.0)
   16|Active     |    1|org.example.impls.provider (0.0.0)
   18|Active     |    1|org.example.impls.command (0.0.0)


But how can i call the service defined in org.example.api from a portlet now? After some searching i found this approach:
BundleContext ctx = FrameworkUtil.getBundle(Greeting.class).getBundleContext();
	    ServiceReference serviceReference = ctx.getServiceReference(PackageAdmin.class.getName());
	    PackageAdmin adm = PackageAdmin.class.cast(ctx.getService(serviceReference));


which unfortunately only seems to work within the OSGi context. Now my thought was to call some Liferay service (as they are reachable from the OSGi context) to register the BundleContext, and obtain it within the portlet from the same Liferay service. However, i have no idea if there is some liferay service to do this, or if i could write one myself (how are liferay services made available in the OSGi context?), or if my problem can be solved in a totally different way in the first place.

Any help is much appreciated!
Chris
thumbnail
Miguel Pastor Olivar, modificado hace 10 años.

RE: Call OSGi service from portlet

New Member Mensajes: 24 Fecha de incorporación: 1/03/11 Mensajes recientes
Hey Chris,

Consuming Liferay Services is extremely easy using a framework like Declarative Services (which already is packed within the release). Consuming services from a component which is not an OSGi component requires a small trick or using the OSGi API (I don' t recommend you to do this if you are not very familiar with OSGi).

You can found a completely application developed on top of OSGi in my Github repo (rebased just right now with the latests contents from master)

I would like to add that the OSGi support included in 6.2.0 is not as good as it should be, but this wasn't the main goal for this release. We just need to put the foundations in place, and right now we need to move forward.

If more people is interested, we could arrange a Hangout (or similar) talk where I could should you some of the things you can do with the contents released in 6.2.0 version.

Hope it helps!

Migue
thumbnail
Jack Bakker, modificado hace 10 años.

RE: Call OSGi service from portlet

Liferay Master Mensajes: 978 Fecha de incorporación: 3/01/10 Mensajes recientes
Hi Miguel,

Your link to 'Github repo" points to this message thread... I am curious to learn more...

Thanks
Jack
thumbnail
Christoph Rabel, modificado hace 10 años.

RE: Call OSGi service from portlet

Liferay Legend Mensajes: 1555 Fecha de incorporación: 24/09/09 Mensajes recientes
+1
Very interesting topic.
thumbnail
Miguel Pastor Olivar, modificado hace 10 años.

RE: Call OSGi service from portlet

New Member Mensajes: 24 Fecha de incorporación: 1/03/11 Mensajes recientes
Sorry about the link guys,

This should be the correct link emoticon
thumbnail
Jack Bakker, modificado hace 10 años.

RE: Call OSGi service from portlet

Liferay Master Mensajes: 978 Fecha de incorporación: 3/01/10 Mensajes recientes
Thanks Miguel, leaving Rome wasn't built in a day emoticon

I'd like to hear more on ideas for future wrt OSGi. Container restart after move to global classpath for services that many portlets consume gets dev-time consuming.
Patrick Warnecke, modificado hace 10 años.

RE: Call OSGi service from portlet

New Member Mensajes: 20 Fecha de incorporación: 30/11/12 Mensajes recientes
Hello,
my company is very interested in the idea of OSGi integration and I should do some research regarding this topic, but I can hardly find any information how to deploy, develop or user OSGi Services with/in Liferay.
Could anyone point me to liferay specific documentation or tutorials or something?

Thanks in advance.