leif 2004/01/08 01:16:00
Modified: instrument-manager/src/java/org/apache/excalibur/instrument/manager/http
SampleChartHandler.java
Added: instrument-manager/src/java/org/apache/excalibur/instrument/manager/http
noawtlibs.jpg
Log:
Modify the handler that generates the dynamic charts so it will serve a friendly
error rather than throwing an exception if the server can not find the AWT libraries.
Revision Changes Path
1.2 +34 -2
avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/SampleChartHandler.java
Index: SampleChartHandler.java
===================================================================
RCS file:
/home/cvs/avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/SampleChartHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SampleChartHandler.java 9 Nov 2003 16:36:33 -0000 1.1
+++ SampleChartHandler.java 8 Jan 2004 09:16:00 -0000 1.2
@@ -53,7 +53,9 @@
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
+import java.awt.Graphics;
import java.awt.image.BufferedImage;
+import java.io.BufferedInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
@@ -203,7 +205,37 @@
// Paint the chart onto the Graphics object of the BufferedImage.
chart.setSize( bi.getWidth(), bi.getHeight() );
- chart.paintComponent( bi.createGraphics() );
+
+ Graphics g;
+ try
+ {
+ g = bi.createGraphics();
+ }
+ catch ( NoClassDefFoundError e )
+ {
+ // On Headless UNIX machines this error will be thrown when attempting
to
+ // create an graphic. The AWT libraries require a native library that
+ // only exists on UNIX system which have X-Windows installed. This is
+ // never a problem on Windows systems.
+
+ // Rather than giving the user nothing, send them a preprepared jpeg
file
+ // that notifies them of the problem.
+ String imageResource = "noawtlibs.jpg";
+ BufferedInputStream is =
+ new BufferedInputStream( getClass().getResourceAsStream(
imageResource ) );
+ byte[] noAWTLibs;
+ try {
+ noAWTLibs = new byte[is.available()];
+ is.read( noAWTLibs, 0, noAWTLibs.length );
+ } finally {
+ is.close();
+ }
+ // Now write the error image out to the client.
+ os.write( noAWTLibs );
+ return;
+ }
+
+ chart.paintComponent( g );
// Encode the BufferedImage as a JPEG image and write it to the output
stream.
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder( os );
1.1
avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/noawtlibs.jpg
<<Binary file>>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]