GeeCON Prague 2014*
The moose likes Servlets and the fly likes Create Image in servlet WITHOUT invoking java.awt.Toolkit - Can it be done? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Create Image in servlet WITHOUT invoking java.awt.Toolkit - Can it be done?" Watch "Create Image in servlet WITHOUT invoking java.awt.Toolkit - Can it be done?" New topic
Author

Create Image in servlet WITHOUT invoking java.awt.Toolkit - Can it be done?

DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
OK, folks Ive been beating my head on the desk over this one for two days! What I have going is a "resize after upload" app Im working on that uploads the images to the server and then resizes them to a max width or height of 500px and optimizes them.. I had it working perfectly on my win2k box but then went to test on my Linux production server ... BOOM, NFG.

After some reading and investigation with my server guy we pinpointed it to the fact the Xwindows server is NOT installed on the server so anytime any class attempts a reference to the Toolkit it blows up.. Ive tried ImageIcon, Toolkit.getDefaultToolkit().getImage etc etc etc..

So someone has HAD to run into this before ... how in GODS NAME do I get a Valid Image object that I can resize etc without invoking a class that requires the Tookit? And no we are NOT installing the XWindows on the server because its sucks up SO much in resources its just not worth it.

Thanks for any help someone might offer!
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
Just upgrade to 1.4. Swing doesn't use the operating system to draw stuff. There are other ways around the problem though, if you can't upgrade. They mostly involve other toolkits that don't use awt to do drawing.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
we are using 1.4 and still have the problem. this is the exception:

500 Servlet Exception

||

java.lang.NoClassDefFoundError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at java.awt.Toolkit$2.run(Toolkit.java:748)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:739)
at ResizeImages.doPost(ResizeImages.java:25)
at ResizeImages.doGet(ResizeImages.java:91)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:126)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:103)
at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:113)
at com.caucho.server.cache.CacheFilterChain.doFilter(CacheFilterChain.java:211)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:177)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:221)
at com.caucho.server.hmux.HmuxRequest.handleRequest(HmuxRequest.java:392)
at com.caucho.server.port.TcpConnection.run(TcpConnection.java:315)
at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:353)
at com.caucho.util.ThreadPool.run(ThreadPool.java:302)
at java.lang.Thread.run(Thread.java:534)

with either this code:

Image image = Toolkit.getDefaultToolkit().getImage(sc.getRealPath("/dlrImages/1000/")+images[x]);

or this:

Image image = new javax.swing.ImageIcon(sc.getRealPath("/dlrImages/1000/")+images[x]).getImage();
[ July 07, 2005: Message edited by: DC Dalton ]
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Try -



You can find more by googling for Headless Linux.

Cheers.


The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Yep, and if you search his formum for the same you'll find a refernce to a jar I found which simulates the missing AWT classes.
 
GeeCON Prague 2014
 
subject: Create Image in servlet WITHOUT invoking java.awt.Toolkit - Can it be done?