开发者

Error when using jcaptcha plugin with grails 1.3.7

Hi I am facing following error when trying to use jcaptcha plugin with grails 1.3.7.

org.codehaus.groovy.runtime.typehandling.GroovyCastException:
  Cannot cast object '{}' with class 'groovy.util.ConfigObject' to class 'com.octo.captcha.service.CaptchaService' due to:
  groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.octo.captcha.service.CaptchaService(groovy.util.ConfigObject)
    at org.grails.plugin.jcaptcha.JcaptchaService.getCaptchaService(JcaptchaService.groovy:42)
    at org.grails.plugin.jcaptcha.JcaptchaService$$FastClassByCGLIB$$98874858.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
    at org.grails.plugin.jcaptcha.JcaptchaService$$EnhancerByCGLIB$$468f85f9.getCaptchaService(<generated>)
    at org.grails.plugin.jcaptcha.JcaptchaService$get开发者_JS百科CaptchaService.call(Unknown Source)
    at org.grails.plugin.jcaptcha.JcaptchaController$_closure1.doCall(JcaptchaController.groovy:29)
    at org.grails.plugin.jcaptcha.JcaptchaController$_closure1.doCall(JcaptchaController.groovy)
    at java.lang.Thread.run(Thread.java:619)

Any pointers on same will be really helpful. Thanks in advance.


A String like "captcha1" (if you named your captcha in the Config.groovy like that) is expected by the jcaptchaService.validateResponse as first argument to identify which captcha-instance to use.

Config.groovy Exmpl.:

...
captchas {
   captcha1 = new GenericManageableCaptchaService(...)
}
...

for the view use the captcha like that:

<jcaptcha:jpeg name="captcha1" /> ...
<g:textField name="user_typed_captcha" value="" />

and in the controller something like that:

if(jcaptchaService.validateResponse("captcha1", session.id, params.user_typed_captcha)) {
   log.info("CAPTCHA WAS VALID!")
} else {
   log.info("CAPTCHA WAS NOT VALID!")
}

This should fix your issue using the jcaptcha in controllers.

For me using the jcaptchaService in CommandObjects did not worked out. I think the reason was that validation method was for some reasons called twice, which made the capture invalid . I used Grails 1.3.7.


When using JCaptcha with Grails, you need to "define captchas" : that means you must specify the rules according to which Jcaptchas are generated.

Your captchas are defined in your conf/Config.groovy file :

jcaptchas {
    captcha1 = …
    captcha2 = …
}

More info on how to create these @ http://www.grails.org/JCaptcha+Plugin

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜