difference between WAB and WAR - osgi

I am a newbie to this and read about WABs , but wish to clear the basic difference -
I mean using osgi embedded in tomcat and making a WAR vs making a WAB ?
When should one consider each option ?
1) OSGI embedded in tomcat
2) tomcat in OSGI
3) using a WAB

OSGi embedded in a container (not only Tomcat!) is likely the only option when you are forced to a traditional JavaEE WAR deployment model, i.e. an IT department operates the container and you can only deloy WAR files to it. This bootstraps a whole OSGi framework within the web application and allows modular development within the web application. The web application is then composed as a set of OSGi bundles. It can also be used to migrate/transfer an existing legacy web application into OSGi modules. However, this will be challenging.
I'd like to call the second approach (Tomcat in OSGi) as a pure OSGi approach. Tomcat or any other Servlet container (eg., Jetty) can be deployed as a bundle (or a set of bundles) in an OSGi framework. The OSGi framework is the container. You don't have the full separation of a web application anymore. The can intersect. Some bundles/modules may implement web functionality and others may not. Core functionality (core bundles) can be reused by other web bundles.
The third option is a result of new spec work in OSGi. Basically, it's a web application with an OSGi bundle manifest. Thus, the whole web application can be deployed as a single OSGi bundle on any framework with WAB support. Technically, the bundle may be deployed as a web application to a Servlet container. But it gets access to a BundleContext. This allows the web application to inter-operate with other bundles or web applications running in the same framework.

Related

Vaadin + Spring Boot + Osgi

Does some one already managed to setup a Vaadin (19 to 21) Web application using Spring Boot and Osgi (as bundle) ?
I've managed to have a Vaadin application running under Osgi container (Karaf).
I've managed to have a Spring Boot Application running under Osgi container (Karaf).
But not both at the same time.
In fact, when trying, no route are being registered and FixedVaadinServlet is never called.
Thanks for help.
I have to say that I don't exactly understand your question since Spring is not OSGi compatible (it just has no OSGi manifest) so I don't see how it may work at all.
Now I'm going to guess....
I've managed to have a Vaadin application running under Osgi container (Karaf).
So your application is built as an OSGi bundle and you have deployed it to Karaf (OSGI container) and it works.
I've managed to have a Spring Boot Application running under Osgi container (Karaf).
You have built something (either WAR or a Spring boot Jar) which is a Web application and you have deployed it to Karaf AS A WEB Application.
This feature provided by Karaf : it's not pure OSGi container. It allows to deploy WEB applications to it.
These Web Applications have no any relation to OSGi.
So you have no Spring application which works in OSGi: if you use another OSGi container (which doesn't support extra features like Web app deployment) then you won't be able to use Spring there since as I said Spring is not OSGi compatible.
So I don't see how it's possible to use Spring + OSGi at all.

Spring Boot App - Reference external code during runtime that isn't part of the bundled WAR?

I have a Spring Boot+React application that is packaged as a bundled WAR.
This works well for most cases, but we need to be able to drop-in functionality in some cases that is not part of the bundle (such as via a JAR).
I knew OSGI exists for this case, but not sure of any usage with Spring Boot. Is there another way to do this as well?
If your use case is a kind of small plugin functionality for your spring boot app then you could start an OSGi framework inside spring boot and load bundles from a separate directory. You plugins could then offer their service via an interface that is provided by the spring boot app and an OSGi service with that interface.
You need some good OSGi knowledge for this to work.

Does spring boot needs a WAS (Websphere Application Server)?

In my theory spring boot is capable of running java web application stand-alone. It says it has a own embedded servlet container and can use JNDI itself.
I built a war file before (spring-mvc, security, gradle built), but Spring boot assemble jar file and it runs on any machine which has JVM.
So my question is, if I made a spring boot based web app (contained JSP files & JNDI for looking up datasource), although it has own embedded servlet container and packaged jar file for running standalone, do I still need to package it as WAR file and deploy it in WAS (Websphere Application Server) or servlet containers for any reasons such as performance, stability, scaling-out etc?
WAS is an full blown Java Enterprise Application Server, on the other hand you have Spring that only requires a Servlet Container (Servlets are a part of full JEE).
Servlet Containers are for example: Tomcat, Jetty, but also WAS.
Spring Boot is able to package the complete application TOGETHER with the code of Tomcat in an JAR, so that this jar contains the Servlet Container and your Application.
Do I need a additional WAS for performance, stability, scaling-out etc?
Performance: No - There should be no important performance differerence between Tomcat and WAS when you run a Spring-Application. (Only that Tomcat needs less memory for itsself)
Stability: Tomcat and WAS are both very mature products.
Scaling: You can build a cluster of Tomcats by your own.
The main features of WAS over Tomcat are:
- WAS supports EJB and CDI (Tomcat would need TomEE for this), but Spring will not use it, because it is its one Dependency Injection container
- WAS has more Monitoring features, but this does not matter, because Spring Boot has Actuator
#See Difference between an application server and a servlet container? for more details
Simple answer is No. You do not need any Full blown application servers for any of the reasons that you mentioned (for performance, stability, scaling-out). You can just do fine with tomcat
Edit
Looks like you are using only JNDI feature from the Application server. Do you really need JNDI when you pack your servlet container along with your application ? I don't think so. That days are long gone.
JNDI really shines when you have to move an application between
environments: development to integration to test to production. If you
configure each app server to use the same JNDI name, you can have
different databases in each environment and not have to change your
code. You just pick up the WAR file and drop it in the new
environment.https://stackoverflow.com/a/7760768/6785908
(If you still need JNDI to be used to look up your data source refer: https://stackoverflow.com/a/24944671/6785908).
No, still I do not really see a reason for packaging your application as WAR and deploy it to traditional application server. That being said, if you have some existing infrastructure lying around and you are being forced to deploy to existing WAS (or WebLogic or JBoss any application server for that matter) server, then I rest my case :).

Can OSGi components be deployed in any Servlet containers?

Can OSGi components be deployed to any Container like Tomcat/Websphere/JBoss..etc ? (just as we deploy a WAR file) or do they require any special libraries or OSGi containers to run the OSGi components ?
If you want just expose the "component" classes, you can treat the jar files as .. jar files.
If you consider the OSGi "component" as a "bundle" exposing some services and doing something, then answer is "no". You need an OSGi container (Karaf, WebSphere Liberty, Carbon, Glassfish, JBoss WildFly ...).
However - as you can see, some application servers provide OSGi support natively.
OSGi components (I guess you mean bundles) require an OSGi framework to run in. So a plain servlet container will not work. Some versions of JBoss provide support for OSGi though.

Spring Web Service accessing Osgi bundles deployed in Tomcat

I have been tasked with looking at redesigning our current web service.
As a lot of the development of our main/legacy products was done using OSGi, we currently have a web service which is developed using osgi bundles and deployed using Talend.
Some of our newer products are being developed around Spring/Maven/Tomcat so I have been asked to investigate moving our web service to this technology stack.
What is required is a Spring contract first Web Service which can access the main business code, which will still be in its OSGi bundles, all packaged neatly in a war
to be deployed in Tomcat.
Is this possible?
Most pages I have seen seem to be pointing at using Virgo but our hope was to cut down on the technologies used, not to add others

Resources