我試圖讓我的servlet可以使用OSGI bundle進行擴展:新添加的bundle也必須是servlet。 Felix提供的Servlet Bridge功能http://felix.apache.org/documentation/subprojects/apache-felix-http-service.html,對我來說看起來非常好,但是我在安裝過程中遇到了一些問題。 作爲菲利克斯的網頁說,爲了設置servlet的橋樑,我們需要做的:Apache Felix Servlet橋接設置
- 部署Web應用程序內org.apache.felix.http.proxy jar文件(WEB-INF/lib目錄) ; [DONE]
在啓動監聽器(像的ServletContextListener)設置的BundleContext作爲servlet上下文屬性 [DONE]- 定義的web.xml內部org.apache.felix.http.proxy.ProxyServlet
- 和其註冊服務上的所有請求[DONE]
- 在web.xml定義org.apache.felix.http.proxy.ProxyListener爲允許HTTP會話相關的事件被轉發[DONE]
- 一定要添加javax.servlet; javax.servlet.http; version = 2.6到OSGi的系統軟件包[不是強制性]
- OSGi框架內部署org.apache.felix.http.bridge(或org.apache.felix.http.bundle)[????]
步驟6似乎不足以使servlet橋在我的情況下工作。 我爲我的捆綁servlet做了所有步驟1-5。我的主要servlet具有OSGI嵌入式機制,所以我從java代碼中部署我的bundle。 這是一塊OSGI發射器的代碼:
Map m = new HashMap();
m.putAll(System.getProperties());
m.put(Constants.FRAMEWORK_STORAGE_CLEAN, "onFirstInit");
m.put(Constants.FRAMEWORK_SYSTEMPACKAGES, "org.osgi.service.http");
fwk = getFrameworkFactory().newFramework(m);
fwk.start();
// Install bundle JAR files and remember the bundle objects.
BundleContext ctxt = fwk.getBundleContext();
for (int i = 0; i < jars.size(); i++) {
Bundle b = ctxt.installBundle(((File) jars.get(i)).toURI().toString());
bundleList.add(b);
}
// Start all installed non-fragment bundles.
for (int i = 0; i < bundleList.size(); i++) {
if (!isFragment((Bundle) bundleList.get(i))) {
((Bundle) bundleList.get(i)).start();
}
}
從主servlet代碼我需要安裝捆綁org.apache.felix.http.bridge
,一些依賴於我的servlet束(SLF4J,的javax.servlet ...)和我的servlet捆綁我已經完成了以下步驟1-5。 部署結果:沒有HttpService可用於Servlet Bundle - 這意味着我不能在我的應用程序中使用它,導致無法在我的Servlet包中註冊任何Servlet實例。
綜觀org.apache.felix.http.bridge
MANIFEST.MF我沒有找到像Export-Service: org.osgi.service.http.HttpService
任何提及如何做我需要用這個包?我如何設置servlet橋?
嗨。你有沒有在https://github.com/apache/felix/tree/trunk/http/samples/bridge看過這個例子,看看它是否適合你? –
當然,這個例子是關於如何爲servlet橋創建一個包。但我的問題是關於如何在服務器端使用這個包 –
該示例演示如何使用servlet橋構建一個war文件。它不構建捆綁。只是想知道這個例子是否按預期工作? –