return createCaptcha(request, null);
}
public CaptchaBean createCaptcha(HttpServletRequest request, String text)
{
CaptchaBean captcha;
if ( text == null )
captcha = new CaptchaBeanImpl(captchaConfig);
else
captcha = new CaptchaBeanImpl(captchaConfig, text);
if (captchaConfig.isUseImageBackground())
{
captcha.setBackgroundImage(this.background);
}
FileOutputStream fs = null;
ServerData url = new ServerData(request);
String imageUrl = url.getBasePath() + url.getContextPath() + captchaConfig.getDirectory() + "/" + captcha.getImageId() + captchaConfig.getImageFormat();
captcha.setImageURL(imageUrl);
String imagePath = this.captchasRealPath + "/" + captcha.getImageId() + captchaConfig.getImageFormat();
captcha.init();
try
{
fs = new FileOutputStream(imagePath);
byte[] data = captcha.getImageBytes();
fs.write(data);
this.removalCache.insert(new RemovableResource(captcha.getImageId(), imagePath));
}
catch (IOException e)
{
log.error("Unexpected error during writing captch image.", e);
imageUrl = "";