如何在Tapestry中使用OSGi服务

时间:2013-08-23 09:16:12

标签: web-applications osgi tapestry osgi-bundle wab

我的Tapestry Web应用程序为某些数据集提供完整的CRUD功能。 到目前为止,我一直在使用模拟器来开发和测试它。

但是,我现在需要用OSGi服务替换该模拟(与Felix一起运行)。

我的主要问题是:

  1. 我是否需要将OSGi服务注入我的tapestry应用程序,若然,该怎么办?
  2. 假设它被注射,是否有任何关于如何使用它的做法?我应该用什么特殊的方法来调用方法或类似的东西?
  3. 在我调用了我需要的方法后,是否需要对它进行一些操作,还是自动完成?
  4. 我是否需要担心HttpService(我看了一些关于它的抱怨,但对它不太了解)
  5. 为了向您提供一些背景信息,这就是我现在正在做的事情

    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-plugin,按照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:\glassfish3\glassfish\domains\domain1\applications\admin-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:\glassfish3\glassfish\domains\domain1\applications\admin-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:\glassfish3\glassfish\domains\domain1\applications\admin-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:\glassfish3\glassfish\domains\domain1\applications\admin-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:\glassfish3\glassfish\domains\domain1\applications\admin-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:\glassfish3\glassfish\domains\domain1\applications\admin-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:\glassfish3\glassfish\domains\domain1\applications\admin-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:\glassfish3\glassfish\domains\domain1\applications\admin-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:\glassfish3\glassfish\domains\domain1\applications\admin-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:\glassfish3\glassfish\domains\domain1\applications\admin-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:\glassfish3\glassfish\domains\domain1\applications\admin-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:\glassfish3\glassfish\domains\domain1\applications\admin-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:\glassfish3\glassfish\domains\domain1\applications\admin-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.|#]
    

1 个答案:

答案 0 :(得分:2)

我对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服务。