hello osgi jsp example
Oct
源起
OSGi 的 HttpService 只提供 servlet 與靜態 resource 註冊,並不提供 JSP,同時 OSGi 定義只到 Servlet API 2.1 版本,如果需要支援 JSP 等標準,就必須另外掛一些 bundle 上去。
一開始需要下載 OSGi 的環境來用。
http://www.eclipse.org/equinox/
HTTP Service (Servlet 2.4 API)
目前還未正式釋出,可以用 eclipse 3.2 team project 匯入來使用,真正要用時再直接匯出成 jar 即可。根據 maillist 的說法,可能會在 3.3M3 釋出,到時就可以直接拿來用。
Embedding an HTTP server in Equinox
http://www.eclipse.org/equinox/server/http_in_equinox.php
http://www.eclipse.org/equinox/server/downloads/jettyhttp-anon.psf
HTTP Service 的實做變成 org.eclipse.equinox.http.jetty,設計方式為轉接 HTTP Service 介面到 jetty 的介面,就可以讓 OSGi 環境使用。
因為 jetty 緣故,所以可以提供 Servlet 2.4 支援,不過需要支援的相依 jar 會比較多。
osgi> 2006/10/26 上午 11:32:58 org.mortbay.http.HttpServer doStart 資訊: Version Jetty/5.1.x 2006/10/26 上午 11:32:58 org.mortbay.util.Container start 資訊: Started org.mortbay.jetty.servlet.ServletHandler@12558d6 2006/10/26 上午 11:32:58 org.mortbay.util.Container start 資訊: Started HttpContext[/,/] 2006/10/26 上午 11:32:58 org.mortbay.http.SocketListener start 資訊: Started SocketListener on 0.0.0.0:80 2006/10/26 上午 11:32:58 org.mortbay.util.Container start 資訊: Started org.mortbay.http.HttpServer@1e859c0 osgi> ss Framework is launched. id State Bundle 0 ACTIVE system.bundle_3.3.0.v20060919 4 ACTIVE org.eclipse.equinox.ds_1.0.0.v20060828 7 ACTIVE org.eclipse.equinox.log_1.0.100.v20060717 8 ACTIVE org.eclipse.osgi.services_3.1.100.v20060918 14 ACTIVE javax.servlet_2.4.0.200610251415 15 ACTIVE org.apache.commons.logging_1.0.4.200610251415 16 ACTIVE org.eclipse.equinox.http.jetty_1.0.0.200610251415 17 ACTIVE org.eclipse.equinox.http.servlet_1.0.0.200610251415 18 ACTIVE org.mortbay.jetty_5.1.11.200610251415
JSP
一樣用 team projext 匯入。根據 maillist 的說法,可能會在 3.3M4 釋出,到時就可以直接拿來用。
OSGi based JSP Support
http://www.eclipse.org/equinox/server/jsp_support.php
http://www.eclipse.org/equinox/server/downloads/jspsupport-anon.psf
Framework is launched. id State Bundle 0 ACTIVE system.bundle_3.3.0.v20060919 4 ACTIVE org.eclipse.equinox.ds_1.0.0.v20060828 7 ACTIVE org.eclipse.equinox.log_1.0.100.v20060717 8 ACTIVE org.eclipse.osgi.services_3.1.100.v20060918 14 ACTIVE javax.servlet_2.4.0.200610251415 15 ACTIVE org.apache.commons.logging_1.0.4.200610251415 16 ACTIVE org.eclipse.equinox.http.jetty_1.0.0.200610251415 17 ACTIVE org.eclipse.equinox.http.servlet_1.0.0.200610251415 18 ACTIVE org.mortbay.jetty_5.1.11.200610251415 27 ACTIVE javax.servlet.jsp_2.0.0.200610251427 28 ACTIVE org.apache.commons.el_1.0.0 29 ACTIVE org.apache.jasper_5.5.17.200610251427 30 ACTIVE org.eclipse.equinox.jsp.examples_1.0.0 31 ACTIVE org.eclipse.equinox.jsp.jasper_1.0.0.qualifier 32 ACTIVE org.eclipse.equinox.jsp.jstl_1.0.0 33 ACTIVE org.eclipse.equinox.jsp.jstl.examples_1.0.0
The jsp/jstl examples can be found at :
http://localhost/jsp-examples/index.html
http://localhost/jstl-examples/index.html
心得
- OSGi 的應用慢慢移到 server-side 和 eclipse 的這些年應用推廣很有關係,目前來看,開發一個 Bundle 最方便的方式還是開 eclipse 來用,雖然它的 PDE 環境還不是完整地支援 OSGi 開發,但是應會慢慢變的更完整。就馬上要用的需求來說,eclipse 的 PDE 環境算是十分方便,這點還沒在其開發環境看到。
- 類似 OSGi 的環境猜想應早就有人做過,只是沒到臨界點無法流行,目前 OSGi 有 eclipse IDE 這類比較大的用戶基礎來支撐,可以不斷演進與除錯,這點對於微型應用開發者來說,還蠻重要的。