如何在Tapestry中使用OSGi服务
我有我的Tapestry Web应用程序,可为某些数据集提供完整的CRUD功能。 到目前为止,我一直在使用mock来开发和测试它。
但是,我现在需要通过OSGi服务(与Felix一起运行)替换该模拟。
我的主要问题是:
HttpService
吗(我瞥了一些关于它的投诉,但并不完全理解它) 为了给你提供一些背景,这就是我现在正在做的事情
public class MyPage {
...
@Inject
private MyDao dao;
...
@Property
private List<Entry> entries;
...
void onPrepareForRender() {
...
this.entries = this.dao.getAll()
...
}
...
}
例如,我想将MyDao dao
替换为提供相同功能的OSGi服务,以便我可以在onPrepareForRender
方法中使用它。
我可以放心地认为与该服务关联的OSGi包已经在运行。
其余的应用程序是作为一个OSGi应用程序。 我在我的pom.xml中添加/更改了一些东西(maven-bundle-plugin,添加了一些清单条目,如http://www.javabeat.net/2011/11/writing-an-osgi-web-application/ )。
但是,它仍然不起作用。
我试图将我的WAR转换为WAB,顺便说一句。
先谢谢你 :)
编辑:转换和从WAR部署到WAB时出现问题
当我打包我的网络应用程序时, war
东西工作正常。 但是,当我将它打包为bundle
并尝试在GlassFish中进行部署时,出现以下错误消息:
部署期间发生错误:没有安装的容器能够处理此应用程序admin-war。 有关更多详细信息,请参阅server.log。
当我去server.log时,它的内容如下:
[#|2013-08-27T17:11:57.600+0200|INFO|glassfish3.1.2|org.glassfish.admingui|_ThreadID=28;_ThreadName=Thread-2;|uploadFileName=admin-war-2.01-SNAPSHOT.jar|#]
[#|2013-08-27T17:11:57.920+0200|WARNING|glassfish3.1.2|javax.enterprise.system.tools.deployment.com.sun.enterprise.deploy.shared|_ThreadID=29;_ThreadName=Thread-2;|DPL8031: Ignoring WEB-INF/ because the containing archive C:glassfish3glassfishdomainsdomain1applicationsadmin-war recorded it as a pre-existing stale file|#]
[#|2013-08-27T17:11:57.939+0200|WARNING|glassfish3.1.2|javax.enterprise.system.tools.deployment.com.sun.enterprise.deploy.shared|_ThreadID=33;_ThreadName=Thread-2;|DPL8031: Ignoring WEB-INF/ because the containing archive C:glassfish3glassfishdomainsdomain1applicationsadmin-war recorded it as a pre-existing stale file|#]
[#|2013-08-27T17:11:57.972+0200|WARNING|glassfish3.1.2|javax.enterprise.system.tools.deployment.com.sun.enterprise.deploy.shared|_ThreadID=29;_ThreadName=Thread-2;|DPL8031: Ignoring WEB-INF/ because the containing archive C:glassfish3glassfishdomainsdomain1applicationsadmin-war recorded it as a pre-existing stale file|#]
[#|2013-08-27T17:11:57.973+0200|WARNING|glassfish3.1.2|javax.enterprise.system.tools.deployment.com.sun.enterprise.deploy.shared|_ThreadID=29;_ThreadName=Thread-2;|DPL8031: Ignoring WEB-INF/ because the containing archive C:glassfish3glassfishdomainsdomain1applicationsadmin-war recorded it as a pre-existing stale file|#]
[#|2013-08-27T17:11:57.974+0200|WARNING|glassfish3.1.2|javax.enterprise.system.tools.deployment.com.sun.enterprise.deploy.shared|_ThreadID=29;_ThreadName=Thread-2;|DPL8031: Ignoring WEB-INF/ because the containing archive C:glassfish3glassfishdomainsdomain1applicationsadmin-war recorded it as a pre-existing stale file|#]
[#|2013-08-27T17:11:57.990+0200|WARNING|glassfish3.1.2|javax.enterprise.system.tools.deployment.com.sun.enterprise.deploy.shared|_ThreadID=29;_ThreadName=Thread-2;|DPL8031: Ignoring WEB-INF/ because the containing archive C:glassfish3glassfishdomainsdomain1applicationsadmin-war recorded it as a pre-existing stale file|#]
[#|2013-08-27T17:11:57.991+0200|WARNING|glassfish3.1.2|javax.enterprise.system.tools.deployment.com.sun.enterprise.deploy.shared|_ThreadID=29;_ThreadName=Thread-2;|DPL8031: Ignoring WEB-INF/ because the containing archive C:glassfish3glassfishdomainsdomain1applicationsadmin-war recorded it as a pre-existing stale file|#]
[#|2013-08-27T17:11:58.006+0200|WARNING|glassfish3.1.2|javax.enterprise.system.tools.deployment.com.sun.enterprise.deploy.shared|_ThreadID=29;_ThreadName=Thread-2;|DPL8031: Ignoring WEB-INF/ because the containing archive C:glassfish3glassfishdomainsdomain1applicationsadmin-war recorded it as a pre-existing stale file|#]
[#|2013-08-27T17:11:58.008+0200|WARNING|glassfish3.1.2|javax.enterprise.system.tools.deployment.com.sun.enterprise.deploy.shared|_ThreadID=29;_ThreadName=Thread-2;|DPL8031: Ignoring WEB-INF/ because the containing archive C:glassfish3glassfishdomainsdomain1applicationsadmin-war recorded it as a pre-existing stale file|#]
[#|2013-08-27T17:11:58.008+0200|WARNING|glassfish3.1.2|javax.enterprise.system.tools.deployment.com.sun.enterprise.deploy.shared|_ThreadID=29;_ThreadName=Thread-2;|DPL8031: Ignoring WEB-INF/ because the containing archive C:glassfish3glassfishdomainsdomain1applicationsadmin-war recorded it as a pre-existing stale file|#]
[#|2013-08-27T17:11:58.024+0200|WARNING|glassfish3.1.2|javax.enterprise.system.tools.deployment.com.sun.enterprise.deploy.shared|_ThreadID=29;_ThreadName=Thread-2;|DPL8031: Ignoring WEB-INF/ because the containing archive C:glassfish3glassfishdomainsdomain1applicationsadmin-war recorded it as a pre-existing stale file|#]
[#|2013-08-27T17:11:58.025+0200|WARNING|glassfish3.1.2|javax.enterprise.system.tools.deployment.com.sun.enterprise.deploy.shared|_ThreadID=29;_ThreadName=Thread-2;|DPL8031: Ignoring WEB-INF/ because the containing archive C:glassfish3glassfishdomainsdomain1applicationsadmin-war recorded it as a pre-existing stale file|#]
[#|2013-08-27T17:11:58.026+0200|SEVERE|glassfish3.1.2|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=29;_ThreadName=Thread-2;|Module type not recognized for module C:glassfish3glassfishdomainsdomain1applicationsadmin-war|#]
[#|2013-08-27T17:11:58.026+0200|SEVERE|glassfish3.1.2|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=29;_ThreadName=Thread-2;|There is no installed container capable of handling this application admin-war|#]
[#|2013-08-27T17:11:58.087+0200|INFO|glassfish3.1.2|org.glassfish.admingui|_ThreadID=28;_ThreadName=Thread-2;|Exception Occurred :Error occurred during deployment: There is no installed container capable of handling this application admin-war. Please see server.log for more details.|#]
我并不熟悉OSGI,但是您需要在AppModule中使用build *方法来提供DAO。 在我下面的例子中,我假定OsgiBundle是一种访问OSGI服务的方式,我不知道实际的OSGI类是什么。
例如:
public class MyAppModule {
public void contributeApplicationDefaults(MappedConfiguration<String, String> config) {
config.add("osgi.path", "path/to/osgi.xml");
}
public OsgiBundle buildOsgiBundle(@Symbol("osgi.path") String osgiPath) {
// lookup the OSGI bundle somehow
}
public MyDao buildMyDao(OsgiBundle osgiBundle) {
return osgiBundle.getService(MyDao.class);
}
public SomeOtherDao buildSomeOtherDao(OsgiBundle osgiBundle) {
return osgiBundle.getService(SomeOtherDao.class);
}
}
如果你想要更深层次的整合(例如自动发布所有OSGI服务作为Tapestry IOC服务),那么看一下TapestrySpringFilter,它将所有Spring bean发布为Tapestry IOC服务。
链接地址: http://www.djcxy.com/p/74725.html