I'm going to try it in my application. Thanks.

Konstantin Ignatyev <[EMAIL PROTECTED]> wrote: Just did the following and it 
seems to work beautifully



public class JCaptchaServlet extends HttpServlet {


  protected void doGet(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {

    String captchaID = request.getSession(true).getId();

    // call the ManageableImageCaptchaService methods
    byte[] captchaChallengeAsJpeg = null;
    ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream();
    try {
      ImageCaptchaService srv = App.getCaptchaService();
      BufferedImage challenge =  srv.getImageChallengeForID(captchaID, 
request.getLocale());
      Object challengeString = srv.getQuestionForID(captchaID, 
request.getLocale());
      // the output stream to render the captcha image as jpeg into

      // a jpeg encoder
      JPEGImageEncoder jpegEncoder =  
JPEGCodec.createJPEGEncoder(jpegOutputStream);
      jpegEncoder.encode(challenge);
    } catch (IllegalArgumentException e) {
      // log a security warning and return a 404...
//            if (log.isWarnEnabled())
//            {
//                log.warn(
//                    "There was a try from "
//                        + request.getRemoteAddr()
//                        + " to render an URL without ID"
//                        + " or with a too long one");
//                theResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
      return;
//            }
    } catch (CaptchaServiceException e) {
      // log and return a 404 instead of an image...
//            log.warn(
//                "Error trying to generate a captcha and "
//                    + "render its challenge as JPEG",
//                e);
      response.sendError(HttpServletResponse.SC_NOT_FOUND);
      return;
    }

    captchaChallengeAsJpeg = jpegOutputStream.toByteArray();

    // render the captcha challenge as a JPEG image in the response
    response.setHeader("Cache-Control", "no-store");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);

    response.setContentType("image/jpeg");
    ServletOutputStream responseOutputStream =
        response.getOutputStream();
    responseOutputStream.write(captchaChallengeAsJpeg);
  }


}

------------
private static ImageCaptchaService captchaService;
  private static Object captchaGuard = new Object();

  public static ImageCaptchaService getCaptchaService() {
    synchronized (captchaGuard) {
      if (captchaService == null) {
        captchaService = new EhcacheManageableImageCaptchaService( new 
SimpleListImageCaptchaEngine() , 180, 100000){

        };
      }
      return captchaService;
    }
  }

----------------------



Validation

@InjectObject( "service:tapestry.globals.HttpServletRequest")
  public abstract HttpServletRequest getHttpRequest();

............
if( App.getCaptchaService().validateResponseForID( 
getHttpRequest().getSession(true).getId(), getCaptchaAnswer() )){
        System.out.println("CAPTCHA - Pass");
      }else{



Oscar Picasso  wrote: Do you have a code example of such an ImageCaptchaServlet?

Daniel Lydiard  wrote: I'm using Jcaptcha with my tapestry application.

1. Load the ImageCaptchaServlet in your web.xml.


jcaptcha

com.foo.ImageCaptchaServlet

1






jcaptcha

/jcaptcha




2. Do something like this in a component class method to get the captcha 
question.
captchaId = getPage().getRequest().getSession(true).getId();
return CaptchaServiceSingleton.getInstance().getQuestionForID(captchaId);

3. Point to the servlet for the captchaimage in your component .

4.  To validate the user response
captchaId = getRequest().getSession(true).getId();

return 
CaptchaServiceSingleton.getInstance().validateResponseForID(captchaId, 
userResponse);


Hope this helps.


----- Original Message ----- 
From: "Oscar Picasso" 
To: "Tapestry users" 
Sent: Sunday, April 16, 2006 11:47 AM
Subject: Re: Looking for a CATCHPA


>I have taken a look. But I have no idea where to start. The api javadoc has 
>only one class:  JCaptchaCommentAuthenticator. It seems there is a problem 
>with the site.
>
> Have you worked with JCaptcha? And do you know where to start?
>
> Oscar
>
>
>
> J�r�me BERNARD  wrote: Have a loot at 
> http://jcaptcha.sourceforge.net/
>
> Regards,
> J�r�me.
>
> On 4/16/06, Oscar Picasso  wrote:
>> Hi,
>>
>> I'm looking for a CATCHPA library to use with my Tapestry application. 
>> I'm looking for something easy to use and efficient.
>>
>> I welcome any advice.
>>
>> Oscar
>>
>>
>> ---------------------------------
>> Blab-away for as little as 1�/min. Make  PC-to-Phone Calls using Yahoo! 
>> Messenger with Voice.
>>
>
>
> --
> J�r�me BERNARD,
> Kalixia, SARL.
> http://weblog.kalixia.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
>
> ---------------------------------
> Yahoo! Messenger with Voice. PC-to-Phone calls for ridiculously low rates. 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


Konstantin Ignatyev




PS: If this is a typical day on planet earth, humans will add fifteen million 
tons of carbon to the atmosphere, destroy 115 square miles of tropical 
rainforest, create seventy-two miles of desert, eliminate between forty to one 
hundred species, erode seventy-one million tons of topsoil, add 2,700 tons of 
CFCs to the stratosphere, and increase their population by 263,000

Bowers, C.A.  The Culture of Denial:  Why the Environmental Movement Needs a 
Strategy for Reforming Universities and Public Schools.  New York:  State 
University of New York Press, 1997: (4) (5) (p.206)

                
---------------------------------
New Yahoo! Messenger with Voice. Call regular phones from your PC and save big.

Reply via email to