[JBoss Seam] - Re: Seam Captcha configuration
by wise_guybg
While waiting for the team to provide a way to configure captcha I have elaborated a tweak that I want make sure is correct. I have subclassed CaptchaImage like so:
| @Startup
| @Scope(APPLICATION)
| @Name("mycaptchaimage")
| @Intercept(NEVER)
| @Install(precedence = BUILT_IN,
| classDependencies = "com.octo.captcha.service.image.ImageCaptchaService")
| public class MyCaptchaImage extends CaptchaImage {
|
| private ImageCaptchaService service;
|
| public static MyCaptchaImage instance() {
| if (!Contexts.isApplicationContextActive()) {
| throw new IllegalStateException("No application context active");
| }
| return (MyCaptchaImage) Contexts.getApplicationContext().get(MyCaptchaImage.class);
| }
|
| @Override
| public void create() {
| service = new DefaultManageableImageCaptchaService(
| new FastHashMapCaptchaStore(),
| new MyImageCaptchaEngine(),
| 180,
| 100000,
| 75000);
| }
|
| @Override
| protected String getResourcePath() {
| return "/mycaptcha";
| }
|
| @Override
| public boolean validateResponse(String id, String response) {
| try {
| return service.validateResponseForID(id, response);
| }
| catch (CaptchaServiceException cse) {
| return false;
| }
| }
|
| @Override
| public void getResource(HttpServletRequest request, HttpServletResponse response) throws IOException {
| ByteArrayOutputStream out = new ByteArrayOutputStream();
|
| try {
| Lifecycle.beginRequest(getServletContext(), request.getSession(), request);
|
| String captchaId = request.getQueryString();
|
| BufferedImage challenge = service.getImageChallengeForID(captchaId, request.getLocale());
|
| ImageIO.write(challenge, "jpeg", out);
| }
| catch (IllegalArgumentException e) {
| response.sendError(HttpServletResponse.SC_NOT_FOUND);
| return;
| }
| catch (CaptchaServiceException e) {
| response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
| return;
| }
| finally {
| Lifecycle.endRequest();
| }
|
| response.setHeader("Cache-Control", "no-store");
| response.setHeader("Pragma", "no-cache");
| response.setDateHeader("Expires", 0);
| response.setContentType("image/jpeg");
| response.getOutputStream().write(out.toByteArray());
| response.getOutputStream().flush();
| response.getOutputStream().close();
| }
|
| }
|
The only change in the usage is that now the resource path is /mycaptcha. I have tested it and is seems to work. Is it OK to subclass the component like this?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4074351#4074351
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4074351
18Â years, 11Â months
[JBoss Seam] - Re: h:commandLink behaviour - decode, encode
by msznapka
Thank you for answer Pete
So you think that loading data from database should be done inside action method (here doSomething)?
What about first page load, where no action was fired?
first page load - getData
action load - getData, action, getData
For information - this is event scoped seam component and data are loaded from database. Such loaded data depends on your action, if no action, than load default data.
So here is code:
| @Name("event")
| @Scope(EVENT)
| public class Event {
| List<Item> data = null;
| getData ... return data;
| setData ... this.data = data;
|
| doSomething() {
| if(linkParameter == null)
| loadDefaultDataFromDatabase();
| else
| loadDataFromDatabase(linkParameter);
| }
| ...
|
so if you access page for first time, null data are returned, that is why i thought that loading data must be inside getters methods
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4074345#4074345
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4074345
18Â years, 11Â months