Interacting Non osgi with osgi bundles - struts2

I am using struts2 for my web application and i want to use osgi architecture for service and dao layer. Now I dont want to wrap my struts2 actions as osgi bundles but want service and dao layer to be packaged as bundles. Now can anybody tell me how my non osgi actions can consume osgi bundles(service and dao layer). And I want to deploy my struts2 web application in web container so how web container will interact with osgi container(where my service and dao is deployed) in this case . Please help .

You need a so called 'bridge' between your web container and your OSGi environment.
Both Felix and Equinox have that capability, but for me the Felix implementation worked much better.
What you basically want to do is:
Add a context listener to your ServletContext
Starting OSGi when starting the ServletContext, stop it when the ServletContext gets destroyed.
Pass the ServletContext to the OSGi context by registering it as a service
Store the OSGi framework object in the ServletContext by registering it as an attribute.
So to access the web context from OSGi: Retrieve the ServletContext service, and go from there.
To access OSGi from the webcontext: Retrieve the OSGi framework from the ServletContext attribute and go from there.
Check the Felix Documentation, also I've made an example a while back on GitHub

Most surely this will not work. Why do you think it should be a good idea to move half of your application to OSGi? Either you should move all of it or none.
You may be able to deploy the struts layer in a war file and a access the OSGi services from it. I think this is possible in Virgo and Apache Karaf. It means to enhance the war with OSGi structures. For example in Karaf you can use a wab file which is a war file with a Manifest.

Related

Grails: Register job from external library

I need to separate a grails service into a dedicated lilbrary in order to use this service across many applications. This works fine for the service itself as I am able to register the service bean in the resources.groovy (see https://docs.grails.org/latest/guide/spring.html).
This service happens to use a quartz job to get some functionality triggered regularly. So naturally I would move this job into the library and need to register it in the main application.
How can that be achieved? Thanks for you time!
Create grails plugin using this guide:
https://docs.grails.org/latest/guide/plugins.html
Then in src/main/groovy/YOUR_PACKAGE/YourPluginGrailsPlugin.groovy you can add bean configuration in doWithSpring() method (in same as resources.groovy way).

Embedded Jetty web app context/holders serving from two resource bases with one web.xml (spring secuity)

I have an existing application which is using the embedded jetty. Right now jetty has only one WebappContext and serving the files from a directory and also it has web.xml (which has spring security configuration in it)
Now I need to serve some static files using a new war.
What is the easy way to configure existing webappcontext to add a new resource base?
If I add new webappcontext how I can tell jetty to use existing web.xml and spring security?
The serving of static files is just the role of the DefaultServlet
See prior answer about that ...
https://stackoverflow.com/a/20223103/775715
As for the existing web.xml and spring security question, the WebAppContext's are, by design, and by the nature of the servlet spec, isolated from each other.
If you want a single spring security configuration that applies for both webapps, you'll need to setup/install CAS.

How do i build and application that works as both OSGI bundles and a WAR

I am developing and application as a series of OSGI bundles which will run on Karaf.
The Bundles has a fair bit of interoperability, both exposing a bunch of services, and consuming services from each other.
However, I would very much like to be able to build a WAR file of the application alongside the bundles. There are a few clients that quite simply won't allow an OSGI container on their servers.
So my question is, what is the best way to separate the OSGI service logic from the application logic? The activators are no trouble, as they are just unused in the WAR deployment, but i have a lot of calls that retrives services from the bundlecontext, like bundleContext.getServiceReference(stuffISortOfNeed.class)scattered around my code. bundleContext is currently a static object set by the activator.
This won't do in a WAR container that knows nothing of OSGI.
Is it possible to somehow hide the BundleContext and the getServiceReference calls away from the actual application? Preferably i would love an injection-like approach where i could define my services with #Annotations and define and injector for OSGI and one for PlainOldJava.
To really have POJOs you could use Blueprint XML to register your Web Application Bundle (WAB).
A good example can be found in the pax web project.
By using XML over annotations you only have an extra resource file that can be ignored if you assemble you bundles as libs in a war file, no extra dependencies on specific annotations.

JSF2 with EJB3 and JPA - how best to package

I'm trying to teach myself a bit about EJB3 and JPA by creating some functionality that uses JSF2 as a front end, stateless EJB3 session beans to handle transactions and JPA to persist entities.
Ideally I'd like the EJB app to be on a remote server, and the JSF2 war file on a separate server and communicate remotely - thus simulating a distributed project. But I'd like them to share the same JPA entity classes (as it seems kind of pointless converting them into other DTO objects just for front-end use - so it makes sense to me if the JPA project is in a project of its own
What I'm having trouble understanding is how to best package and deploy the various components.
Would it be best to deploy:
1) on server one: an EAR file containing the JPA jar file and the EJB module on one server. But if I do this where should the persistence.xml file be located - in the jpa jar file or in the ejb module?
and
2) on server two: a war file with the JSF application and the JPA jar file in the WEB-INF lib of this war. In this case, I assume the EJB interfaces will also need to be externalized into a jar file and included in the web-inf/lib?
or am I thinking in completely the wrong way?
Would appreciate any thoughts on what the best practices should be to achieve what I'm trying to do? Apologies in advance if I'm doing it all wrong...it's a learning experience!
First JPA objects are managed by persistence context hence i dont recommend to pass around that object to web layer. You may use JAXB objects to be sent to your web layer. JPA entity objects should be read and set to JAXB object fields and return the same.
Its faster and easier than pojo mapping frameworks.

Is it possible to add Grails MVC classes at deployment time?

I'm writing a Grails app which I'd like 3rd parties to augment at runtime. Ideally they would be able to add a JAR/WAR to the webapp directory which contains new domain, controller and service classes, new views, and other content.
Is there a simple way to do this within grails? Would it be simplest to create a startup script which copies the new classes etc. into the relevant directories and then updates grails.xml and web.xml?
You will be able to do this in version 2 of grails in which plugins will be also OSGI plugins http://jira.codehaus.org/browse/GRAILS/fixforversion/15421
It seems that the Grails plugins will actually fit quite well for this: http://www.grails.org/Understanding+Plugins
A plugin can do just about anything... One thing a plugin cannot do though is modify the web-app/WEB-INF/web.xml or web-app/WEB-INF/applicationContext.xml files. A plugin can participate in web.xml generation, but not modify the file or provide a replacement. A plugin can NEVER change the applicationContext.xml file, but can provide runtime bean definitions

Resources