如何在Tapestry中使用OSGi服务



我有一个Tapestry web应用程序,它为一些数据集提供了完整的CRUD功能。到目前为止,我一直在使用mock来开发和测试它

然而,我现在需要用OSGi服务(与Felix一起运行)来替换mock。

我的主要问题是:

  1. 我需要将OSGi服务注入到我的挂毯应用程序中吗?如果需要,该怎么做
  2. 假设它是注入的,有没有关于如何使用它的实践?我应该用什么特殊的方式来调用这些方法或类似的东西
  3. 在调用了我需要的方法后,我需要对它做些什么吗?还是自动完成
  4. 我需要担心HttpService吗(我看了一些关于它的抱怨,但不太明白)

为了给你提供一些上下文,我现在是这样做的

public class MyPage {
    ...
    @Inject
    private MyDao dao;
    ...
    @Property
    private List<Entry> entries;
    ...
    void onPrepareForRender() {
        ...
        this.entries = this.dao.getAll()
        ...
    }
    ...
}

我想用一个提供相同功能的OSGi服务来代替MyDao dao,这样我就可以在onPrepareForRender方法中使用它了。

我可以放心地假设,与该服务相关联的OSGi捆绑包已经在运行。

应用程序的其余部分是作为OSGi应用程序制作的。我在pom.xml中添加/更改了一些内容(maven bundle插件,按照中的说明添加了一些清单条目http://www.javabeat.net/2011/11/writing-an-osgi-web-application/)。

然而,它仍然不起作用。

顺便说一句,我正试图将我的WAR转换为WAB。

提前感谢:)

编辑:从WAR转换和部署到WAB时出现问题

当我将我的网络应用程序打包为war时,它运行良好。然而,当我将其打包为bundle,并尝试在GlassFish中部署它时,我会收到以下错误消息:

部署期间出错:没有安装容器能够处理这个应用程序管理战争。请参阅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,它将所有springbean发布为Tapeistry IOC服务。

相关内容

  • 没有找到相关文章

最新更新