Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Custom Java Graphics Package Comunicatting to Servlet problems

0 views
Skip to first unread message

mena...@my-deja.com

unread,
Jun 22, 2000, 3:00:00 AM6/22/00
to
I hope somebody has not only ran into this problem, but might have some
insight on how to fix it. Let me give you a brief description on what
I'm doing:

I'm writing a dynamic graphics package for a client which uses
Netscape's Web Server for the servlets (EJBs later) and IBM's jdk1.1.8
on a UNIX box WITHOUT an X Server running. The package draws 2D graphs
(Line, bar, pie, etc.) based on the information that passed to its
constructor. It draws the image to a GraphicsContext, encodes the
image and returns back a byte array consisting of the encoded image.
This works flawlessly when used as external classes on my Windows NT
2000 development machine, but once I created a test servlet that
instantiated my class and tried to return the image, all hell broke
loose.

I started researching and come to find out, there's a bug that depends
on the X Server running on a UNIX server. So I thought I would try it
on a Windows NT server running the same server software. A different
error this time, sounds easy, but I can't figure out what the problem
is.

Here is the error I receive coming directly from the Netscape server:

--------------------------------------------------

[22/Jun/2000:10:58:14] failure ( 293): Internal error: exception
thrown from the servlet service function (uri=/servlet/TestServlet):
java.lang.NullPointerException: , Stack:
java.lang.NullPointerException:
at sun.awt.SunToolkit.getFontMetrics(SunToolkit.java:174)
at sun.awt.windows.WToolkit.getFontMetrics(WToolkit.java:346)
at java.awt.Component.getFontMetrics(Component.java:1730)
at Graph2D.setBounds(Graph2D.java:257)
at Graph2D.(Graph2D.java:105)
at LineGraph2D.(LineGraph2D.java:35)
at TestChartArray.init(TestChartArray.java:169)
at TestChartArray.(TestChartArray.java:49)
at TestServlet.service(TestServlet.java:64)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:826)
at com.netscape.server.http.servlet.NSServletRunner.Service
(NSServletRunner.java:462)

---------------------------------------------------

Somebody help!

mena...@yahoo.com


Sent via Deja.com http://www.deja.com/
Before you buy.

mena...@my-deja.com

unread,
Jun 22, 2000, 3:00:00 AM6/22/00
to
anybody?

In article <8iu0ps$olf$1...@nnrp1.deja.com>,

Simon Brooke

unread,
Jun 23, 2000, 3:00:00 AM6/23/00
to
mena...@my-deja.com writes:

> I hope somebody has not only ran into this problem, but might have some
> insight on how to fix it. Let me give you a brief description on what
> I'm doing:
>
> I'm writing a dynamic graphics package for a client which uses
> Netscape's Web Server for the servlets (EJBs later) and IBM's jdk1.1.8
> on a UNIX box WITHOUT an X Server running. The package draws 2D graphs
> (Line, bar, pie, etc.) based on the information that passed to its
> constructor. It draws the image to a GraphicsContext, encodes the
> image and returns back a byte array consisting of the encoded image.
> This works flawlessly when used as external classes on my Windows NT
> 2000 development machine, but once I created a test servlet that
> instantiated my class and tried to return the image, all hell broke
> loose.

I've just answered this one in another thread, but here goes again.

You need a virtual frame buffer running as the user who owns your
server process. See Xvfb(1).

I run this from an init script as follows:

------------------------------ cut here ----------------------------
#! /bin/sh
#
# description: Xvfb: virtual X server with no real screen. Needed, among
# other things, to allow servlets to draw graphics.

# Source function library.
. /etc/rc.d/init.d/functions

# Get config.
. /etc/sysconfig/network

# Check that networking is up.
if [ ${NETWORKING} = "no" ]
then
exit 0
fi

# See how we were called.
case "$1" in
start)
echo -n "Starting Xvfb services: "
Xvfb :1 -fp /usr/X11R6/lib/X11/fonts/misc/,/usr/X11R6/lib/X11/fonts/75dpi/ -screen 0 640x480x24 &

echo
touch /var/lock/subsys/Xvfb
;;
stop)
echo -n "Stopping Xvfb services: "
killproc Xvfb

echo
rm -f /var/lock/subsys/Xvfb
;;
status)
status Xvfb
;;
restart|reload)
$0 stop
$0 start
;;
*)
echo "Usage: xvfb {start|stop|status|restart}"
exit 1
esac

exit 0
------------------------------ cut here ----------------------------

Obviously you'll have to edit this, especially the font path, for your
local conditions. Also note that I've only allowed 640x480 with 24bit
colour depth - if your graphics are bigger than this, make the screen
geometry bigger (I tend to assume all server-side generated graphics
will be reasonably small).

You then set the DISPLAY environment variable which you pass to your
server to yourhost:1.0 - I do this with Apache JServ as follows:

# An environment name with value passed to the JVM
# Syntax: wrapper.env=[name]=[value]
# Default: NONE on Unix Systems
# SystemDrive and SystemRoot with appropriate values on Win32 systems
wrapper.env=DISPLAY=localhost:1.0

(Obviously you'll need to do something different for your Netscape
server - the simplest thing may simply be to set the variable in the
enviroment before you start the server. After this it should all work
but if you have further difficulties please get back to me.

Oh - to see it work,
<URL:http://www.weft.co.uk/event/uk.co.weft.htform.ExampleMappedImageServlet>

--
si...@jasmine.org.uk (Simon Brooke) http://www.jasmine.org.uk/~simon/

;; I'd rather live in sybar-space

0 new messages