本文整理汇总了Java中com.octo.captcha.service.image.ImageCaptchaService类的典型用法代码示例。如果您正苦于以下问题:Java ImageCaptchaService类的具体用法?Java ImageCaptchaService怎么用?Java ImageCaptchaService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ImageCaptchaService类属于com.octo.captcha.service.image包,在下文中一共展示了ImageCaptchaService类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import com.octo.captcha.service.image.ImageCaptchaService; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* @author covito
* @param config
* @throws ServletException
*/
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
WebApplicationContext appCtx = WebApplicationContextUtils
.getWebApplicationContext(getServletContext());
Map<String,ImageCaptchaService> m= BeanFactoryUtils.beansOfTypeIncludingAncestors(
appCtx, ImageCaptchaService.class);
if(ObjectUtil.empty(m)){
logger.error("spring config not found com.octo.captcha.service.image.ImageCaptchaService impl");
return;
}
String imageName=HttpCompUtil.getSvlConfig(config, "captchaService", null);
if(imageName==null&&m.size()==1){
captchaService=m.values().iterator().next();
}else{
captchaService=m.get(imageName);
}
if(captchaService==null){
logger.error("spring config ImageCaptchaService impl not only or captchaService not found");
return;
}
}
示例2: setUp
import com.octo.captcha.service.image.ImageCaptchaService; //导入依赖的package包/类
@Before
public void setUp() {
request = new MockHttpServletRequest();
request.setAttribute(HandlerMapping.INTROSPECT_TYPE_LEVEL_MAPPING, true);
request.setRequestURI("/ajax/insert");
request.setMethod("POST");
response = new MockHttpServletResponse();
adapter = new AnnotationMethodHandlerAdapter();
ajaxController = new AjaxController();
ajaxController.setAccountService(accountService);
// mock captcha service
captchaService = createMock(ImageCaptchaService.class);
expect(
captchaService.validateResponseForID(request.getSession()
.getId(), CORRECT_CAPTCHA_KEY)).andReturn(true);
expect(
captchaService.validateResponseForID(request.getSession()
.getId(), INCORRECT_CAPTCHA_KEY)).andReturn(false);
ajaxController.setCaptchaService(captchaService);
}
示例3: init
import com.octo.captcha.service.image.ImageCaptchaService; //导入依赖的package包/类
@Override
public void init() throws ServletException {
WebApplicationContext appCtx = WebApplicationContextUtils
.getWebApplicationContext(getServletContext());
captchaService = (ImageCaptchaService) BeanFactoryUtils
.beanOfTypeIncludingAncestors(appCtx, ImageCaptchaService.class);
session = (SessionProvider) BeanFactoryUtils
.beanOfTypeIncludingAncestors(appCtx, SessionProvider.class);
}
示例4: init
import com.octo.captcha.service.image.ImageCaptchaService; //导入依赖的package包/类
@Override
public void init() throws ServletException {
WebApplicationContext appCtx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
if(appCtx != null){
captchaService = BeanFactoryUtils.beanOfTypeIncludingAncestors(appCtx, ImageCaptchaService.class);
}
}
示例5: flushNewCaptchaToResponse
import com.octo.captcha.service.image.ImageCaptchaService; //导入依赖的package包/类
/**
* retrieve a new ImageCaptcha using ImageCaptchaService and flush it to the response.<br/> Captcha are localized
* using request locale.<br/>
* <p/>
* This method returns a 404 to the client instead of the image if the request isn't correct (missing parameters,
* etc...)..<br/> The log may be null.<br/>
*
* @param theRequest the request
* @param theResponse the response
* @param log a commons logger
* @param service an ImageCaptchaService instance
*
* @throws java.io.IOException if a problem occurs during the jpeg generation process
*/
public static void flushNewCaptchaToResponse(HttpServletRequest theRequest,
HttpServletResponse theResponse,
Log log,
ImageCaptchaService service,
String id,
Locale locale)
throws IOException {
// call the ImageCaptchaService method to retrieve a captcha
byte[] captchaChallengeAsJpeg = null;
ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream();
try {
BufferedImage challenge =
service.getImageChallengeForID(id, locale);
// the output stream to render the captcha image as jpeg into
ImageIO.write(challenge, "jpg", jpegOutputStream);
} catch (IllegalArgumentException e) {
// log a security warning and return a 404...
if (log != null && log.isWarnEnabled()) {
log.warn(
"There was a try from "
+ theRequest.getRemoteAddr()
+ " to render an captcha with invalid ID :'" + id
+ "' or with a too long one");
theResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
}
captchaChallengeAsJpeg = jpegOutputStream.toByteArray();
// render the captcha challenge as a JPEG image in the response
theResponse.setHeader("Cache-Control", "no-store");
theResponse.setHeader("Pragma", "no-cache");
theResponse.setDateHeader("Expires", 0);
theResponse.setContentType("image/jpeg");
ServletOutputStream responseOutputStream =
theResponse.getOutputStream();
responseOutputStream.write(captchaChallengeAsJpeg);
responseOutputStream.flush();
responseOutputStream.close();
}
示例6: getInstance
import com.octo.captcha.service.image.ImageCaptchaService; //导入依赖的package包/类
public static ImageCaptchaService getInstance(){
return instance;
}
示例7: setCaptchaService
import com.octo.captcha.service.image.ImageCaptchaService; //导入依赖的package包/类
public void setCaptchaService(ImageCaptchaService captchaService) {
this.captchaService = captchaService;
}
示例8: captchaService
import com.octo.captcha.service.image.ImageCaptchaService; //导入依赖的package包/类
@Bean
public ImageCaptchaService captchaService() {
return new GenericManageableCaptchaService(imageEngine(), MIN_STORAGE_DELAY, MAX_STORAGE_DELAY);
}
示例9: getInstance
import com.octo.captcha.service.image.ImageCaptchaService; //导入依赖的package包/类
/**
* Liefert die Instanz des Captcha-Services zurück.
* @return Instanz des Captcha-Services
*/
public static ImageCaptchaService getInstance() {
return instance;
}