tianxiaolu 2007-01-26
随着OSGi/Equinox逐渐成为JavaEE服务端的基础软件架构,OSGi上部署WEB应用程序的解决方案日渐成熟。这里介绍三种目前我们所知的解决方案,前两种是Equinox组织提出的方案,后一种是OpenCore平台采取的解决方案。
WEB-INF的目录结构大致如下(大致如此):
* /WEB-INF
o /web.xml (with one servlet entry assigning all incoming requests to the BridgeServlet)
o /lib/servletbridge.jar (the classes associated with the equinox.servletbridge)
o /eclipse (the eclipse platform directory)
+ launch.ini (contains framework properties that will allow override of any eclipse specific System Properties)
+ /configuration (contains config.ini which lists the bundles you want to have available)
+ /features
+ /plugins 部署结构如下图(转载):
个人感觉这个解决方案使用价值不大。
OSGi标准中的HTTP服务接口如下:
package org.osgi.service.http;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import java.util.Dictionary;
public interface HttpService {
public void registerServlet(String alias, Servlet servlet,
Dictionary initparams, HttpContext context)
throws ServletException, NamespaceException;
public void registerResources(String alias, String name,
HttpContext context) throws NamespaceException;
public void unregister(String alias);
public HttpContext createDefaultHttpContext();
} 部署结构图(转载):
因为OSGi是最早为嵌入式系统设计,所以OSGi标准中的HTTP服务只提供了有限的Servlet与静态资源的发布功能,没有一个完整的WEB容器概念,这种模式更适合通过WEB方式暴露(Export)服务,不太适合开发展现层的WEB应用。
通过Equinox提供的扩展/扩展点功能可以简化这种方式WEB应用的开发,就是通过plugin.xml来配置Servlet和静态页面的注册。
这三种插件类型间关系类似Decorator模式,从内到外增加"特征"描述:
这样我们可以把一个应用的WEB层像业务层一样,分割为多个插件,部署在OSGi/Equinox的框架中.
部署结构图:
我们觉得这种方式以合适的力度将WEB层分割为插件部署在OSGi框架上,充分的发挥了OSGi体系结构的强大之处,也提高了WEB层开发部署的灵活性。目前,业界好像也有很多项目是采用这中方式部署。这种部署方式的缺点是,不得不修改Jetty容器的实现,以使其适应OSGi的环境,我们希望Jetty以后能支持这个功能:)
GoogleCode上发布了一个基于OpenCore的示例项目linktalk,一个基于GWT、Equinox、OpenCore的Ajax聊天室。
项目地址:http://code.google.com/p/lintkalk
源码下载:svncheckouthttps://linktalk.googlecode.com/svn/trunk/project
程序下载:svncheckouthttps://linktalk.googlecode.com/svn/trunk/release