Injecting blueprint OSGi service into JSF/PrimeFaces bean

最后都变了- 提交于 2019-12-06 12:27:57

问题


I have a project built on top OSGi and Karaf server. For dependency injection we are using Aries Blueprint. The main part of the project is a Apache Camel routes and integration things, but now I need to create some maintenance web interface. So I give a try to JSF - PrimeFaces implementation. I was able to create some demo, which works in OSGi under Karaf, that's ok.

Now I'd like to know if it's possible to use Blueprint here, to reference some already existing OSGi services we have and inject the service into JSF Bean, so we can benefit from already written code.

Can you help me, please?


回答1:


We solved this in the following way:

  • We created a listener that:
    • Creates a ServiceTracker that tracks the BlueprintContainer service attached to the same bundle
    • Puts the servicetracker into the ServletContext attributes
  • We created an ELResolver that uses this ServiceTracker and if there is a BlueprintContainer available it uses the getComponentInstance of that to get the value
  • The listener opens the servicetracer during application initialization and closes it during application destroy

Our listener class: https://source.everit.biz/svn/everit-util/trunk/core/src/main/java/org/everit/util/core/servlet/ServiceLoaderListener.java

Our EL resolver class: https://source.everit.biz/svn/everit-util/trunk/core/src/main/java/org/everit/util/core/el/OsgiELResolver.java

User/pass: guest/guest

After you registered your custom el-resolver all el-expressions will be evaluated in the way that id-s of component instances will be searched inside the blueprint container. In case you say that you have a bean-property in your faces-config.xml with the value #{myComponent} it will be searched inside the BlueprintContainer.



来源:https://stackoverflow.com/questions/17962399/injecting-blueprint-osgi-service-into-jsf-primefaces-bean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!