我正在尝试使用OSGI包来扩展我的servlet:新添加的包也必须是servlet。有一个由Felix http://felix.apache.org/documentation/subprojects/apache-felix-http-service.html提供的Servlet Bridge功能,看起来非常好,但我在设置过程中遇到了一些问题。 正如Felix网页所说,为了设置servlet桥,我们需要做:
- 在Web应用程序(WEB-INF / lib)中部署org.apache.felix.http.proxy jar文件; [DONE]
- 在启动侦听器(如ServletContextListener)中将BundleContext设置为servlet上下文属性 [DONE]
- 在web.xml中定义org.apache.felix.http.proxy.ProxyServlet并将其注册以用于所有请求 [DONE]
- 将org.apache.felix.http.proxy.ProxyListener定义为您的web.xml,以允许转发与HTTP会话相关的事件 [DONE]
- 务必将javax.servlet; javax.servlet.http; version = 2.6添加到OSGi系统包 [非强制性]
- 在OSGi框架内部署org.apache.felix.http.bridge(或org.apache.felix.http.bundle) [????]
醇>
步骤No 6似乎不足以使servlet桥在我的情况下工作。 我为我的bundle 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
bundle,我的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桥?
答案 0 :(得分:1)
看起来我在配置嵌入式OSGI时出错了。现在我得到了它,如果有人需要一个felix servlet桥的样本看看这个:http://vbashur.blogspot.kr/2014/07/osgi-servlet-bridge-sample.html