byte[] captchaChallengeAsJpeg = null;
ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream();
try {
ApplicationContext ctx = WebApplicationContextUtils
.getRequiredWebApplicationContext(getServletContext());
ImageCaptchaService imageCaptchaService = (ImageCaptchaService) ctx
.getBean(captchaServiceName);
String captchaId = httpServletRequest.getSession().getId();
BufferedImage challenge = imageCaptchaService
.getImageChallengeForID(captchaId, httpServletRequest
.getLocale());
JPEGImageEncoder jpegEncoder = JPEGCodec
.createJPEGEncoder(jpegOutputStream);