隨筆 - 1  文章 - 37  trackbacks - 0
          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          留言簿(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 閱讀(2508) 評論(0)  編輯  收藏 所屬分類: OSGI
          主站蜘蛛池模板: 大连市| 碌曲县| 岳普湖县| 安徽省| 类乌齐县| 北流市| 定结县| 五常市| 威远县| 洛扎县| 孝感市| 高淳县| 和龙市| 延庆县| 南江县| 庄河市| 阳城县| 岑巩县| 卢氏县| 宕昌县| 忻城县| 漯河市| 永泰县| 大新县| 阳曲县| 张家界市| 会理县| 弥渡县| 北海市| 绵阳市| 永平县| 高邑县| 抚远县| 丰镇市| 宁武县| 泾川县| 白水县| 贵德县| 蓝山县| 广河县| 武穴市|