DC Dalton

Ranch Hand
+ Follow
since May 28, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by DC Dalton

OK, long story but I'll try to make it quick. I have a server in my possesion that has a Struts / Hibernate app running in Tomcat 5. The app is a nightmare and takes down the server regularly. Anyways they fired the old programmer and hired me to build a new app but I can't even get the old app to run. They don't want this one fixed but they want me to look at some of his interfaces so I can mimic them somewhat.

I'm thinking this thing was setup to explicity run on the domain and since it is now on my internal backbone and running on an IP this MAY be the problem.

What's happening is the second I try and access the app via a browser I get a Security Exception. The orginal app had an html page that literally did nothing except redirect them to this app. I added a jsp to stop the redirect but no matter what when I try and go into the app I get this damn exception.

I've been through ever file I can think of, the server.xml, the web.xml, and all the other xml files in the WEB-INF folder. I've also gone through the Tomcat config files to see if I could find anything.

I know Java (quite well) but again I no nothing about Struts. Are there any files I should be looking or entries in these files that could cause this?
13 years ago
Im doing some image rotation with the JAI and although its works fabulously I am getting a 1px black border on the top and left of the image when I rotate the image 90 degrees right OR left. When I do a 180 rotate it doesnt appear. Ive done a bunch of reading and can seem to find why this is happening or what I need to adjust to stop it. Here is the code I have so far:

PlanarImage src = JAI.create("fileload", imageName);
float flip = (float)Math.toRadians(angle);
float centerX = src.getWidth() / 2f;
float centerY = src.getHeight() /2f;
ParameterBlock pb = new ParameterBlock();
pb.addSource(src);
pb.add(centerX);
pb.add(centerY);
pb.add(flip);
pb.add(new InterpolationNearest());
PlanarImage changedImage = JAI.create("rotate", pb);

and then Im saving it with this code: (although I dont think this has anything to do with it)

java.io.FileOutputStream stream = new java.io.FileOutputStream(fullOut);
javax.media.jai.RenderedOp in = javax.media.jai.JAI.create("encode", changedImage, stream, "JPEG", null);

Anyone see what Im doing wrong or (more than likely) something Ive neglected to adjust in the code?

thanks
13 years ago
Thanks for the point in the right direction but Im still having the problem after adding the dispose() to each of the RenderedOp objects ... just cant seem to nail it down. Heres the updated ConvertTiff class:

class ConvertTiff{

protected String convertTiff(String tiffFile, javax.servlet.ServletContext sc, String galleryID) throws java.io.IOException{

String fileName = tiffFile.substring(0, tiffFile.indexOf("."));

String outputFile = fileName+".jpg";

String fullOut = sc.getRealPath("/images/galleries/"+galleryID+"/")+fileName+".jpg";

// Load the input image.
javax.media.jai.RenderedOp src = javax.media.jai.JAI.create("fileload", sc.getRealPath("/images/galleries/"+galleryID+"/")+tiffFile);

// Encode the file as a JPEG image.
java.io.FileOutputStream stream = new java.io.FileOutputStream(fullOut);
javax.media.jai.RenderedOp in = javax.media.jai.JAI.create("encode",src, stream, "JPEG", null);

// Store the image in the BMP format.
javax.media.jai.RenderedOp out = javax.media.jai.JAI.create("filestore",src, fullOut, "JPEG", null);

src.dispose();
stream.close();
in.dispose();
out.dispose();

java.io.File oldFile = new java.io.File(sc.getRealPath("/images/galleries/"+galleryID+"/")+tiffFile);

if (oldFile.exists()){
oldFile.delete();
}
return outputFile;
}
};

the code that calls this method remains the same, Im starting to wonder if its something there but I dont see anything else Ive forgotten to close prior to drop into the convert method..

thanks again!
[ August 08, 2005: Message edited by: DC Dalton ]
13 years ago
Im building an app that allows photos to be uploaded to a server. I had it going perfect with jpeg and gif images only but I wanted to support tiffs and if they uploaded a tiff, convert it to a jpeg.

Anyways I have it all working fine .... not 100% thrilled with the logic yet but its getting there. Im having a problem though deleting the tiffs once Ive created the new jpeg. I know its a file lock someplace because I cant delete them thru Windows explorer either but MAN I can find the stinking lock!

Here's the code that calls the convertor (its done with a try catch as they ARENT supposed to be uploading TIFFs:

java.io.FileInputStream in = new java.io.FileInputStream(sc.getRealPath("/images/galleries/"+galleryID+"/")+images.elementAt(x));
com.sun.image.codec.jpeg.JPEGImageDecoder decoder = null;
java.awt.image.BufferedImage image = null;

try{
decoder = com.sun.image.codec.jpeg.JPEGCodec.createJPEGDecoder(in);
image = decoder.decodeAsBufferedImage();
}
catch (com.sun.image.codec.jpeg.ImageFormatException ife) {
in.close();
String jpeg = new ConvertTiff().convertTiff((String)images.elementAt(x), sc, galleryID);
in = new java.io.FileInputStream(sc.getRealPath("/images/galleries/"+galleryID+"/")+jpeg);

decoder = com.sun.image.codec.jpeg.JPEGCodec.createJPEGDecoder(in);
image = decoder.decodeAsBufferedImage();
images.remove(x);
images.add(x, jpeg);
}
in.close();


AND here is the ConvertTiff class:

class ConvertTiff{

public String convertTiff(String tiffFile, javax.servlet.ServletContext sc, String galleryID) throws java.io.IOException{

String fileName = tiffFile.substring(0, tiffFile.indexOf("."));

String outputFile = fileName+".jpg";

String fullOut = sc.getRealPath("/images/galleries/"+galleryID+"/")+fileName+".jpg";

// Load the input image.
javax.media.jai.RenderedOp src = javax.media.jai.JAI.create("fileload", sc.getRealPath("/images/galleries/"+galleryID+"/")+tiffFile);

// Encode the file as a JPEG image.
java.io.FileOutputStream stream = new java.io.FileOutputStream(fullOut);
javax.media.jai.JAI.create("encode", src, stream, "JPEG", null);

// Store the image in the BMP format.
javax.media.jai.JAI.create("filestore", src, fullOut, "JPEG", null);

stream.close();

java.io.File oldFile = new java.io.File(sc.getRealPath("/images/galleries/"+galleryID+"/")+tiffFile);

if (oldFile.exists()){
oldFile.delete();
}
return outputFile;
}
};

Now I AM getting into the if oldFile.exists() with no problem ... but as I said its not deleting either in my app OR in Windows explorer so Ive got a lock on the file someplace ... Im just not seeing it..

Thanks in advance!
13 years ago
Im really getting into the JAI API and would like to find a good book to demystify some of it .. any suggestions?
13 years ago
Hi Ernest, I was reading thru some posts and spotted this one, I was curious why you say detatching data from the servlet when passing it to an object was so important.

I usually do this anyways as I have a "Data Cleaner" object that I pass all incoming data into and it returns a hashtable with that cleaned and trimmed data. But once in a while, when i dont have a bunch of data coming Ill pass the request object to the helper object, specifically if Im just slamming data into a db or something.

Can you elaborate on this topic? If there are ramifications Im not aware of Id like to know then so I can fix any potential problems before they occur. I handle several enterprise level sites that are just now starting to get traffic but may soon have tens of thousands of customers banging through the all the time.

Thanks for any info you can provide.
[ July 29, 2005: Message edited by: DC Dalton ]
13 years ago
I think you can do that on your front end (even though not a flawless idea).I have to look around but I remember something about an accept attribute in your form tag.. Ill have to look around though
13 years ago
You can but OH MAN does it create a nightmare of code!

First off ANY time you can seperate your backend code and your front end display its well worth taking the time! That way if you have a major design change you arent spending days, weeks and months trying to redo all your servlets and how they present the data!

I always recommend using external styles for formatting and external script files for any javascript you may need. Saves a lot of headaches!
13 years ago
Man Im stuck again. What I have is a servlet that must connect to a remote php app, send it some data and then collect the response from that php app back at the servlet. Then I have to do some things with the data etc etc.

Maybe Im way off base here but I was using an HttpURLConnection object to do this but I can seem to find a way to send the outside app the data I need to send and then grab the response from that app. I seem to be making a connection fine because my getResponseMessage() method is returning OK.

Anyone point me in the right direction here or have some example code (that would be awesome) .... Im really stuck here as Ive never dont this quite like this!

Thanks
14 years ago
No Im scaling images that are uploaded to a web site (scaling and optimizing) .... thats where the problems started
14 years ago
OK, I know this is going to sound strange but I tried over in the servlets section and have been beating my head trying to figure it out for two days..

what i need to do is replace this code (in a servlet):

Graphics2D graphics2D = thumbImage.createGraphics();
graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null);

With some other way to do the exact same thing without calling anything that will try to evoke the X-Windows server on a Linux server (we dont have it installed)

Ive got all the image reading and writing, scaling and everything else done but this section tries to call the X-Windows server and throws an exception. When I remove this from the code my images are scaled but come out solid black..

Im hoping someone here can help as Ive tried about everything I can think of!

thanks
14 years ago
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 ]
14 years ago
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!
14 years ago
Ahh yes the old "stupid users wont use the logout function on my site" problem... man I know it all too well. I would have to ask a few questions..

what kind of goodies are you storing in the users sessions? (hopefully not the magna carta)

are you setting the interval for time out with setMaxInactiveInterval? (if so for how long)

there is a semi decent way to remind them or force them to log out.. I actually just found it a while back but its not 100% (may help though) in Javascript there is a function called onbeforeunload... you place it in your body tag just like the onload .... now here's where it gets kind of tricky. You have to check to make sure they are closing the page or going to a site OTHER than your and if they are you can throw a confirm at them. If they click the OK on the confirm you can use a location.href to send them thru a logout servlet.. if not you set the onbeforeunload to null and they get no confirm. It a pai but I have used it in an online appplication and it worked pretty good.

the part that sucks about it is if they have javascript disabled, then it wont work.

You may want to look into that and HOW MUCH info you are storing in the sessions. If you are sucking up tons of memory I have a feeling you may be stuffing too much into them..

Hope this helps
14 years ago
not looking to do that at all ..... Im just sending the data back to the calling XMLHttpRequest object, which I was able to do with a simple out.print

thanks
14 years ago