Different log files for Grails applications deployed within one servlet container - grails

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.

Related

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

Grails application in openshift

I am trying to deploy my grails application on an openshift server. I have created an instance using command "rhc app create MyApp jbossews-2.0". When I ssh to the server, I see a jboss folder but no tomcat folder. How can I deploy my .war file onto the server?
I think the Docs on how to deploy a binary file will help you with this, however what the docs do not say is that with Tomcat the deployments directory is called webapps but they work the same way (except for the marker files, tomcat does not use those).
You may want to check out https://github.com/gssOpenShiftsupportExamples/JavaSample as it shows an example of how to do this with JBoss (the same thing will work for Tomcat if you change the directory as denoted above).

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

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.

Configure different versions of the same Grails application

By default Grails uses the following locations to look for config files:
"classpath:${appName}-config.properties",
"classpath:${appName}-config.groovy",
"file:${userHome}/.grails/${appName}-config.properties",
"file:${userHome}/.grails/${appName}-config.groovy"
But this leads to conflicts if two (or more) versions of the same application (with the same app name) are runing in the same servlet container. I need this for testing.
How can I use different config files for two Grails applications with the same name in the same servlet container?
Maybe by Externalize Your Grails Configuration.
Here is a good link : externalize grails configuration
I hope this help.

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