【问题标题】:Apache Felix Servlet Bridge setupApache Felix Servlet 桥设置
【发布时间】:2014-08-10 17:09:08
【问题描述】:

我正在尝试使用 OSGI 包使我的 servlet 可扩展:新添加的包也必须是 servlet。 Felix http://felix.apache.org/documentation/subprojects/apache-felix-http-service.html 提供了一个 Servlet Bridge 功能,对我来说看起来很不错,但我在设置过程中遇到了一些问题。 正如 Felix 网页所说,为了设置 servlet 桥,我们需要做:

  1. 在 Web 应用程序 (WEB-INF/lib) 中部署 org.apache.felix.http.proxy jar 文件; [完成]
  2. 在启动监听器(如 ServletContextListener)中将 BundleContext 设置为 servlet 上下文属性 [DONE]
  3. 在您的 web.xml 中定义 org.apache.felix.http.proxy.ProxyServlet 并注册它以服务于所有请求[DONE]
  4. 在您的 web.xml 中将 org.apache.felix.http.proxy.ProxyListener 定义为允许转发 HTTP 会话相关事件 [DONE]
  5. 务必将 javax.servlet;javax.servlet.http;version=2.6 添加到 OSGi 系统包[非强制性]
  6. 在 OSGi 框架内部署 org.apache.felix.http.bridge(或 org.apache.felix.http.bundle)[????]

第 6 步似乎不足以让 servlet 桥在我的情况下工作。 我为我的 bundle 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 Bundle 的 HttpService - 这意味着我无法在我的应用程序中使用它,导致无法在我的 servlet 包中注册任何 Servlet 实例。

查看org.apache.felix.http.bridge 的 MANIFEST.MF,我没有找到像 Export-Service: org.osgi.service.http.HttpService 这样的提及
我需要如何使用这个捆绑包?我需要如何设置 servlet 桥接器?

【问题讨论】:

  • 嗨。您是否尝试过github.com/apache/felix/tree/trunk/http/samples/bridge 的示例,看看是否适合您?
  • 当然,这个例子是关于如何为 servlet 桥创建一个包。但我的问题是关于如何在服务器端使用这个包
  • 该示例展示了如何使用 servlet 桥构建一个 war 文件。它不构建捆绑包。只是想知道该示例是否按预期工作?
  • 就我而言,它没有按预期工作。但是我修改了这个示例。而不是使用war文件,我想使用一个包(jar文件)并将这个包安装到主servlet的OSGI嵌入式框架

标签: servlets osgi apache-felix embedded-osgi


【解决方案1】:

看起来我在配置嵌入式 OSGI 时出错了。现在我搞定了,如果有人需要一个 felix servlet 桥的样本,请看一下:http://vbashur.blogspot.kr/2014/07/osgi-servlet-bridge-sample.html

【讨论】:

    猜你喜欢
    • 2013-12-25
    • 2013-03-04
    • 2019-01-28
    • 2018-05-14
    • 2012-08-28
    • 2019-12-15
    • 2016-03-26
    • 2011-11-03
    • 2016-12-25
    相关资源
    最近更新 更多