サーブレットブリッジ osgi 実装を使用して tomcat にデプロイされた単純な WAB にアクセスできません。
純粋な osgi バンドルを使用して HttpService を使用して jsp/servlets/html をプログラムで登録することができ、このバンドルにアクセスできました。次に試したのは、1 つの html リソースと 1 つのサーブレット リソースを含む別の WAB を作成することでしたが、バンドルにアクセスする際に問題が発生しました。私はjarredとunjarredの両方のバンドルを試しました。私が今想定しているのは、WAB の場合、プログラムまたは宣言的な方法でリソースを登録する必要がないということです。
以下は、私が作成した WAB バンドルです。コンソールにアクティブ化および非アクティブ化メッセージを表示するためのアクティベーターのみで、Http Service Tracker は含まれていません。
sample.http1
helloworld.html
|META-INF
MANIFEST.MF
|WEB-INF
web.xml
|classes
|sample
|http
Activator.class
HelloWorldServlet.class
以下はMANIFEST.MFファイルです
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: sample.http1
Bundle-SymbolicName: sample.http1
Bundle-Version: 1.0.0
Bundle-Activator: sample.http.Activator
Import-Package: javax.servlet,javax.servlet.http,org.osgi.framework, org.osgi.service.http, org.osgi.util.tracker
Bundle-ClassPath: WEB-INF/classes
Web-ContextPath: /samplehttp
以下はActivatorクラスのコードです
package sample.http;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {
public void start(BundleContext context) throws Exception {
System.out.println("Starting Hello World");
}
public void stop(BundleContext context) throws Exception {
System.out.println("Stopping Hello World");
}
}
以下はweb.xmlの内容です
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<servlet>
<servlet-name>helloworld</servlet-name>
<servlet-class>sample.http.HelloWorldServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>helloworld</servlet-name>
<url-pattern>/helloworld</url-pattern>
</servlet-mapping>
</web-app>
次に、このバンドルを有効にしました。以下のように WAB リソースにアクセスしようとしましたが、404 page resource not found エラーが発生します。
http://localhost/bridge/samplehttp/helloworld.html
-- 静的 html の場合
http://localhost/samplehttp/helloworld.html
http://localhost/bridge/samplehttp/helloworld
-- HelloWorldServlet の場合
http://localhost/samplehttp/helloworld
Tomcat はポート 80 でホストされており、HttpService を使用してプログラムで登録されている他の osgi バンドルにアクセスできます。以下の osgi バンドルは完全に機能します。
例えば http://localhost/bridge/jsp-examples/helloworld.jsp
ご意見をお聞かせください。osgi 仕様書と別のブログ ( http://www.javabeat.net/2011/11/writing-an-osgi-web-application/ ) を参照しました。