OSGI创建模块化Web应用程序 [英] OSGI creating modular web application

查看:130
本文介绍了OSGI创建模块化Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一种创建模块化Web应用程序的解决方案,它是模块化的,用户可以以简单的jar形式提供自己的插件,然后将其自己的数据提供给我的Web应用程序和我的webapp将负责显示它。

I have been looking for a solution to create a modular web application, which is modular in the sense that user can provide its own plugin in form of a simple jar which will then provide its own data to my web application and my webapp will be responsible for displaying it.

现在,我希望我的网络应用程序尽可能通用,而不依赖于j2ee Web容器来支持任何内容。即我不能依靠我的Web容器来提供osgi支持并将Web应用程序部署为osgi包本身(这对于例如glassfish和WAS来说真的很简单)。

Now the catch is i want my web app to be as generic as possible without relying on the j2ee web container to support anything . i.e. i cant rely on my web container to provide osgi support and deploy web application as an osgi bundle itself ( which truly makes things very simple for eg. glassfish and WAS).

我打算使用equinox,我只看到解决方案是他们在官方网站上提供的servlet桥,但对我而言,将所有内容委托给我真是太痛苦了。一个servlet,它将依次解释请求并找到一个合适的bundle类,然后再以某种方式仅将数据传回Web应用程序。

I am planning to use equinox and only solution i see currently is the servlet bridge they provide on their official site, but to me it is really a pain to delegate everything to a servlet which will in turn interpret the request and find an apropriate bundle Class and then again communicate back somehow only the data to the web application.

对我而言,如果我的网络应用程序也是一个捆绑包,那就太棒了。
我能尝试的理想解决方案有什么接近的吗?或osgi和web应用程序(容器)的两个关系之间的任何其他通信方法?

To me it would be wonderful if my web app was also a bundle. Is there anything close to this ideal solution which i can try for? Or any other communication method between the two relams of osgi and web appliction (container)?

推荐答案

OSGi规范详细介绍了WAB(Web存档包)格式。

The OSGi spec details the WAB (Web Archive Bundle) format.

Pax Web 为WAB提供了极大的支持/ WAR webapps(PAX Web在Equinox,Felix等上正常运行)

And Pax Web offers great support for WAB/WAR webapps (PAX Web runs fine on Equinox, Felix, etc)

使用pax web,您可以通过ServletContext获取BundleContext,例如:

Using pax web you get the BundleContext via the ServletContext, eg:

BundleContext bundleContext = (BundleContext) getServletContext().getAttribute("osgi-bundlecontext");

对于你提到的用户驱动的可插拔性,我建议你为插件包提供一些服务接口实施并在您的webapp中使用 ServiceTracker 听取他们的注册(除非您使用声明式服务)。您也可以轻松地安装捆绑包。

For the user driven pluggability you mention, I'd suggested you provide some service interfaces for the plugin bundles to implement and in your webapp use a ServiceTracker to listen for their registration (unless you're using Declarative Services). You also easily be able to install bundles from an upload servlet.

我猜测用户上传插件必须登录并获得授权,所以此时安全问题已得到满足。

I'm guessing users uploading plugins would have to be logged in and authorized, so security issues will have been met at this point.

编辑:在此回复评论空间不足在评论栏中

道歉,我想你误解了你的问题 - 你有一个现有的webapp容器,你想部署一个带OSGi功能的WAR吗?如果是这种情况,那么要么像其他人提到的那样使用ServletBridge,要么将OSGi框架嵌入到WAR中(这相对容易,请参阅这个例如)。

Apologies, think I misinterpreted you question - you have an existing webapp container(s) and you want to deploy a WAR with OSGi functionality? If that's the case then either use the ServletBridge as others have mentioned or embed an OSGi framework into your WAR (this is relatively easy, see this for example).

你甚至可以通过尝试从ServletContext获取BundleContext来使这个可选,如果这将返回null然后启动您自己的嵌入式框架。这样它将在本机OSGi容器(例如Glassfish)或Java EE应用服务器中运行。

You could even make this optional by attempting to get the BundleContext from the ServletContext and if this returns null then launch your own embedded framework. That way it'll run in a native OSGi container (e.g. Glassfish) or in a Java EE app server.

否则,PaxWeb是HttpService和WebApp OSGi的实现规范,但有很多扩展,使生活更轻松 - 但你将其部署到OSGi容器。

Otherwise, PaxWeb is an implementation of the HttpService and WebApp OSGi specs, but with lots of extensions to make life easier - but you deploy this to an OSGi container.

这篇关于OSGI创建模块化Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆