Java Servlet抛出异常

时间:2013-07-23 12:28:06

标签: java jsp tomcat

我们为Sybase服务器开发了一个基于Web的监控应用程序,并且在生产环境中使用jfree生成图表时出现问题。

我们通常在QA机器中构建和测试我们的应用程序,然后将构建的* .war文件ftp到生产环境。

当完全相同的代码无法在生产中生成图形时,问题就出现在生产环境中。

以下是我们要导入的类和包:

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;

以下是我们认为会抛出错误的代码片段:

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();
  }

最后QA中的server.log条目随后出现在生产中:

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)

更改代码行后,我收到以下新错误:

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)

这看起来像一个已知的问题,但我仍然无法解决它:

See herehere

2 个答案:

答案 0 :(得分:1)

所以最后这个问题得到了解决。错误基本上是jfree对象无法启动。

jfree构造函数尝试进行一些静态初始化,其中一个失败。

原因结果是以下jar,即使它在类路径中: 侏儒-java的bridge.jar

只需在accessibility.properties文件中注释掉类名,就可以防止java尝试加载该类。

这看起来像一个已知问题: Reference1 Reference2

之后一切正常![/ p>

感谢大家的帮助!非常赞赏。

答案 1 :(得分:0)

根据您的描述,听起来生产系统中的数据与QA系统中的数据不同。

我注意到您的System.out.println("I am in the Chart Generation TRY Block");未显示在日志中。尝试将.out更改为.err,并尝试捕捉Throwablehttp://docs.oracle.com/javase/7/docs/api/java/lang/Throwable.html)。

catch ( Throwable t )

有可能会捕获Exception未命中的异常(我认为),这可能会提供更多信息。