Re: [Wicket-user] Issue of having a webpage return binary content

2006-11-21 Thread Eelco Hillenius
For binary output, use a (web)resource. For instance, something like this:

WebResource export = new WebResource() {

  @Override
  public IResourceStream getResourceStream() {
CharSequence discounts = DataBase.getInstance()
.exportDiscounts();
return new StringResourceStream(discounts, text/plain);
  }

  @Override
  protected void setHeaders(WebResponse response) {
super.setHeaders(response);
response.setAttachmentHeader(discounts.csv);
  }
};
export.setCacheable(false);

new ResourceLink(this, exportLink, export);


Eelco

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


[Wicket-user] Issue of having a webpage return binary content

2006-11-21 Thread Carfield Yim
I need to create a webpage output captcha image to user, actually that
is done and work for me to output binary to outputstream. However
there is MarkupNotFoundException appear at my log file. I guess I can
put a dummy HTML at the classpath, however, can I not doing that but
tell wicket don't lookup markup?

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] Issue of having a webpage return binary content

2006-11-21 Thread Carfield Yim
Thanks for introducting the class to me, however look like this
missing some object like session and request which I need

In fact I am going to output captcha according to jCaptcha example, it
need request and session as follow. But can I do the same at
WebResource?

public ImageCaptcha() throws ImageFormatException, IOException {
super();
final WebRequest httpServletRequest = (WebRequest)getRequest();
final WebResponse httpServletResponse = (WebResponse)getResponse();
byte[] captchaChallengeAsJpeg = null;
// the output stream to render the captcha image as jpeg into
ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream();
// get the session id that will identify the generated captcha.
// the same id must be used to validate the response, the
session id is a good candidate!
String captchaId = getSession().getId();
// call the ImageCaptchaService getChallenge method
BufferedImage challenge = new
DefaultManageableImageCaptchaService().getImageChallengeForID(captchaId,

 httpServletRequest.getLocale());
// a jpeg encoder
JPEGImageEncoder jpegEncoder =
JPEGCodec.createJPEGEncoder(jpegOutputStream);
jpegEncoder.encode(challenge);
captchaChallengeAsJpeg = jpegOutputStream.toByteArray();

// flush it in the response
httpServletResponse.setHeader(Cache-Control, no-store);
httpServletResponse.setHeader(Pragma, no-cache);
httpServletResponse.setDateHeader(Expires, 0);
httpServletResponse.setContentType(image/jpeg);
OutputStream responseOutputStream =
httpServletResponse.getOutputStream();
responseOutputStream.write(captchaChallengeAsJpeg);
responseOutputStream.flush();
responseOutputStream.close();
}
On 11/22/06, Eelco Hillenius [EMAIL PROTECTED] wrote:
 For binary output, use a (web)resource. For instance, something like this:

 WebResource export = new WebResource() {

   @Override
   public IResourceStream getResourceStream() {
 CharSequence discounts = DataBase.getInstance()
 .exportDiscounts();
 return new StringResourceStream(discounts, text/plain);
   }

   @Override
   protected void setHeaders(WebResponse response) {
 super.setHeaders(response);
 response.setAttachmentHeader(discounts.csv);
   }
 };
 export.setCacheable(false);

 new ResourceLink(this, exportLink, export);


 Eelco

 -
 Take Surveys. Earn Cash. Influence the Future of IT
 Join SourceForge.net's Techsay panel and you'll get the chance to share your
 opinions on IT  business topics through brief surveys - and earn cash
 http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
 ___
 Wicket-user mailing list
 Wicket-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/wicket-user


-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] Issue of having a webpage return binary content

2006-11-21 Thread Eelco Hillenius
You can always do RequestCycle.get() (or
((WebRequest)RequestCycle.get())) to get the current request cycle, on
which you can then call get(Web)Request and get(Web)Response

Eelco

On 11/21/06, Carfield Yim [EMAIL PROTECTED] wrote:
 Thanks for introducting the class to me, however look like this
 missing some object like session and request which I need

 In fact I am going to output captcha according to jCaptcha example, it
 need request and session as follow. But can I do the same at
 WebResource?

 public ImageCaptcha() throws ImageFormatException, IOException {
 super();
 final WebRequest httpServletRequest = (WebRequest)getRequest();
 final WebResponse httpServletResponse = (WebResponse)getResponse();
 byte[] captchaChallengeAsJpeg = null;
 // the output stream to render the captcha image as jpeg into
 ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream();
 // get the session id that will identify the generated captcha.
 // the same id must be used to validate the response, the
 session id is a good candidate!
 String captchaId = getSession().getId();
 // call the ImageCaptchaService getChallenge method
 BufferedImage challenge = new
 DefaultManageableImageCaptchaService().getImageChallengeForID(captchaId,

  httpServletRequest.getLocale());
 // a jpeg encoder
 JPEGImageEncoder jpegEncoder =
 JPEGCodec.createJPEGEncoder(jpegOutputStream);
 jpegEncoder.encode(challenge);
 captchaChallengeAsJpeg = jpegOutputStream.toByteArray();

 // flush it in the response
 httpServletResponse.setHeader(Cache-Control, no-store);
 httpServletResponse.setHeader(Pragma, no-cache);
 httpServletResponse.setDateHeader(Expires, 0);
 httpServletResponse.setContentType(image/jpeg);
 OutputStream responseOutputStream =
 httpServletResponse.getOutputStream();
 responseOutputStream.write(captchaChallengeAsJpeg);
 responseOutputStream.flush();
 responseOutputStream.close();
 }
 On 11/22/06, Eelco Hillenius [EMAIL PROTECTED] wrote:
  For binary output, use a (web)resource. For instance, something like this:
 
  WebResource export = new WebResource() {
 
@Override
public IResourceStream getResourceStream() {
  CharSequence discounts = DataBase.getInstance()
  .exportDiscounts();
  return new StringResourceStream(discounts, text/plain);
}
 
@Override
protected void setHeaders(WebResponse response) {
  super.setHeaders(response);
  response.setAttachmentHeader(discounts.csv);
}
  };
  export.setCacheable(false);
 
  new ResourceLink(this, exportLink, export);
 
 
  Eelco
 
  -
  Take Surveys. Earn Cash. Influence the Future of IT
  Join SourceForge.net's Techsay panel and you'll get the chance to share your
  opinions on IT  business topics through brief surveys - and earn cash
  http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
  ___
  Wicket-user mailing list
  Wicket-user@lists.sourceforge.net
  https://lists.sourceforge.net/lists/listinfo/wicket-user
 

 -
 Take Surveys. Earn Cash. Influence the Future of IT
 Join SourceForge.net's Techsay panel and you'll get the chance to share your
 opinions on IT  business topics through brief surveys - and earn cash
 http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
 ___
 Wicket-user mailing list
 Wicket-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/wicket-user


-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] Issue of having a webpage return binary content

2006-11-21 Thread Carfield Yim
Thanks, in fact I get a even nicer way generate image, which is just
use Image() object from wicket, thanks everyone

On 11/22/06, Eelco Hillenius [EMAIL PROTECTED] wrote:
 You can always do RequestCycle.get() (or
 ((WebRequest)RequestCycle.get())) to get the current request cycle, on
 which you can then call get(Web)Request and get(Web)Response

 Eelco

 On 11/21/06, Carfield Yim [EMAIL PROTECTED] wrote:
  Thanks for introducting the class to me, however look like this
  missing some object like session and request which I need
 
  In fact I am going to output captcha according to jCaptcha example, it
  need request and session as follow. But can I do the same at
  WebResource?
 
  public ImageCaptcha() throws ImageFormatException, IOException {
  super();
  final WebRequest httpServletRequest = (WebRequest)getRequest();
  final WebResponse httpServletResponse = (WebResponse)getResponse();
  byte[] captchaChallengeAsJpeg = null;
  // the output stream to render the captcha image as jpeg into
  ByteArrayOutputStream jpegOutputStream = new 
  ByteArrayOutputStream();
  // get the session id that will identify the generated captcha.
  // the same id must be used to validate the response, the
  session id is a good candidate!
  String captchaId = getSession().getId();
  // call the ImageCaptchaService getChallenge method
  BufferedImage challenge = new
  DefaultManageableImageCaptchaService().getImageChallengeForID(captchaId,
 
   httpServletRequest.getLocale());
  // a jpeg encoder
  JPEGImageEncoder jpegEncoder =
  JPEGCodec.createJPEGEncoder(jpegOutputStream);
  jpegEncoder.encode(challenge);
  captchaChallengeAsJpeg = jpegOutputStream.toByteArray();
 
  // flush it in the response
  httpServletResponse.setHeader(Cache-Control, no-store);
  httpServletResponse.setHeader(Pragma, no-cache);
  httpServletResponse.setDateHeader(Expires, 0);
  httpServletResponse.setContentType(image/jpeg);
  OutputStream responseOutputStream =
  httpServletResponse.getOutputStream();
  responseOutputStream.write(captchaChallengeAsJpeg);
  responseOutputStream.flush();
  responseOutputStream.close();
  }
  On 11/22/06, Eelco Hillenius [EMAIL PROTECTED] wrote:
   For binary output, use a (web)resource. For instance, something like this:
  
   WebResource export = new WebResource() {
  
 @Override
 public IResourceStream getResourceStream() {
   CharSequence discounts = DataBase.getInstance()
   .exportDiscounts();
   return new StringResourceStream(discounts, text/plain);
 }
  
 @Override
 protected void setHeaders(WebResponse response) {
   super.setHeaders(response);
   response.setAttachmentHeader(discounts.csv);
 }
   };
   export.setCacheable(false);
  
   new ResourceLink(this, exportLink, export);
  
  
   Eelco
  
   -
   Take Surveys. Earn Cash. Influence the Future of IT
   Join SourceForge.net's Techsay panel and you'll get the chance to share 
   your
   opinions on IT  business topics through brief surveys - and earn cash
   http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
   ___
   Wicket-user mailing list
   Wicket-user@lists.sourceforge.net
   https://lists.sourceforge.net/lists/listinfo/wicket-user
  
 
  -
  Take Surveys. Earn Cash. Influence the Future of IT
  Join SourceForge.net's Techsay panel and you'll get the chance to share your
  opinions on IT  business topics through brief surveys - and earn cash
  http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
  ___
  Wicket-user mailing list
  Wicket-user@lists.sourceforge.net
  https://lists.sourceforge.net/lists/listinfo/wicket-user
 

 -
 Take Surveys. Earn Cash. Influence the Future of IT
 Join SourceForge.net's Techsay panel and you'll get the chance to share your
 opinions on IT  business topics through brief surveys - and earn cash
 http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
 ___
 Wicket-user mailing list
 Wicket-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/wicket-user


-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys - and earn cash