How to use OSGi services in Tapestry

I have my Tapestry web application that offers full CRUD functionality for some dataset. So far I have used mocks for development and testing.

However, I now need to replace this layout with the OSGi service (works with Felix).

My main questions / questions:

  • Do I need to embed the OSGi service in my tapestry app, and if so, how do I do this?
  • Assuming it is introduced, are there any methods for using it? Any special ways that I should call methods or something like that?
  • Do I need to do something with it after I call the methods that I need, or is this done automatically?
  • Do I need to worry about the HttpService (I looked at some complaints about this, but did not quite understand).

To provide you with some kind of context, here is how I do it now

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

I would like to replace MyDao dao with an OSGi service that provides the same functionality as I, for example, I can use it in the onPrepareForRender method.

I can safely assume that the OSGi package associated with the service will already be running.

The rest of the application runs as an OSGi application. I added / changed stuff in my pom.xml (maven-bundle-plugin, added some manifest entries, as stated in http://www.javabeat.net/2011/11/writing-an-osgi-web-application/ ) .

However, it still does not work.

I am trying to convert my WAR to WAB, by the way.

Thanks in advance:)

EDIT: Problem Converting and Deploying from WAR to WAB

When I pack my web application as war , everything works fine. However, when I pack it as a bundle and try to deploy it to GlassFish, I get the following error message:

Deployment error: there is no container installed capable of handling this admin-war application. See Server.log for more details.

When I switch to server.log, here is what it says:

 [#|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.|#] 
+4
source share
1 answer

I am not familiar with OSGI, but you will need to use the build * methods in your AppModule to provide the DAO. In my example below, I assumed that the OsgiBundle is a way to access OSGI services, I have no idea what the actual OSGI class is called.

eg:

 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); } } 

If you want deeper integration (i.e. automatically publish all OSGI services as IOC Tapestry services), take a look at TapestrySpringFilter, which publishes all spring beans as IOC Tapestry services.

+2
source

Source: https://habr.com/ru/post/1498559/


All Articles