简体   繁体   中英

Java Servlet throwing exception

We have developed a web based monitoring application for our Sybase servers and are having issues generating a graph using jfree in the production environment.

We usually build and test our application in a QA machine and then ftp the built *.war file to the production environment.

The issue arises in the production environment when the exact same piece of code fails to generate the graph in the production.

Below are the classes and packages we are importing:

package var;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.text.Format;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashSet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.axis.DateAxis;
import org.jfree.data.time.Minute;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.xy.XYDataset;
import java.sql.DriverManager;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.sql.*;
import javax.naming.*;
import org.jfree.ui.RectangleInsets;
import java.awt.GraphicsEnvironment;

Below is the snippet of code we believe to be throwing the error:

else
{
  int interval=Integer.parseInt(request.getParameter("interval").toString());
  System.out.println("I Before OS Level Object creation");
  OSLevel osl=new OSLevel();
  width=1500;
  height=500;
  XYDataset mdaDataSet=null;
  try
  {
  System.out.println("I Before XY Dataset generation");
  mdaDataSet=osl.generateXYDataSet(start, end, dval3, cpuval3, dsql3,interval);
  CategoryPlot plotmda = null;
  System.out.println("I Before Time Series generation");
  chartos = ChartFactory.createTimeSeriesChart(
          title, // chart title
          "Time", // domain axis label
          "CPU Usage Percentage", // range axis label
          mdaDataSet, // data
          true, // include legend
          true, // tooltips
          false // urls
          );
  System.out.println("The title is:"+title);
  }
  catch(Exception e)
  {
  System.out.println("I am in the Chart Generation TRY Block");
  e.printStackTrace();
  }

And finally the server.log entries in QA followed by in production:

the query is:SELECT CPUUsed,DateTime FROM bureau.bp_mda_cpu WHERE (DateTime > '2013-07-11' and DateTime < '2013-07-18') and ClientID='G123'
I Before OS Level Object creation
I Before XY Dataset generation
I Before Time Series generation
The title is:MITSUBISHI_GLOSS Sybase CPU(MDA CPU report)
The File Path is:/tmp/tmpChart148725123563269780.tmp
END of the report



the query is:SELECT CPUUsed,DateTime FROM bureau.bp_mda_cpu WHERE (DateTime > '2013-07-11' and DateTime < '2013-07-18') and ClientID='G123'
I Before OS Level Object creation
I Before XY Dataset generation
I Before Time Series generation
Jul 18, 2013 9:52:07 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet GenerateDBReport threw exception
javax.servlet.ServletException: Servlet execution threw an exception
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:311)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:263)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1018)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:196)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:499)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
        at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1018)
        at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2748)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:186)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
        at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1018)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:512)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1018)
        at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:199)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:637)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:463)
        at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:568)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:631)
        at java.lang.Thread.run(Thread.java:662)

After changing the code line a bit i got the following new error:

java.lang.NoClassDefFoundError: Could not initialize class org.jfree.chart.JFreeChart
        at org.jfree.chart.ChartFactory.createLineChart(ChartFactory.java:1242)
        at var.DatabaseLevelReport.doGet(Unknown Source)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

This looks like a known issue but still i could not solve it:

See here and here

So finally the issue got resolved. The error was basically that a jfree object was failing to initiate.

The jfree constructor tries to do some static initialisations out of which one was failing.

The reason turned out to be the following jar even though it was in the classpath: gnome-java-bridge.jar

Simply commenting out the class name in the accessibility.properties file, prevents java from trying to load that class.

This looks like a known issue: Reference1 Reference2

After that everything worked perfectly normal!

Thanks all for your help! much Appreciated.

From your description, it sounds like the data within the productive system is not the same as that in QA system.

I noticed that your System.out.println("I am in the Chart Generation TRY Block"); is not being shown in the logs. Try changing the .out to .err and also try catching Throwable ( http://docs.oracle.com/javase/7/docs/api/java/lang/Throwable.html ).

catch ( Throwable t )

It is possible that will catch exceptions that Exception misses (I think), which might provide more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM