2013-07-23 179 views
0

我們爲Sybase服務器開發了基於Web的監控應用程序,並且在生產環境中使用jfree生成圖形時出現問題。Java Servlet拋出異常

我們通常在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(); 
    } 

最後下的server.log條目QA其次是在生產中:

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) 

更改代碼行後,我有點foll由於新的錯誤:

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

+0

看着你已經上傳的堆棧跟蹤,這個錯誤看起來並不像它與任何外部庫有關。您是否在QA和生產環境中使用相同的容器服務器/版本?另請檢查以確保您的網絡應用程序中沒有應用程序服務器特定的罐子,例如 「servlet-api.jar」。我相信建議不要在網絡應用程序中手動添加這些罐子。 – PJR

回答

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失誤(我認爲),這可能會提供更多的信息。

+0

感謝您的回覆。生產和QA中的數據將從同一個數據庫中查詢。所以我很確定他們是一樣的。我會嘗試你的其他建議,然後回來。 –

1

最後問題得到解決。該錯誤基本上是一個jfree對象未能啓動。

jfree構造函數試圖做一些靜態初始化,其中一個失敗。

的原因竟然是,即使它是在類路徑中的以下jar: 的gnome-java的bridge.jar

只需在accessibility.properties文件中註釋掉類的名稱,防止從Java嘗試加載該類。

這看起來像一個已知的問題: Reference1 Reference2

之後,一切工作完全正常!

謝謝大家的幫助!非常感激。