Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4239783
Votes 7
Synopsis Need to do off-screen drawing in CGI program written in java to create GIF outpu
Category java:classes_awt
Reported Against 1.2.1
Release Fixed
State 11-Closed, duplicate of 4281163, bug
Priority: 4-Low
Related Bugs 4281163
Submit Date 20-MAY-1999
Description




I am developing a CGI script that creates a GIF file on the fly as
output.
The following program (with associated classes) works if  it is run with
the
worstation open and with DISPLAY (X-11) set.    But the

getGraphics(..)

call hangs if DISPLAY is not set.  Of course no DISPLAY can be set for
a CGI program !!!

Any comments, ideas will be deeply appreciated.

Paul



import java.io.*;
import java.awt.*;
import java.awt.image.*;
//import Acme.JPM.Encoders.*;


public class TestGif
{   public static void main(String[] args)
             throws IOException
    {    Image off = new BufferedImage(400,300,
                         BufferedImage.TYPE_INT_RGB);
         System.err.print("one");
         //  getGraphics() hangs if no DISPLAY
         Graphics off_g = off.getGraphics();
         off_g.drawRect(20,20,100,70);
         FileOutputStream out = new FileOutputStream("rect.gif");
         GifEncoder en = new GifEncoder(off, out);
         en.encode();    // sends GIF to file out
         return;
    }
}
(Review ID: 57936) 
======================================================================
Work Around




Not known.
======================================================================
Evaluation
This is headless AWT.
Comments
  
  Include a link with my name & email   

Submitted On 17-OCT-1999
pshwang
Just checking back on the progress on this report.  Am surprised there
are not more votes for this bug.  How do people generate graphics
using Java on the server side anyway?  I presume the same problem
is present with servlets.
pwang@mcs.kent.edu


Submitted On 15-FEB-2000
moog
I have the same problem when trying to generate jpeg:s serverside using the
java2 jpegcodec. Doesn't anyone have a workaround? I don't want to install x on
my server.... 

daniel@spraydio.com


Submitted On 31-MAY-2000
puybaret
Have a look at PJA (Pure Java AWT) library provided by eTeks.

It is an AWT Toolkit library with 100% pure Java graphics, 
compatible with Java 1.1.
It doesn't need any X11 Display : all java.awt.Graphics 
drawing methods are written in Java in an off-screen image 
managed with a buffer. 
The people using servlets with no X11 Display available on 
their Unix web server, will be able to generate image results 
with their servlets (charts, pies, counters,...) using Java 
Graphics methods.

Switch Toolkit from X11 or Windows default Toolkit to PJA 
Toolkit can be done in one operation :
Change the "awt.toolkit" System property to 
"com.eteks.awt.PJAToolkit"  (thus getDefaultToolkit () static 
method of java.awt.Toolkit will use this class as Toolkit).

PJA library is free to enable people to optimize the Graphics 
methods and use it on their server.

More information available at http://www.eteks.com
(PJA can be accessed directly at http://www.eteks.com/pja/en)


Submitted On 08-NOV-2000
patenaude
I have the same problem trying to create PDF files from a SUN. It works fine as long as I'm logged into an 
X-window. But in production, the server won't always have someone logged in. I looked at the PJA site but 
since I don't speak French, I can't tell if it will work on a SUN. The only download files appear to be PC or 
Mac... I can't believe that this isn't considered a bug!


Submitted On 31-JAN-2001
lars_bjerregaard
Dear Java team.<P>
I'm confused. "Headless AWT", what is that supposed to mean?
I've got exactly the same problem. Doing serverside graphics without having and X-Windows session open (after all- the 2 does not necessarily have anything to do with each other!). I'll give you the ultimate simple example to reproduce it:<p><p>
import java.awt.*; <p>
import java.awt.image.*;<p>
<p>
public class AwtTest {<p>
<p>
    public static void main(String args[]) {<p>
<p>
        BufferedImage bi = new BufferedImage( 300, 200, BufferedImage.TYPE_INT_RGB);<p>
        Graphics2D g2 = bi.createGraphics();<p>
    }<p>
}<p>
<p>
Just run "java AwtTest". When you run it without an active X server, it'll say it can't find one with this DISPLAY variable (not matter what you set it to), and when you have an X server going on your machine, as an example an X emulator on your Windoze machine, with the DISPLAY pointing to it, it works fine (the example does nothing off course).<p>
So from my own experience, and from what you guys confirm, it sounds like an AWT 'feature' rather than a bug. Is that understood correctly?<p>
This is rather unfortunate, because it means you can't do graphics if you haven't got X running, whether you need X or not. Not good!!!


Submitted On 12-FEB-2001
thomaschoy
I also faced the same problem. I found that as long as the 
CGI touched java.awt.* (that includes Image, Graphics, 
Graphics2D, Toolkit, etc...), even javax.swing.* will 
generate such error on an Unix box without running X 
session. I'm still investigating how to avoid that. But I 
found a workabout using DISPLAY, which use BufferedImage 
plus com.sun.image.codec.jpeg:

import java.io.*;
import com.sun.image.codec.jpeg.*;
...
FileInputStream in = new FileInputStream(imageFile);
JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(in);
BufferedImage image = decoder.decodeAsBufferedImage();
in.close();

Hope this help. If any expert know how to solve this 
DISPLAY problem, please advise. :~)

Thomas Choy



PLEASE NOTE: JDK6 is formerly known as Project Mustang