I think youl will have to change the code in your Portlet class. In my code I have my
WebFormPortlet.java with this code in the
saveData method:
1
2
3 if (requireCaptcha) {
4 try {
5 //CaptchaUtil.check(actionRequest);
6 String enteredCaptchaText = ParamUtil.getString(uploadRequest, "captchaText");
7
8 PortletSession session = actionRequest.getPortletSession();
9 //String captchaText = getCaptchaValueFromSession(session);
10 String captchaText = "";
11 Enumeration<String> atNames = session.getAttributeNames();
12 while (atNames.hasMoreElements()) {
13 String name = atNames.nextElement();
14 if (name.contains("CAPTCHA_TEXT")) {
15 captchaText = (String) session.getAttribute(name);
16 }
17 }
18 if (Validator.isNull(captchaText)) {
19 throw new Exception("Internal Error! Captcha text not found in session");
20 }
21 if (!StringUtils.equals(captchaText, enteredCaptchaText)) {
22 throw new Exception("Invalid captcha text. Please reenter.");
23 }
24 }
25 catch (CaptchaTextException cte) {
26 SessionErrors.add(
27 actionRequest, CaptchaTextException.class.getName());
28
29 return;
30 }
31 }
And this would be my
serveResource method:
1
2
3 public void serveResource(
4 ResourceRequest resourceRequest, ResourceResponse resourceResponse)
5 throws IOException, PortletException {
6
7 String cmd = ParamUtil.getString(resourceRequest, Constants.CMD);
8
9 try {
10 if (cmd.equals("captcha")) {
11 //serveCaptcha(resourceRequest, resourceResponse);
12 com.liferay.portal.kernel.captcha.CaptchaUtil.serveImage(resourceRequest, resourceResponse);
13 }
14 else if (cmd.equals("export")) {
15 exportData(resourceRequest, resourceResponse);
16 }
17 }
18 catch (Exception e) {
19 _log.error(e, e);
20 }
21 }
Try if this is a valid solution for your problem.
Please sign in to flag this as inappropriate.