JFreeChart Crashes JVM on Solaris
JFreeChart Crashes JVM on Solaris
Attempting to generate a simple pie chart causes an immediate JVM crash on Solaris.
The JfreeChart code is running as a JSP page under the Orion servlet container. The last message in the log is X-windows reporting that it can no longer contact the server process.
The chart draws fine on Windows and Linux systems.
The code is attached. Grateful if someone could show me the error of my ways. Note that I am using the Jakarta xTags taglib to parse xml (the source of the data which gets fed into the chart.)
Thanks in advance.
Bill Clark
<%@ page import="java.util.*,java.io.*,com.sun.image.codec.jpeg.*,com.jrefinery.chart.*,com.jrefinery.chart.data.*,com.jrefinery.chart.ui.*,com.jrefinery.data.*,com.jrefinery.ui.*"%>
<%@ taglib uri="/WEB-INF/xtags.tld" prefix="xtags" %>
<%
String symbols="";
String values="";
%>
<xtags:parse>
<?xml version="1.0" encoding="ISO-8859-1" ?>
<portfolio name="frank" currency="USD">
<fid id="valccy">0</fid>
<fid id="netccy">0</fid>
<fid id="pctccy">0</fid>
<fid id="netday">0</fid>
<fid id="pctday">0</fid>
<fid id="cash">-</fid>
<ric name="MSFT" id="1">
<fid id="name">
<![CDATA[ MSFT
]]>
</fid>
<fid id="quantity">10</fid>
<fid id="prcnow">-</fid>
<fid id="valnow">-</fid>
<fid id="ccynow" name="-">-</fid>
<fid id="valccy">-</fid>
<fid id="netccy">-</fid>
<fid id="pctccy">-</fid>
</ric>
<ric name="RTRSY" id="2">
<fid id="name">
<![CDATA[ RTRSY
]]>
</fid>
<fid id="quantity">20</fid>
<fid id="prcnow">-</fid>
<fid id="valnow">-</fid>
<fid id="ccynow" name="-">-</fid>
<fid id="valccy">-</fid>
<fid id="netccy">-</fid>
<fid id="pctccy">-</fid>
</ric>
<ric name="MSFT" id="3">
<fid id="name">
<![CDATA[ MSFT
]]>
</fid>
<fid id="quantity">30</fid>
<fid id="prcnow">-</fid>
<fid id="valnow">-</fid>
<fid id="ccynow" name="-">-</fid>
<fid id="valccy">-</fid>
<fid id="netccy">-</fid>
<fid id="pctccy">-</fid>
</ric>
<ric name="RTRSY" id="4">
<fid id="name">
<![CDATA[ RTRSY
]]>
</fid>
<fid id="quantity">40</fid>
<fid id="prcnow">-</fid>
<fid id="valnow">-</fid>
<fid id="ccynow" name="-">-</fid>
<fid id="valccy">-</fid>
<fid id="netccy">-</fid>
<fid id="pctccy">-</fid>
</ric>
</portfolio>
</xtags:parse>
<xtags:choose>
<xtags:when test="//portfolio/ric">
<xtags:forEach select="//portfolio/ric">
<xtags:variable id="symbol" select="@name"/>
<xtags:variable id="value" select="fid[@id='quantity']"/>
<% symbols=symbols + symbol + ","; values = values + value + ","; %>
</xtags:forEach>
<%
processRequest(request, response, symbols.substring(0,symbols.length()-1),values.substring(0,values.length()-1));
%>
</xtags:when>
<xtags:otherwise>
There are no securities in this portfolio
</xtags:otherwise>
</xtags:choose>
<%!
private static final String SYMBOLS_PARAM = "symbols";
private static final String VALUES_PARAM = "values";
private static final String TITLE_PARAM = "title";
private static final String CHART_TYPE_PARAM = "type";
private static final String CHART_WIDTH_PARAM = "width";
private static final String CHART_HEIGHT_PARAM = "height";
private static final String CHART_TYPE_PIE = "Pie";
private static final String CHART_TYPE_BAR = "Bar";
// Build a PieChart from the request params
protected JFreeChart getPieChart(String symbollist,String valuelist) {
System.out.println("Here");
JFreeChart chart;
DefaultPieDataset pieData = new DefaultPieDataset();
String[] symbols = getRequestedSymbols(symbollist);
String[] values = getRequestedSymbolValues(valuelist);
for (int x=0; x < symbols.length; x++) {
pieData.setValue(symbols[x], Double.valueOf((String)values[x]));
}
chart = ChartFactory.createPieChart(null, pieData, true);
// This creates a distrubution chart
((PiePlot)chart.getPlot()).setSectionLabelType(PiePlot.NAME_AND_PERCENT_LABELS);
return chart;
}
// Return a string[] of requested symbols from the request
private String[] getRequestedSymbols(String symbols) {
List list = new ArrayList();
StringTokenizer st = new StringTokenizer(symbols,",");
while (st.hasMoreTokens())
{
list.add(st.nextToken());
}
return (String[])list.toArray(new String[0]);
}
// Return a string[] of requested symbols values from the request
private String[] getRequestedSymbolValues(String values) {
List list = new ArrayList();
StringTokenizer st = new StringTokenizer(values,",");
while (st.hasMoreTokens())
{
list.add(st.nextToken());
}
return (String[])list.toArray(new String[0]);
}
// Build a BarChart from the request params
protected JFreeChart getBarChart(String symbollist, String valuelist) {
JFreeChart chart;
CategoryDataset data;
// Series are the symbols
String[] series = getRequestedSymbols(symbollist);
// values are the symbol values
String[] values = getRequestedSymbolValues(valuelist);
// We don't want categories, use blank
String[] cats = new String[] {""};
// Get the dataset
data = getDataSet(values);
// Set the series on the dataset
((DefaultCategoryDataset)data).setSeriesNames(series);
// Set the categories name, if not called then they are
// automatically generated as Category 1, etc.
((DefaultCategoryDataset)data).setCategories(cats);
// Call factory to create the chart
chart = ChartFactory.createVerticalBarChart(null,
"Symbols", "Values", data, true);
return chart;
}
// build a dataset off of the values for the symbols
private CategoryDataset getDataSet(String[] values) {
Number[][] data = new Double[values.length][1];
for (int x=0; x < values.length; x++) {
data[x][0]=new Double(values[x]);
}
return new DefaultCategoryDataset(data);
}
/** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response,String symbols, String values)
throws ServletException, java.io.IOException {
System.out.println("Symbols: " + symbols + ". Values: " + values);
JFreeChart chart = null;
TextTitle title = null;
// Set the content type to JPG
response.setContentType("image/jpeg");
// Get the outputstream to render to
OutputStream out = response.getOutputStream();
// Read the chart type
String type = request.getParameter(CHART_TYPE_PARAM);
if (type.equals(CHART_TYPE_PIE)) {
chart = getPieChart(symbols,values);
} else if (type.equals(CHART_TYPE_BAR)){
chart = getBarChart(symbols,values);
}
// Read the chart title
String chartTitle = request.getParameter(TITLE_PARAM);
if (chartTitle != null) {
title = new TextTitle(chartTitle);
// Build the title object
List titles = new ArrayList();
titles.add(title);
chart.setTitles(titles);
}
// Get the chart height/width
int width = 400;
int height = 300;
try {
width = Integer.parseInt( request.getParameter(CHART_WIDTH_PARAM ) );
height = Integer.parseInt( request.getParameter(CHART_HEIGHT_PARAM) );
}
catch (Exception e) {
}
// Write the chart to the stream
ChartUtilities.writeChartAsJPEG(out, chart, width, height);
// close the stream
out.close();
}
%>
The JfreeChart code is running as a JSP page under the Orion servlet container. The last message in the log is X-windows reporting that it can no longer contact the server process.
The chart draws fine on Windows and Linux systems.
The code is attached. Grateful if someone could show me the error of my ways. Note that I am using the Jakarta xTags taglib to parse xml (the source of the data which gets fed into the chart.)
Thanks in advance.
Bill Clark
<%@ page import="java.util.*,java.io.*,com.sun.image.codec.jpeg.*,com.jrefinery.chart.*,com.jrefinery.chart.data.*,com.jrefinery.chart.ui.*,com.jrefinery.data.*,com.jrefinery.ui.*"%>
<%@ taglib uri="/WEB-INF/xtags.tld" prefix="xtags" %>
<%
String symbols="";
String values="";
%>
<xtags:parse>
<?xml version="1.0" encoding="ISO-8859-1" ?>
<portfolio name="frank" currency="USD">
<fid id="valccy">0</fid>
<fid id="netccy">0</fid>
<fid id="pctccy">0</fid>
<fid id="netday">0</fid>
<fid id="pctday">0</fid>
<fid id="cash">-</fid>
<ric name="MSFT" id="1">
<fid id="name">
<![CDATA[ MSFT
]]>
</fid>
<fid id="quantity">10</fid>
<fid id="prcnow">-</fid>
<fid id="valnow">-</fid>
<fid id="ccynow" name="-">-</fid>
<fid id="valccy">-</fid>
<fid id="netccy">-</fid>
<fid id="pctccy">-</fid>
</ric>
<ric name="RTRSY" id="2">
<fid id="name">
<![CDATA[ RTRSY
]]>
</fid>
<fid id="quantity">20</fid>
<fid id="prcnow">-</fid>
<fid id="valnow">-</fid>
<fid id="ccynow" name="-">-</fid>
<fid id="valccy">-</fid>
<fid id="netccy">-</fid>
<fid id="pctccy">-</fid>
</ric>
<ric name="MSFT" id="3">
<fid id="name">
<![CDATA[ MSFT
]]>
</fid>
<fid id="quantity">30</fid>
<fid id="prcnow">-</fid>
<fid id="valnow">-</fid>
<fid id="ccynow" name="-">-</fid>
<fid id="valccy">-</fid>
<fid id="netccy">-</fid>
<fid id="pctccy">-</fid>
</ric>
<ric name="RTRSY" id="4">
<fid id="name">
<![CDATA[ RTRSY
]]>
</fid>
<fid id="quantity">40</fid>
<fid id="prcnow">-</fid>
<fid id="valnow">-</fid>
<fid id="ccynow" name="-">-</fid>
<fid id="valccy">-</fid>
<fid id="netccy">-</fid>
<fid id="pctccy">-</fid>
</ric>
</portfolio>
</xtags:parse>
<xtags:choose>
<xtags:when test="//portfolio/ric">
<xtags:forEach select="//portfolio/ric">
<xtags:variable id="symbol" select="@name"/>
<xtags:variable id="value" select="fid[@id='quantity']"/>
<% symbols=symbols + symbol + ","; values = values + value + ","; %>
</xtags:forEach>
<%
processRequest(request, response, symbols.substring(0,symbols.length()-1),values.substring(0,values.length()-1));
%>
</xtags:when>
<xtags:otherwise>
There are no securities in this portfolio
</xtags:otherwise>
</xtags:choose>
<%!
private static final String SYMBOLS_PARAM = "symbols";
private static final String VALUES_PARAM = "values";
private static final String TITLE_PARAM = "title";
private static final String CHART_TYPE_PARAM = "type";
private static final String CHART_WIDTH_PARAM = "width";
private static final String CHART_HEIGHT_PARAM = "height";
private static final String CHART_TYPE_PIE = "Pie";
private static final String CHART_TYPE_BAR = "Bar";
// Build a PieChart from the request params
protected JFreeChart getPieChart(String symbollist,String valuelist) {
System.out.println("Here");
JFreeChart chart;
DefaultPieDataset pieData = new DefaultPieDataset();
String[] symbols = getRequestedSymbols(symbollist);
String[] values = getRequestedSymbolValues(valuelist);
for (int x=0; x < symbols.length; x++) {
pieData.setValue(symbols[x], Double.valueOf((String)values[x]));
}
chart = ChartFactory.createPieChart(null, pieData, true);
// This creates a distrubution chart
((PiePlot)chart.getPlot()).setSectionLabelType(PiePlot.NAME_AND_PERCENT_LABELS);
return chart;
}
// Return a string[] of requested symbols from the request
private String[] getRequestedSymbols(String symbols) {
List list = new ArrayList();
StringTokenizer st = new StringTokenizer(symbols,",");
while (st.hasMoreTokens())
{
list.add(st.nextToken());
}
return (String[])list.toArray(new String[0]);
}
// Return a string[] of requested symbols values from the request
private String[] getRequestedSymbolValues(String values) {
List list = new ArrayList();
StringTokenizer st = new StringTokenizer(values,",");
while (st.hasMoreTokens())
{
list.add(st.nextToken());
}
return (String[])list.toArray(new String[0]);
}
// Build a BarChart from the request params
protected JFreeChart getBarChart(String symbollist, String valuelist) {
JFreeChart chart;
CategoryDataset data;
// Series are the symbols
String[] series = getRequestedSymbols(symbollist);
// values are the symbol values
String[] values = getRequestedSymbolValues(valuelist);
// We don't want categories, use blank
String[] cats = new String[] {""};
// Get the dataset
data = getDataSet(values);
// Set the series on the dataset
((DefaultCategoryDataset)data).setSeriesNames(series);
// Set the categories name, if not called then they are
// automatically generated as Category 1, etc.
((DefaultCategoryDataset)data).setCategories(cats);
// Call factory to create the chart
chart = ChartFactory.createVerticalBarChart(null,
"Symbols", "Values", data, true);
return chart;
}
// build a dataset off of the values for the symbols
private CategoryDataset getDataSet(String[] values) {
Number[][] data = new Double[values.length][1];
for (int x=0; x < values.length; x++) {
data[x][0]=new Double(values[x]);
}
return new DefaultCategoryDataset(data);
}
/** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response,String symbols, String values)
throws ServletException, java.io.IOException {
System.out.println("Symbols: " + symbols + ". Values: " + values);
JFreeChart chart = null;
TextTitle title = null;
// Set the content type to JPG
response.setContentType("image/jpeg");
// Get the outputstream to render to
OutputStream out = response.getOutputStream();
// Read the chart type
String type = request.getParameter(CHART_TYPE_PARAM);
if (type.equals(CHART_TYPE_PIE)) {
chart = getPieChart(symbols,values);
} else if (type.equals(CHART_TYPE_BAR)){
chart = getBarChart(symbols,values);
}
// Read the chart title
String chartTitle = request.getParameter(TITLE_PARAM);
if (chartTitle != null) {
title = new TextTitle(chartTitle);
// Build the title object
List titles = new ArrayList();
titles.add(title);
chart.setTitles(titles);
}
// Get the chart height/width
int width = 400;
int height = 300;
try {
width = Integer.parseInt( request.getParameter(CHART_WIDTH_PARAM ) );
height = Integer.parseInt( request.getParameter(CHART_HEIGHT_PARAM) );
}
catch (Exception e) {
}
// Write the chart to the stream
ChartUtilities.writeChartAsJPEG(out, chart, width, height);
// close the stream
out.close();
}
%>
Re: JFreeChart Crashes JVM on Solaris
I was able to get around this problem by incorporating the PJA pure Java graphics environment. I simply followed the instructions provided with PJA.
Re: JFreeChart Crashes JVM on Solaris
Hi Bill Clark,
Could you please give us more information on pja configuration, I tried according to document , but it does not work. I dont have x windows on my machine, using iplanet server for servlet.
Naheed
Could you please give us more information on pja configuration, I tried according to document , but it does not work. I dont have x windows on my machine, using iplanet server for servlet.
Naheed
Re: JFreeChart Crashes JVM on Solaris
Naheed,
The most important thing seemed to be the command line parameters, esp xbootclass. Here's what worked for me:
1) Use the following java command line arguments when starting
/opt/JAVA/bin/java -client -Xbootclasspath/a:/<your web app path>/WEB-INF/lib/pja.jar -Djava.awt.graphicsenv=com.eteks.java2d.PJAGraphicsEnvironment -Djava2d.font.usePlatformFont=false -Djava.awt.fonts=$JAVA_HOME/jre/lib/fonts -Djava.awt=com.eteks.awt.PJAToolkit -
<class name> ...
2) make sure pja.jar is in your web apps class path. Actually, it doesn't really matter where it goes as long as you specify the correct location in -xbootclass.
Just for comparison purposes, my platform consists of
JDK1.3.1
Solaris 8
Orion Application Server 1.5.4
JFreeChart 0.8.1
If you are having problems under iPlanet, it may have to with the different classloader. Try putting PJA.jar into iPlanet's lib directory.
If all else, fails you may have to bite the bullet and upgrade to JDK1.4. That way, you won't even need PJA at all.
Good luck.
Bill Clark
The most important thing seemed to be the command line parameters, esp xbootclass. Here's what worked for me:
1) Use the following java command line arguments when starting
/opt/JAVA/bin/java -client -Xbootclasspath/a:/<your web app path>/WEB-INF/lib/pja.jar -Djava.awt.graphicsenv=com.eteks.java2d.PJAGraphicsEnvironment -Djava2d.font.usePlatformFont=false -Djava.awt.fonts=$JAVA_HOME/jre/lib/fonts -Djava.awt=com.eteks.awt.PJAToolkit -
<class name> ...
2) make sure pja.jar is in your web apps class path. Actually, it doesn't really matter where it goes as long as you specify the correct location in -xbootclass.
Just for comparison purposes, my platform consists of
JDK1.3.1
Solaris 8
Orion Application Server 1.5.4
JFreeChart 0.8.1
If you are having problems under iPlanet, it may have to with the different classloader. Try putting PJA.jar into iPlanet's lib directory.
If all else, fails you may have to bite the bullet and upgrade to JDK1.4. That way, you won't even need PJA at all.
Good luck.
Bill Clark
Re: JFreeChart Crashes JVM on Solaris
Hi Bill
Thanks for replying, yes i tried that way it did work ! with iplanet.
I used j2re1_3_1_03.
But now the real problem is, I want to get it working on Solaris_JDK_1.2.2_11.
I have tried all experiment which i got from documentation like patching rt.jar etc. It did not work. For some reason I am not supposed to upgrade jdk. any thought on this ?
I have tried with Xvfb setting on solaris box also and here is the log for that.
JFreeChartServletDemo: init
[26/Apr/2002:10:16:13] failure (28667): Internal error: exception thrown from the servlet service funct
ion (uri=/servlets/JF): java.lang.InternalError: Display type (DirectColor) and depth (32) not supporte
d., stack: java.lang.InternalError: Display type (DirectColor) and depth (32) not supported.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at <Unloaded Method>
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName0(Compiled Code)
at java.lang.Class.forName(Compiled Code)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:56)
at java.awt.Font.initializeFont(Font.java:255)
at java.awt.Font.<init>(Font.java:285)
at <Unloaded Method>
at com.jrefinery.chart.HorizontalCategoryAxis.<init>(Unknown Source)
at com.jrefinery.chart.ChartFactory.createVerticalBarChart(Unknown Source)
at com.jrefinery.chart.demo.JFreeChartServletDemo.createChart(Unknown Source)
at com.jrefinery.chart.demo.JFreeChartServletDemo.doGet(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:701)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:826)
at com.netscape.server.http.servlet.NSServletRunner.Service(NSServletRunner.java:533)
, root cause:
Naheed
Thanks for replying, yes i tried that way it did work ! with iplanet.
I used j2re1_3_1_03.
But now the real problem is, I want to get it working on Solaris_JDK_1.2.2_11.
I have tried all experiment which i got from documentation like patching rt.jar etc. It did not work. For some reason I am not supposed to upgrade jdk. any thought on this ?
I have tried with Xvfb setting on solaris box also and here is the log for that.
JFreeChartServletDemo: init
[26/Apr/2002:10:16:13] failure (28667): Internal error: exception thrown from the servlet service funct
ion (uri=/servlets/JF): java.lang.InternalError: Display type (DirectColor) and depth (32) not supporte
d., stack: java.lang.InternalError: Display type (DirectColor) and depth (32) not supported.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at <Unloaded Method>
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName0(Compiled Code)
at java.lang.Class.forName(Compiled Code)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:56)
at java.awt.Font.initializeFont(Font.java:255)
at java.awt.Font.<init>(Font.java:285)
at <Unloaded Method>
at com.jrefinery.chart.HorizontalCategoryAxis.<init>(Unknown Source)
at com.jrefinery.chart.ChartFactory.createVerticalBarChart(Unknown Source)
at com.jrefinery.chart.demo.JFreeChartServletDemo.createChart(Unknown Source)
at com.jrefinery.chart.demo.JFreeChartServletDemo.doGet(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:701)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:826)
at com.netscape.server.http.servlet.NSServletRunner.Service(NSServletRunner.java:533)
, root cause:
Naheed
getParameter() method in HTML
I have a problem about non-static getParameter method in JavaApplet to get param from HTML in static method. How can I do that?
How can I draw two or three lines in a one line chart?
How can I draw two or three lines in a one line chart?
Re: JFreeChart Crashes JVM on Solaris
Naheed:
I couldn't get 32 bit depth to work either, but 24 bits was OK with VNC 3.3.3 <http://www.uk.research.att.com/vnc/>, JDK 1.2.2, Solaris 2.7, Tomcat 3.2.3, and JFreeChart 0.5.6. I invoked VNC as
vncserver :1 -geometry 640x480 -depth 24 -pn
This seemed compatible with java.awt.image.BufferedImage.TYPE_INT_RGB.
Hope this helps.
John
I couldn't get 32 bit depth to work either, but 24 bits was OK with VNC 3.3.3 <http://www.uk.research.att.com/vnc/>, JDK 1.2.2, Solaris 2.7, Tomcat 3.2.3, and JFreeChart 0.5.6. I invoked VNC as
vncserver :1 -geometry 640x480 -depth 24 -pn
This seemed compatible with java.awt.image.BufferedImage.TYPE_INT_RGB.
Hope this helps.
John
Re: JFreeChart Crashes JVM on Solaris
>I couldn't get 32 bit depth to work either, but 24 bits was OK with VNC 3.3.3 >http://www.uk.research.att.com/vnc/, JDK 1.2.2,
On the home page it states that you need Java 1.3.
Hope this helps, Good luck.
On the home page it states that you need Java 1.3.
Hope this helps, Good luck.
Re: JFreeChart Crashes JVM on Solaris
The current version of JFreeChart may need Java 1.3, but Naheed was stuck with 1.2.2 and the combination I cited does indeed work.
John
John