----------------------------------------------------------------
BEFORE YOU POST, search the faq at <http://java.apache.org/faq/>
WHEN YOU POST, include all relevant version numbers, log files,
and configuration files.  Don't make us guess your problem!!!
----------------------------------------------------------------

hi all. i have a servlet called geoview, which is invoked thus:

        <img src="/servlets/geoview?sql=..." usemap="#geomap">

it works fine when the page containing it is viewed a number of times 
(5-20 times say), but eventually, the image is never delivered to the
browser.  

other servlets in the same zone continue to work fine - although they
just return html in response to doGet and don't return images.  i have
to re-start apache to get geoview to work again.

i'm stumped because nothing is logged in the jserv logs

i'm using Apache JServ 1.1beta2, Apache 1.3.9, Red Hat 6.1 kernel
2.2.13, IBM JDK v1.1.8

in rc.local, i've got:

        /usr/X11R6/bin/Xvfb :2 -screen 0 1152x900x8 2>>
/etc/httpd/logs/Xvfb.log &

there is probably something simple wrong with my use of AWT, so i've
attached geoview.java in the hope that some kind soul can show me the
error of my ways.

thanks in anticipation,

jason harrop

====================


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.awt.*;
import java.util.*;
import java.sql.*;


import Acme.JPM.Encoders.GifEncoder;

public class geoview extends HttpServlet
{


  Frame frame = null;
  Graphics g = null;
  Image mapImage, houseIcon;

  int MaxX, MaxY;

  public void init(ServletConfig config) throws ServletException
  {
    super.init(config);
    // Construct a reusable unshown frame
    frame = new Frame();
    frame.addNotify();
  }


 public void doGet(HttpServletRequest req, HttpServletResponse res)
                throws ServletException, IOException
    {

        MaxX = Integer.parseInt( req.getParameter("_reqWidth") );
        MaxY = Integer.parseInt( req.getParameter("_reqHeight") );


    try {
                res.setContentType("image/gif");
                OutputStream out = res.getOutputStream();

      MediaTracker mt = new MediaTracker(frame);  // frame acts as an
ImageObserver

      mapImage =
Toolkit.getDefaultToolkit().getImage("/home/httpd/servlets/Map.gif");
      mt.addImage(mapImage, 0);

      houseIcon =
Toolkit.getDefaultToolkit().getImage("/home/httpd/countryviews/html/images/house911.gif");
      mt.addImage(houseIcon, 1);

      try {
        mt.waitForAll();
      }
      catch (InterruptedException e) {
        getServletContext().log(e, "Interrupted while loading image");
        throw new ServletException(e.getMessage());
      }

      // Construct a matching-size off screen graphics context

      Image offscreen = frame.createImage(MaxX, MaxY); // create image
buffer
      g = offscreen.getGraphics(); // get graphics context


      // Draw the image to the off screen graphics context
      g.drawImage(mapImage, 0, 0, MaxX, MaxY, frame);

      //SQL

            try {
                    ResourceBundle bundle =
ResourceBundle.getBundle("SelectResource");  

                Class.forName ( bundle.getString("Driver")
).newInstance();
                Connection conTMP = DriverManager.getConnection (
bundle.getString("URL") );
                Statement stmtTMP = conTMP.createStatement ();

                ResultSet rsTMP = stmtTMP.executeQuery ("SELECT " +
req.getParameter("sql"));
                boolean noResults = true;
                while ( rsTMP.next() )
                {
                                markSpot( setX( rsTMP.getDouble("Longitude") ) ,
setY(rsTMP.getDouble("Latitude")) );
                }

                rsTMP.close();
                stmtTMP.close();
                conTMP.close();
                }
                        catch (SQLException ex)
                        {
                while (ex != null)
                {
                    System.out.println ("SQL Exception:  " +
                            ex.getMessage ());
                    System.err.println ("SQL Exception:  " +
                            ex.getMessage ());
                    ex = ex.getNextException ();
                }
            }
            catch (java.lang.Exception ex)
            {
                    ex.printStackTrace ();
            }


   GifEncoder encoder = new GifEncoder(offscreen, out);
      encoder.encode();


    }
    catch (java.lang.Exception ex)
    {
                System.out.println ( ex.getMessage () );
                System.err.println ( ex.getMessage () );
                ex.printStackTrace ();
    }
    
    
    
  }  // end doGet




  public void destroy()
  {
    // Clean up resources
    if (frame != null) frame.removeNotify();
  }




        public void markSpot( int x, int y)
        {
        //g.setColor(Color.darkGray);
        //g.fillOval(x-5, y-5, 11, 11);
        //g.setColor(Color.green);
        //g.fillOval(x-3, y-3, 7, 7);
                g.drawImage(houseIcon, x-4, y-5, frame);
        }


        public int setY(double lat)
        {

                double minLat = 36.645;
                double maxLat = 37.387;
                int pixRange = MaxY;
                return ( (int)Math.round( pixRange*(lat - minLat)/(maxLat-minLat) ) );

        }

        public int setX(double lon)
        {

                double minLong = 145.117;
                double maxLong = 146.684;
                int pixRange = MaxX;
                return ( (int)Math.round(  pixRange*(lon - minLong)/(maxLong-minLong)
) );
        }


}


--
--------------------------------------------------------------
Please read the FAQ! <http://java.apache.org/faq/>
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives and Other:  <http://java.apache.org/main/mail.html>
Problems?:           [EMAIL PROTECTED]

Reply via email to