随笔 - 1  文章 - 37  trackbacks - 0
<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

留言簿(16)

随笔分类

随笔档案

文章分类

文章档案

test

搜索

  •  

最新评论

关于作者
      The author of this article is co-author of the book "Struts Best Practices" published in German (2004) and French (Feb 2005). He has been working with Java n-tier web since 1998, including SilverStream appserver, before the advent of OS and J2EE. His company, Infonoia SA is editor of multi-platform, multi-repository software and solutions around document retrieval and publishing. Infonoia also provides consulting services, mentoring and training (English, French, German) on Best Practices in the web technologies and frameworks they use, such as Struts, Eclipse and RSP. Wolfgang is also available for speaking engagements on RSP. Wolfgang can be reached at wgehner at infonoia dot com.

关于本文
      这篇文章将会分成两个部分通过分析一个实例去分析如果使用OSGI构建一个WEB应用。
        第一个部分只是简单的介绍了如何在应用中创建扩展点(extension points),第二部分将通过映射你自己的Servlet和依赖关系使其能够作为一个新的Web应用运行

Extensions and Extension points
      在RSP Samples里面的每个Bundle目录中都有一个 plugin.xml,这里面所配置的 Extension 和 Extension point让这些URL和Resource能够被访问到,它为各个Bundle间的协作提供了一个通道。(个人感觉这里所说的扩展和扩展点有点像Spring AOP里面的 Advice 和 Pointcut),
      OSGI-R4规范中提供了Declarative Services (简称DS)机制,关于DS的详细介绍请查阅 BlueDavy 的Opendoc.

      用Plug-in Manifest Editor打开org.rsp.framework.struts中的Plugin.xml,进入 Extensions 面板,可以看到这个Bundle使用了3种Equinox的Extension(看字面意思就能知道这3种Extension是做什么用的),再进入 Extension points面板,没有发现该Bundle提供任何扩展点(Extension points),分析一下具体配置.
 1<?xml version="1.0" encoding="UTF-8"?>
 2<?eclipse version="3.0"?>
 3<plugin>
 4    <extension id="myservletID" name="myservletName" point="org.eclipse.equinox.servlet.ext.servlets">
 5        <alias>/do</alias>
 6        <servlet-class>org.rsp.framework.struts.base.BundleActionServlet</servlet-class>
 7        <init-param>
 8            <param-name>config</param-name>
 9            <param-value>*/WEB-INF/struts-config.xml</param-value>            
10        </init-param>        
11        <init-param>
12            <param-name>chainConfig</param-name>
13            <param-value>*/WEB-INF/chain-config.xml</param-value>            
14        </init-param>
15        <httpcontext-name>cross-context</httpcontext-name>
16    </extension>
17
18    <extension id="myservletID3" name="myservletName3" point="org.eclipse.equinox.servlet.ext.servlets">
19        <alias>/struts/strutstest.jsp</alias>
20        <servlet-class>org.rsp.framework.struts.strutstest_jsp</servlet-class>
21        <httpcontext-name>cross-context</httpcontext-name>
22    </extension>
23
24    <extension id="testResource" point="org.eclipse.equinox.servlet.ext.resources">
25        <alias>/struts</alias>
26        <base-name>/</base-name>
27        <httpcontext-name>cross-context</httpcontext-name>
28    </extension>
29     
30    <extension point="org.eclipse.equinox.servlet.ext.httpcontexts">
31        <path>/WebContent</path>
32        <httpcontext-name>cross-context</httpcontext-name>
33    </extension>
34 
35</plugin>

第4-16行,扩展了org.eclipse.equinox.servlet.ext.servlets,也就是说/do路径下的URL都交给org.rsp.framework.struts.base.BundleActionServlet去处理
第18-22行,将/struts/strutstest.jsp 交给 org.rsp.framework.struts.strutstest_jsp去处理
第24-28行,资源路径的映射
第30-33行,Context映射


The structure of servlet "extension points" is similar, but not quite identical to what you would find in a web.xml . replaces and is new. The OSGi standard specifies that each HTTP service (used by the BridgeServlet , under the hood) uses a different ServletContext * unless the HttpContext is shared*. This could create problems in case of MVC forwards, where usually certain information is passed from the first servlet to the second via the request context. That transport would be broken under Eclipse-OSGi if different or "null" HttpContexts are used among the related servlets. The trick is to give all servlets and resources the same " httpcontext-name ". The name of our choice is "cross-context" (alluding to the Tomcat server.xml attribute as in cross-context="true" , which does similar things but across web applications.). 

同理,资源映射也是如此     

本文翻译到此已经基本告一段落,原文后面的内容都是基本操作,而本文宗旨就是对OSGI的Web应用有个大概的了解,这个目的已经达到了。

结束语

偶尔从Google上搜索到了这篇文章,感觉对像我这样的OSGI初学者很有用,于是将其意思整理了一下,帖在BLOG上,希望能对路过的OSGI爱好者有所帮助。
如果想更好的理解作者的意图,建议看原文。
欢迎大家通过邮箱
osgi.phrancol@gmail.com与我讨论有关OSGI的话题。

作者针对原文开的讨论帖 , [点击这里]
Spring-osgi首页有个OSGI视频课程,值得一看 [
点击这里]
BlueDavy的BLOG [
点击这里]
Equinox in a Servlet Container
Developing Eclipse/OSGi Web Applications Part 1 
Developing Eclipse/OSGi Web Applications Part 2

posted on 2007-08-30 11:05 Phrancol Yang 阅读(2482) 评论(0)  编辑  收藏 所属分类: OSGI

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


网站导航: