随笔 - 1  文章 - 37  trackbacks - 0
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

留言簿(16)

随笔分类

随笔档案

文章分类

文章档案

test

搜索

  •  

最新评论

Extwind——支持OSGi应用的Tomcat

最新进度:

实现Tomcat与Equinox的扩展集成,全面兼容原始Tomcat和Equinox。
界面控制台基本完成,目前可以使用它控制OSGi-App中的bundle,功能(Install, Start, Stop, Uninstall )
在System Bundle(Equinox)中export: javax.servlet,org.extwind.osgi.service
实现HttpService注册Servlet和Resource
实现HttpService注册jsp 实现相同HttpContext注册地Servlet和Resource共享ServletContext
OSGiContext自动安装OSGi-App根目录中的jar包

Tomcat-OSGi QuickStart:

1. 准备工作
使用Extwind的Tomcat-OSGi是非常简单的,首先下载不到2M的rar文件,其中包括以下内容:
extwind-tomcat-osgi-0.1-alpha.jar  -  Tomcat于Equinox集成jar包,它是必须的。
org.eclipse.osgi-0.1-Alpha.jar   -  扩充过的Equinox osgi-framework,它不是必须的,如果不使用它,将需要额外的bundle去支持javax.servlet,javax.servlet.http,org.extwind.osgi.service.http,建议使用它,因为在以后的版本中,它有可能会成为必须得。
osgiManager   -   Web Application,支持OSGi Application管理的控制台,通过它可以对每一个OSGi-App中的bundle进行管理
osgiapp  -   一个非常简单的Web Application,里面包含一个简单的bundle,分别注册了一个static resource,一个jsp文件,一个Servlet
server.xml - Tomcat 6.x的示例配置文件,可选的
tomcat-users.xml - Tomcat 6.x 控制台用户权限配置文件,可选的


[ 点击这里下载 Tomcat-OSGi-QuickStart ]


2. 配置Tomcat 6.x
将Tomcat 6.x 解压到某目录,例如  D:\Tomcat6
将extwind-tomcat-osgi-0.1-alpha.jar   和   org.eclipse.osgi-0.1-Alpha.jar   拷贝到 D:\Tomcat6\lib  目录下
将osgiapp和osgiManager拷贝到 D:\Tomcat6\webapps 目录下
打开server.xml,在<Host>节点中加入2个属性 className和hostConfigClass,就像下面一样:(或者直接使用本例提供的server.xml)
<Host name="localhost"  appBase="webapps"
            unpackWARs
="true" autoDeploy="true"
            xmlValidation
="false" xmlNamespaceAware="false" className="org.extwind.tomcat.catalina.core.ExtenseStandardHost" hostConfigClass="org.extwind.tomcat.catalina.startup.ExtenseHostConfig">

将tomcat-users.xml拷贝到D:\Tomcat6\conf 目录下,覆盖原配置文件


3. 开始使用
经过以上简单的准备和配置工作,现在已经可以开始使用了,启动tomcat,访问

http://localhost:8080/osgiManager/html/list

 

认证框中的用户名和密码都是 tomcat,之后会进入下面这个页面



点击OSGi Console,进入/osgiapp的管理界面



可以看到,org.extwind.test.bundle已经被安装了,因为OSGi-App启动时会将根目录中的jar包作为bundle自动安装
控制台提供了4个功能:安装,启动,停止,卸载。 在以后的版本中会逐步加强控制台的管理功能。

在测试bundle中注册了3个资源

public class TestBundleActivator implements BundleActivator {
    
    HttpService httpService 
= null;

    
public void start(BundleContext context) throws Exception {
        ServiceReference sr 
= context.getServiceReference(HttpService.class
                .getName());
        httpService 
= (HttpService) context.getService(sr);
        System.out.println(
"====================================================");
        System.out.println(httpService.getClass().getName());
        System.out.println(
"====================================================");
        Dictionary
<String, String> initparams = new Hashtable<String, String>();
        initparams.put(
"servlet-name""petstore");
        initparams.put(
"load-on-startup""2");
        httpService.registerServlet(
"/test.do"new TestServlet(), initparams, null);
        httpService.registerResources(
"/files""/resource"null);
        httpService.registerResources(
"*.jsp""/resource"null);
    }


    
public void stop(BundleContext context) throws Exception {
        httpService.unregister(
"/test.do");
        httpService.unregister(
"/files");
        httpService.unregister(
"*.jsp");
    }


}

3个资源的链接分别是
http://localhost:8080/osgiapp/files/test.ini
http://localhost:8080/osgiapp/test.do
http://localhost:8080/osgiapp/resource/date.jsp
这里的jsp并没有使用Equinox的JspServlet,而是作为一个resource进行注册

现在,可以通过OSGi Console 对模块进行热插拔了。

到这里,已经基本使用了Tomcat-OSGi的简单功能,更多的功能正在开发中。


获取最新Tomcat-OSGi的源码:
http://code.google.com/p/extwind

加入Extwind Group马上开始讨论
http://groups.google.com/group/extwind

posted on 2009-04-12 02:17 Phrancol Yang 阅读(2779) 评论(1)  编辑  收藏 所属分类: OSGI

FeedBack:
# re: Extwind——支持OSGi应用的Tomcat [未登录] 2010-01-11 16:50 Thinker
能不能把源代码发我一下,我想学习学习,谢谢
tzh8478@163.com  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: