for (int i = 0; i < LENGTH; i++) {
final String column = String.valueOf(RANDOM.nextInt(
MAX_CAPTCHA_COLUM));
captcha += column;
final String imageName = row + "/" + column + ".png";
final Image captchaChar = CAPTCHAS.get(imageName);
final Composite composite = ImagesServiceFactory.makeComposite(
captchaChar, i * WIDTH_CAPTCHA_CHAR, 0,
1.0F, Composite.Anchor.TOP_LEFT);
composites.add(composite);
}
final HttpSession httpSession = request.getSession();
LOGGER.log(Level.FINER, "Captcha[{0}] for session[id={1}]",
new Object[]{captcha,
httpSession.getId()});
httpSession.setAttribute(CAPTCHA, captcha);
final Image captchaImage =
IMAGE_SERVICE.composite(composites,
WIDTH_CAPTCHA_CHAR * LENGTH,
HEIGHT_CAPTCHA_CHAR,
0);
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/png");
final OutputStream outputStream = response.getOutputStream();
outputStream.write(captchaImage.getImageData());
outputStream.close();
}