Fixing captcha error because of OpenJDK

This commit is contained in:
Pablo 2010-11-24 00:09:06 +01:00
parent 862a53e147
commit dfba30f83f
2 changed files with 10 additions and 15 deletions

View File

@ -22,6 +22,7 @@ package com.wisemapping.controller;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -54,22 +55,16 @@ public class CaptchaController
final String captchaId = request.getSession().getId(); final String captchaId = request.getSession().getId();
// call the ImageCaptchaService getChallenge method // call the ImageCaptchaService getChallenge method
final BufferedImage challenge = captchaService.getImageChallengeForID(captchaId,request.getLocale()); final BufferedImage challenge = captchaService.getImageChallengeForID(captchaId,request.getLocale());
// a jpeg encoder // flush it in the response
final JPEGImageEncoder jpegEncoder = JPEGCodec.createJPEGEncoder(jpegOutputStream); response.setHeader("Cache-Control", "no-store");
jpegEncoder.encode(challenge); response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);
captchaChallengeAsJpeg = jpegOutputStream.toByteArray(); response.setContentType("image/jpeg");
final ServletOutputStream responseOutputStream = response.getOutputStream();
// flush it in the response ImageIO.write(challenge, "png", responseOutputStream);
response.setHeader("Cache-Control", "no-store"); responseOutputStream.flush();
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpeg");
final ServletOutputStream responseOutputStream = response.getOutputStream();
responseOutputStream.write(captchaChallengeAsJpeg);
responseOutputStream.flush();
responseOutputStream.close(); responseOutputStream.close();
return null; return null;
} }