How to log exceptions from a specific package deployed in tomcat - exception

I'm forced to use custom closed source lib in my web app deployed in tomcat 6. It is logging a lot of exceptions in my stdout log (catalina.out) via printStackTrace and then rethrowing them for me to handle. Is there a way to prevent or reroute logging of exceptions from a specific package deployed in webapp?

e.printStackTrace prints to the console similar to System.err
In Tomcat, the catalina.sh has this line which redirects all console errors to catalina.out
This applies for the Tomcat server as a whole.
"$CATALINA_BASE"/logs/catalina.out 2>&1 &
So in short, if you cant tinker with the source code to use log4j, you could try sending this to another file within the catalina.sh, but again this would not be package specific as you want.
And this would just bloat another file in a similar manner.

How about calling that segment within a try/catch segment, thus catching the exception before your app dies, adding it to log4j (or any other logging mechanism)

Related

Google cloud - Stackdriver debug reports "File was not found in the executable" for GCE Jetty war

I've been trying to follow the
Setting Up Stackdriver Debugger for Java applications on Google Compute Engine, but am running into issues with Stackdriver Debug.
I'm building my .war file from a separate build server, then deploying it to my GCE server. I added the agent to the start command via /etc/defaults, and my app appears in the https://console.cloud.google.com/debug control panel. The version I set in the run command matches the revision that shows up in the source-context(s).json files.
However when I click open the app, I see the message that
No source version information was provided by the deployed application
I connected the app's git repo as a mirrored cloud repository, and can browse the source files in the sidebar of the Stackdriver Debug page. But, If I browse to a file and add a breakpoint I get an error that the error "File was not found in the executable."
I have ran the gcloud preview app gen-repo-info-file command, which created two basic json files storing my git repo and revision. Is it supposed to do anything else?
I have tried running jetty using both normal and extracted modes. If I have jetty first extract the war file, I can see the source-context.json filesin the WEB-INF/classes directory.
What am I missing?
https://github.com/GoogleCloudPlatform/cloud-debug-java#extra-classpath mentions
you can update the agentPath showing your WEB-INF/class directory.
-agentpath:/opt/cdbg/cdbg_java_agent.so=--cdbg_extra_class_path=/opt/tomcat/webapps/myapp/WEB-INF/classes
For multiple class paths:
-agentpath:/opt/cdbg/cdbg_java_agent.so=--cdbg_extra_class_path=/opt/tomcat/webapps/myapp/WEB-INF/classes:/another/path/with/classes
There are a couple of things going on here.
First, it sounds like you are doing the correct thing with gen-repo-info-file. The debugger agent should pick up the json files from the WEB-INF/classes directory.
The debugger uses fuzzy matching to find source files, so as long as the name of the .java file matches a file in your executable, you should not get that error.
The most likely scenario given the information in your question is that you are attaching the debugger to a launcher process, rather than your actual application. Without further details, I can't absolutely confirm that, though.
If you send us more details at cdbg-feedback#google.com, we can look more closely at your case to see if we can understand exactly what's happening, and potentially improve our documentation, since it sounds like you followed the docs pretty closely.

Using Cobertura for Junit testing webapp deployed on WebSphere Liberty Profile

I have been trying to generate code coverage for my web application using Cobertura and Junit but am running into problems. My webapp is a Java web application deployed on WebSphere Liberty Profile. I have followed the steps mentioned here: https://github.com/cobertura/cobertura/wiki/FAQ#using-cobertura-with-a-web-application
My steps are as follows:
Instrument classes using cobertura-instrument ant task.
Put cobertura.jar in the lib folder of my webapp (so that it is on the classpath)
Start Liberty
Run Junits (JUnit runs in a separate JVM other than the Liberty JVM)
The problem is that, cobertura.ser file is not generated when I stop liberty. I have tried the "hack" mentioned here:
https://github.com/cobertura/cobertura/wiki/FAQ#using-cobertura-with-a-web-application
It seemed to work (I actually got some coverage info), but I was seeing that the cobertura.ser file was repeatedly being initialized to zero size and then the size increased to some number, so I am a little hesitant to use this. Moreover, this requires change in the code itself, and depends on the logout code being called, which is not quite ideal for automation.
But I am more interested in a setting for Websphere Liberty such as the one described for JBoss
-Djboss.shutdown.forceHalt=false
In particular, a jvm setting that would allow Cobertura to detect the JVM shutdown hook called by Liberty profile. Is there such a setting for WebSphere/Liberty?
The liberty profile doesn't ever call Runtime.halt so all shutdown hooks should be called appropriately. I thought I'd take a look to reproduce and I think I managed to get it working (I say I think because none of the command line scripts worked so I may still have done something wrong)
Wrote a simple servlet war
Downloaded cobertura and put the cobertura-2.1.1.jar and all the jars in the downloads lib folder into the WEB-INF/lib of my war
Ran the java InstrumentMain class to instrument the classes in WEB-INF/classes (choosing to overwrite them)
Started the server
Accessed the application
Shutdown the server
at the end I looked in the WEB-INF/classes and there was a cobertura.ser file that was 1480 bytes (i.e. non-zero.). When I ran the report tool on this it said I had no coverage, so I deleted the file and went back to reproduce. The cobertura.ser file in WEB-INF/classes wasn't generated. Instead I looked in the server working directory (in case it was there instead) and it wasn't. When I generated the report on this I got coverage.
So some possible things to look for:
Is this the corbertura.ser you are looking for? Look in the usr/servers/ folder to see if there is one there.
Did the instrumented classes end up in the app prior to or instead of the non-instrumented ones
Was the cobertura dependencies available.

ResourceConfig will be locked when adding extension module in Jersey

I am trying to build a jax-rs web service using Jersey2.8. When I put a jar like jersey-media-json-jackson-2.8.jar or jersey-media-moxy-2.8.jar under WEB-INF/lib folder, the exception "The resource configuration is not modifiable in this context" will occur on the browser.
Why this issue happens and how could i fix this?

Parsed Console Output Error in Hudson

im running Hudson continuous integration for db unit.
when i run the job the console output is displaying the SUCCESS, but then why do the Parsed Console Output keep returning this error:
ERROR:Failed to parse console log :
log-parser plugin ERROR: Cannot parse log: Can't read parsing rules file:
i already installed the parse-log plugin & i already restarted the Hudson..
i installed the plugin using remote PC
any help and suggestion is appreciated. Thanks!
1) Place the Parser Rule File in the JENKINS_HOME location.
2) Configure that log parser console output in the Global COnfiguration settings and Name it.
3) Add this option in the Post Build Actions and Select the Name
ok silly me..
i forgot to configure the global configuration in hudson that link to the parser rule file..
problem solved.
I'm posting this in case anyone else has a specific case of this problem. This issue started when upgrading from 1.509.2 to 1.554.3... I had the parsing rules file in the win\system folder which was a known issue when running Jenkins as a service. Well I guess they fixed it by this version. I moved the parsing rules back into Jenkins Home folder and it worked fine again.

Running applet from html page

I have made a simple Applet which simply invokes a ant target thorugh batch file on click of button. To do this i am using
ExecTask exec = new ExecTask();
exec.setExecutable("run.bat");
Commandline.Argument arg = exec.createArg();
arg.setValue("-buildfile D:/cloudengine/Applet/build.xml");
exec.execute();
When i run this from eclipse it works properly. But my requirement is to run this from a html page so i have created a simple html with applet tag
<APPLET ALIGN="CENTER" CODE="HtmlAntTest.class" WIDTH="800" HEIGHT="500"></APPLET>
But in browser's java console i get below exception on click of button
Exception in thread "AWT-EventQueue-2" java.lang.ExceptionInInitializerError
at org.apache.tools.ant.taskdefs.ExecTask.<init>(ExecTask.java:72)
.
.
.
Caused by: java.security.AccessControlException: access denied (java.util.PropertyPermission file.encoding read)
Any pointers would be of great help. Thanks in advance
You need to grant additional rights to the applet. It is all explained in detail here:
http://java.sun.com/developer/onlineTraining/Programming/JDCBook/appA.html
As das_weezul commented, the applet will require elevated privileges to do this. While changing policy files is one way to achieve that, it is error prone and impractical for deployment.
To get an applet trusted at time of deployment, it will be necessary to:
Put the classes in a Jar file (see Packaging Programs in JAR Files for details).
Digitally sign the Jar file (see Signing and Verifying JAR Files for details).
Get the end user to OK the code when prompted to trust it.
It takes a little time to set up code signing in a build file, but once done correctly it can be forgotten.