OSGi in embedded mode exposing jars which are present in main application - struts2

I have one struts2 application which is running Apache Felix OSGi in embedded mode. Is it possible to expose jar files in main webapp to the OSGi bundles? Otherwise I will have to deploy same jar file twice once include in webapp classpath for the main application and once more deployed as bundle inside embedded Felix OSGi container.

Yes. You can certainly do this. But, there are known issues with embedding an OSGi container within a webapp. The arise from the fact that the classloader context of the webapp is non-standard. I've been working with an app that does exactly the same thing. If I was able to write the app from scratch, I would NOT do it this way. I would, instead, deploy Struts2 as an OSGi bundle itself, along with everything else. In other words, I'd embrace the OSGi modularized runtime completely.
With that being said, the OSGi container is itself a bundle and can export packages just like any bundle. It's known as the "system bundle" and you can specify packages from the "host" application's classloader as packages to export into the OSGi container via the system bundle.
See the example on this page, and search for this configuration parameter.
Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA
This config parameter contains a list of packages from the host app's classloader that should be available to your osgi bundles.
As for the "issues", see these links as a start:
A good description of the embedded in a webapp dangers.
Specifics about classloader issues.

Related

Deploy resource adapter and application in websphere liberty image

I have a requirement to create a spring boot application and connect it to EIS via dtpraUnisys JCA adapter. the flow is
Application -> ADapter RAR -> EIS
I want to use the websphere liberty image and then bundle the rar and the application jar file
Where should I give the rar file location, application jar file details.
is there any example which I can refer based on docker image
I don't know of anything official, but I did go through something similar (but with Java EE instead of Spring Boot) with IBM MQ on my Github.
The basic idea is that you typically place resource adapters and other shared in /opt/ol/wlp/usr/shared/resources/ for Open Liberty or /opt/ibm/wlp/usr/shared/resources for WebSphere Liberty. I do that in my Dockerfile:
RUN mkdir /opt/ol/wlp/usr/shared/resources/wmq/ && chown -R 1001:0 /opt/ol/wlp/usr/shared/resources/wmq/
COPY --chown=1001:0 docker/wmq.jmsra.rar /opt/ol/wlp/usr/shared/resources/wmq/
Then you reference them in server.xml, using the shared.resource.dir variable:
<resourceAdapter id="mqJmsRa" location="${shared.resource.dir}/wmq/wmq.jmsra.rar">
<classloader apiTypeVisibility="spec, ibm-api, api, third-party"/>
</resourceAdapter>
From there, you might have to create some config items. I'm not sure what EIS needs, but the entire server.xml syntax is documented on the Open Liberty website (this applies to WebSphere Liberty, too) so you can find what you need. You'll usually need to reference your resource adapter to set properties on it using the properties.<adaptorName> element.
This works for any type of application on Liberty. Deploying the spring boot app might require some extra steps. There's a good guide to deploy a spring boot app on Liberty in Docker on the Open Liberty guides site.

Springboot running on Docker unable to read files from resources

I have a springboot project with default structure. I have an excel file under resources/data. My program need to load excel file and dump data into different tables from each sheet.
When I run from Eclipse, program loads excel file correctly and everything looks good. However, when I deploy the same App on Docker, it fails to read the File from resources.
Have anyone encountered this issues? How have you solved it?
First of all try to check whether the Docker is a reason, or there is an issue with java code. Spring boot creates an artifact that can be run with just java -jar <your-spring-boot-artifact.jar>
If this doesn't run even without docker, then you should change the way you access Excel files from spring boot application (your java code):
if the file is in resources folder, it should be packaged into the spring boot artifact.
In this case, you have to use getClass().getResourceAsStream() to access the file, and not rely on java.io.File API, because File API doesn't allow working with files inside a Jar, its not a regular filesystem.

How to integrate moskito-java (monitoring-tool) into a grails application?

I would like to use moskito monitoring within my grails 2.3.9 application.
I already added the dependencies for moskito and the webui into BuildConfig.groovy
compile 'net.anotheria:moskito-core:2.4.2'
compile 'net.anotheria:moskito-aop:2.4.2'
runtime 'net.anotheria:moskito-webui:2.4.2'
runtime 'net.anotheria:moskito-web:2.4.2'
runtime 'net.anotheria:moskito-webui-jersey:2.4.2'
I also marked the classes i want to monitor with the #Monitor annotation.
Now i need to get access to the moskito-webui. I need to add a servlet filter to the web.xml of the grails application (regarding to the documentation). I just installed the grails templates with grails install-templates and modified the web.xml file but i can't get access to the webui of moskito.
Does somebody know how to create an urlmapping or servlet filter for moskito webui within grails? How to integrate it correctly?
if you upgrade to 2.5.0 you don't need an embedded webui, instead you can use a standalone tool called MoSKito Inspect (actually same as WebUI, nicer name).
First add
moskito-inspect-remote
to your dependencies. This jar includes a web-fragment that starts a local listener on RMI port 9041 (port can be altered later).
Second: Download or build your own MoSKito Inspect (take tomcat7 and drop in http://search.maven.org/remotecontent?filepath=net/anotheria/moskito-inspect-standalone/2.5.0/moskito-inspect-standalone-2.5.0.war or build from github source).
Download link is:
http://www.moskito.org/download.html
Third: start your application and MoSKito Inspect. Enter in quickconnect localhost and port 9401. You should see your annotated classes now.
If you have further problems you can also use moskito mailing list: moskito-users#lists.anotheria.net
regards
Leon

Different log files for Grails applications deployed within one servlet container

I have 2 grails applications packed with --nojars parameter in grails war command. All grails framework libraries are moved to server and they are loader in shared.loader line in tomcat servlet container.
My question is, how can I set different loggers for this different application.
Now log4j = {..} produce the static variable which is shared between two applications.
I'd like to have different logs for each one.
When deploying the war files produced by grails build command without --nojars everithing went well, and each application had its own log file.
Any suggestions ?
I think there should be two different web applications as well. If you do not want the duplicate libraries packaged again, just give them a 'provided' scope and make sure they are available in your instance of Tomcat.

New URLStreamHandlers in glassfish

I have a legacy application that I'm trying to port to Java EE. Presently this application calls URL.setURLStreamHandlerFactory() to register some custom URL protocol handlers. This call fails under Glassfish v 2.1 and 3 because glassfish has already registered a factory.
I've tried using the java.protocol.handler.pkgs system property, but that doesn't work for me due to classloader issues. The handler classes are all part of the application and I'm not keen on trying to extract them and put a jar in the container's classpath.
I've got a whiff of osgi bundles - apparently I could write a Bundle that'll deal with the new protocols. I'm not keen on making this web application an osgi bundle (one step at a time! EE first, then osgi if the need arises).
Is it possible to pop a bundle jar in to my WEB-INF/lib directory and have Glassfish load it as a bundle? The bundle will need to import packages from the web applications (another jar in WEB-INF/lib or in WEB-INF/classes). I'm willing to package this app as an EAR if that'll work, I just can't justify osgifying the entire application without knowing more.
I've solved my issue. Apparently I had some wires crossed as the java.protocol.handler.pkgs system property works fine.
For any one else tripping up, I put a jar with my handlers in $DOMAINDIR/lib/ext/ as well as in my WAR's WEB-INF/lib directory. In my application's configuration I've also put a jvm option -Djava.protocol.handler.pkgs=my.handlers.pkg.prefix
I've noticed in glassfish 2.1 it works without the jvm option if I put the prefix in to some startup code, but in glassfish 3 the jvm option is necessary because felix (the osgi implementation glassfish is using) only consults the property upon the server startup, not for each request.

Resources