簡體   English   中英

Apache Felix Servlet Bridge設置

[英]Apache Felix Servlet Bridge setup

我試圖使我的servlet可通過OSGI捆綁軟件擴展:新添加的捆綁軟件也必須是servlet。 Felix提供了一個Servlet Bridge功能http://felix.apache.org/documentation/subprojects/apache-felix-http-service.html ,對我來說很不錯,但是在設置過程中遇到了一些問題。 如Felix網頁所述,為了設置Servlet橋接,我們需要執行以下操作:

  1. 在Web應用程序(WEB-INF / lib)中部署org.apache.felix.http.proxy jar文件; [DONE]
  2. 在啟動偵聽器(如ServletContextListener)中,將BundleContext設置為Servlet上下文屬性[DONE]
  3. 在web.xml內定義org.apache.felix.http.proxy.ProxyServlet並將其注冊以服務於所有請求[完成]
  4. 在您的web.xml中將org.apache.felix.http.proxy.ProxyListener定義為,以允許轉發與HTTP會話相關的事件[完成]
  5. 確保將javax.servlet; javax.servlet.http; version = 2.6添加到OSGi系統軟件包中[不是強制性的]
  6. 在OSGi框架內部署org.apache.felix.http.bridge(或org.apache.felix.http.bundle) [????]

在我的案例中,步驟6似乎不足以使servlet橋接正常工作。 我為我的捆綁小服務程序完成了所有步驟1-5。 我的主要Servlet具有OSGI嵌入式機制,因此我從Java代碼部署了捆綁軟件。 這是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 ...)和我按照步驟1-5制作的servlet捆綁包的一些依賴項。 部署結果:Servlet捆綁包沒有可用的HttpService-這意味着我無法在應用程序中使用它,因此無法在Servlet捆綁包中注冊任何Servlet實例。

在查看org.apache.felix.http.bridge MANIFEST.MF時,我沒有發現任何類似Export-Service: org.osgi.service.http.HttpService提及Export-Service: org.osgi.service.http.HttpService
我該如何使用此捆綁包? 我需要如何設置Servlet橋接?

看來我在配置嵌入式OSGI時出錯。 現在我開始工作了,如果有人需要felix servlet橋的示例,請看一下: http : //vbashur.blogspot.kr/2014/07/osgi-servlet-bridge-sample.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM