LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-22-2008, 03:26 PM   #1
elprawn
Member
 
Registered: Feb 2005
Distribution: Gentoo 2008
Posts: 138

Rep: Reputation: 15
Tomcat 5.5; 503 error; Image processing; Apache 2.2; Fedora Core 5.


Hello.

I have a Java Class with the following code...

Code:
import java.awt.image.BufferedImage;
import javax.imageio.*;
import java.io.File;
import java.awt.Color;

public class ProduceVerifyImage {
	
	public static String getVerifyURI (String form, String code) {
		
		if (form != null && code != null && form.length() > 1 && code.length() == 4) {
			
			code = code.toLowerCase();
			BufferedImage b = new BufferedImage(120, 30, BufferedImage.TYPE_4BYTE_ABGR);
			BufferedImage[] chars = new BufferedImage[4];
			BufferedImage[] masks = new BufferedImage[4];
			BufferedImage[] mixed = new BufferedImage[4];
			
			for (int i=0; i < 4; i++) {
			
				try {
					chars[i] = ImageIO.read(new File("/var/www/dynamic/pics/site/verify/" + code.charAt(i) + ".gif"));
					masks[i] = ImageIO.read(new File("/var/www/dynamic/pics/site/verify/mask" + (int)Math.ceil(Math.random() * 40) + ".gif"));
					mixed[i] = new BufferedImage(30, 30, BufferedImage.TYPE_4BYTE_ABGR);
				} catch (Exception e) {
					
				}
				
			}
			
			for (int h = 0; h < 4; h++) {
			
				for (int i = 0; i < 30; i++ ) {
				
					for (int j = 0; j < 30; j++) {
					
						Color charscolor = new Color(chars[h].getRGB(i, j));
						Color maskscolor = new Color(masks[h].getRGB(i, j));
					
						int red = (int)((charscolor.getRed() + maskscolor.getRed()) / 2);
						int green = (int)((charscolor.getGreen() + maskscolor.getGreen()) / 2);
						int blue = (int)((charscolor.getBlue() + maskscolor.getBlue()) / 2);
					
						Color mixedcolor = new Color(red, green, blue);
					
						mixed[h].setRGB(i, j, mixedcolor.getRGB());
					}
				
				}
			
			}
			
			b.setRGB(0, 0, 30, 30, mixed[0].getRGB(0, 0, 30, 30, null, 0, 30), 0, 30);
			b.setRGB(30, 0, 30, 30, mixed[1].getRGB(0, 0, 30, 30, null, 0, 30), 0, 30);
			b.setRGB(60, 0, 30, 30, mixed[2].getRGB(0, 0, 30, 30, null, 0, 30), 0, 30);
			b.setRGB(90, 0, 30, 30, mixed[3].getRGB(0, 0, 30, 30, null, 0, 30), 0, 30);
			
			File outputfile = new File("/var/www/dynamic/pics/site/verify/codes/" + form + "-" + code + ".png");
			
			try {
				outputfile.delete();
				ImageIO.write(b, "png", outputfile);
				
			} catch (Exception e) {
				
			}
			
			return "/var/www/dynamic/pics/site/verify/codes/" + form + "-" + code + ".png";
		
		}
		
		return "";
		
	}
	
}
The function getVerifyURI is called by my servlet as follows...

Code:
String imguri = ProduceVerifyImage.getVerifyURI("Register", verifyCode);
The error I get is shown as...

Code:
Service Temporarily Unavailable

The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

Apache/2.2.2 (Fedora) Server at 192.168.2.91 Port 80
Commenting the line out of my servlet stops the error, but I'd like to get it working. I've tried adding a main(String[] args) function to the ProduceVerifyImage class that calls the getVerifyURI function and it works as expected but the servlet throws up that 503 error when I include a call to it in my servlet code.

Thanks for your help.
 
Old 09-23-2008, 02:59 AM   #2
elprawn
Member
 
Registered: Feb 2005
Distribution: Gentoo 2008
Posts: 138

Original Poster
Rep: Reputation: 15
OK, well I managed to find the code which causes the error. I get the error if I leave in either of the following two lines...

Code:
chars[i] = ImageIO.read(new File("/var/www/dynamic/pics/site/verify/" + code.charAt(i) + ".gif"));
masks[i] = ImageIO.read(new File("/var/www/dynamic/pics/site/verify/mask" + (int)Math.ceil(Math.random() * 40) + ".gif"));
Any ideas?
 
Old 09-23-2008, 03:11 AM   #3
elprawn
Member
 
Registered: Feb 2005
Distribution: Gentoo 2008
Posts: 138

Original Poster
Rep: Reputation: 15
Specifically it seems to be ImageIO.read() and ImageIO.write() that are upsetting the server. Anyone know what the problem might be?
 
Old 09-23-2008, 05:10 AM   #4
elprawn
Member
 
Registered: Feb 2005
Distribution: Gentoo 2008
Posts: 138

Original Poster
Rep: Reputation: 15
Turns out any calls to any ImageIO functions will cause the error. What could be causing this?
 
Old 09-23-2008, 06:17 AM   #5
elprawn
Member
 
Registered: Feb 2005
Distribution: Gentoo 2008
Posts: 138

Original Poster
Rep: Reputation: 15
The last thing I have in my Catalina.out file is...

Code:
(.:5000): Gtk-WARNING **: cannot open display:
 
Old 09-23-2008, 08:03 AM   #6
elprawn
Member
 
Registered: Feb 2005
Distribution: Gentoo 2008
Posts: 138

Original Poster
Rep: Reputation: 15
OK, so I found out that the JAVA_HOME in my tomcat5.conf points to some lame version of java. Editing it to point to the Sun version yields the following...

Code:
Starting tomcat5: /usr/bin/rebuild-jar-repository: error: Could not find jdbc-stdext Java extension for this JVM
/usr/bin/rebuild-jar-repository: error: Could not find jndi Java extension for this JVM
/usr/bin/rebuild-jar-repository: error: Some detected jars were not found for this jvm
/usr/bin/rebuild-jar-repository: error: Could not find jaas Java extension for this JVM
/usr/bin/rebuild-jar-repository: error: Some detected jars were not found for this jvm
find: warning: you have specified the -mindepth option after a non-option argument -type, but options are not positional (-mindepth affects tests specified before it as well as those specified after it).  Please specify options before other arguments.

find: warning: you have specified the -maxdepth option after a non-option argument -type, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it).  Please specify options before other arguments.

Using CATALINA_BASE:   /usr/share/tomcat5
Using CATALINA_HOME:   /usr/share/tomcat5
Using CATALINA_TMPDIR: /usr/share/tomcat5/temp
Using JRE_HOME:
                                                           [  OK  ]
Which basically translates as jndi.jar and jaas.jar not being in my $JAVA_HOME/jre/lib folder (the sun version).

Is there a painless way of fixing this?
 
Old 09-23-2008, 11:51 AM   #7
elprawn
Member
 
Registered: Feb 2005
Distribution: Gentoo 2008
Posts: 138

Original Poster
Rep: Reputation: 15
Right, well I finally got it seeing those jar files and made my JAVA_HOME one which was outside the /root folder and... it works!!!

Hope this has helped someone
 
Old 06-25-2009, 01:35 PM   #8
jnojr
Member
 
Registered: Sep 2007
Location: Chandler, AZ
Posts: 227

Rep: Reputation: 20
How did you get it to "see" those jars?

I'm using RHEL5.2 and I installed java 1.6.0u13 This error cropped up, but the only jndi.jar and jaas.jar I se are the ones that ship with the awful gcj-java-1.4.2 packages. Where do the current, modern, Sun JARs come from?
 
Old 06-26-2009, 04:58 AM   #9
elprawn
Member
 
Registered: Feb 2005
Distribution: Gentoo 2008
Posts: 138

Original Poster
Rep: Reputation: 15
To be honest, I can't remember. Sorry I haven't been much help. Try this, though...

Extract the folders from the sun jar files and copy them or symbolic link them into the tomcat5/common/classes, tomcat5/server/classes and tomcat5/shared/classes folders. I'm not sure which one they're meant to be in, but it'll be one of them and I'm pretty sure this should fix your problem.

Last edited by elprawn; 06-27-2009 at 01:41 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache Error on Fedora Core 2 RJDavison Linux - Software 2 02-16-2009 08:21 AM
dpkg: error processing webmin-core (--configure) cccc Debian 2 12-25-2006 09:34 PM
webmin-core processing error code 1 on Debian Sarge raskulnikov Linux - General 0 09-22-2006 10:57 AM
Fedora Core 2 + Apache + Tomcat + JDBC paulecoyote Linux - Newbie 9 07-27-2004 06:58 PM
Error 503 Apache v2-ncl Linux - Software 1 07-07-2004 06:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration