Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Liferay Captcha validation Rajesh GR March 24, 2010 10:48 PM
RE: Liferay Captcha validation Sandeep Nair March 24, 2010 11:19 PM
RE: Liferay Captcha validation Rajesh GR March 25, 2010 12:11 AM
RE: Liferay Captcha validation Sandeep Nair March 25, 2010 12:18 AM
RE: Liferay Captcha validation Rajesh GR March 25, 2010 12:21 AM
RE: Liferay Captcha validation Sandeep Nair March 25, 2010 12:23 AM
RE: Liferay Captcha validation Rajesh GR March 25, 2010 12:30 AM
RE: Liferay Captcha validation Arsh g March 11, 2011 2:34 AM
RE: Liferay Captcha validation Arsh g March 22, 2011 11:08 PM
RE: Liferay Captcha validation Sandeep Nair March 25, 2010 1:26 AM
RE: Liferay Captcha validation Rajesh GR March 25, 2010 1:49 AM
RE: Liferay Captcha validation Sandeep Nair March 25, 2010 2:11 AM
RE: Liferay Captcha validation Rajesh GR March 25, 2010 2:39 AM
RE: Liferay Captcha validation Sandeep Nair March 25, 2010 2:42 AM
RE: Liferay Captcha validation Sandeep Nair March 25, 2010 2:45 AM
RE: Liferay Captcha validation Rajesh GR March 25, 2010 2:46 AM
RE: Liferay Captcha validation Sandeep Nair March 25, 2010 2:57 AM
RE: Liferay Captcha validation Rajesh GR March 25, 2010 3:28 AM
RE: Liferay Captcha validation Alexey Kakunin March 25, 2010 2:08 PM
RE: Liferay Captcha validation Rajesh GR March 26, 2010 3:00 AM
RE: Liferay Captcha validation Hadrien Mens-Pellen April 7, 2011 1:09 AM
RE: Liferay Captcha validation Danial Mustofa Habibi December 28, 2011 6:28 AM
RE: Liferay Captcha validation Sandeep Nair December 28, 2011 9:34 PM
RE: Liferay Captcha validation Danial Mustofa Habibi December 29, 2011 3:36 AM
RE: Liferay Captcha validation Sandeep Nair December 29, 2011 3:36 AM
RE: Liferay Captcha validation Danial Mustofa Habibi December 29, 2011 4:02 AM
RE: Liferay Captcha validation Sandeep Nair December 29, 2011 5:20 AM
RE: Liferay Captcha validation Danial Mustofa Habibi December 29, 2011 4:35 PM
Rajesh GR
Liferay Captcha validation
March 24, 2010 10:48 PM
Answer

Rajesh GR

Rank: Regular Member

Posts: 157

Join Date: February 7, 2010

Recent Posts

Hi,

i had created a new signup portlet and need to use the liferay captcha in tat portlet.

for tat i had used the liferay captcha in my insert.jsp like below.

  1
  2<%@ page contentType="text/html; charset=UTF-8" %>
  3<%@ include file="/WEB-INF/jsp/forgotpassword/include.jsp" %>
  4
  5<%@ page import="javax.servlet.*"%>
  6<%@ page import="javax.servlet.http.*"%>
  7<%@ page import="javax.portlet.*"%>
  8<%@ page import="javax.portlet.ResourceRequest"%>
  9<%@ page import="javax.portlet.ResourceResponse"%>
 10<%@ page import="java.util.*"%>
 11<%@ page import="java.io.*"%>
 12<%@ page import="java.awt.*"%>
 13<%@ page import="java.awt.image.*"%>
 14<%@ page import="javax.imageio.*"%>
 15<%@ page import="java.awt.geom.*"%>
 16<%@ page import="com.esic.portal.html.signup.util.CaptchaTextProducer"%>
 17<%@ page import="com.esic.portal.html.signup.controller.SignUpController"%>
 18<%@ page import="com.esic.portal.html.signup.domain.Signup"%>
 19<%@ page import="com.esic.portal.html.signup.util.Base64"%>
 20
 21
 22<%@ page import="com.liferay.portal.util.PortalUtil"%>
 23<%@ page import="com.liferay.portal.kernel.captcha.CaptchaTextException"%>
 24<%@ page import="com.liferay.portal.kernel.captcha.CaptchaUtil"%>
 25<%@ page import="com.liferay.portal.kernel.captcha.Captcha"%>
 26
 27<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
 28<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
 29<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
 30
 31<%@ taglib uri="http://liferay.com/tld/journal" prefix="jnl"%>
 32<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet"%>
 33<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme"%>
 34<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>
 35
 36
 37<portlet:defineObjects/>
 38
 39<portlet:actionURL var="captchaURL"/>
 40<liferay-theme:defineObjects />
 41
 42<portlet:actionURL var="formAction">
 43    <portlet:param name="action" value="insert"/>
 44</portlet:actionURL>
 45
 46<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 47<link rel="stylesheet" href="/ESICInternetAuthServicePortlets/css/internet_auth_service_style.css" type="text/css" />
 48
 49<script language="Javascript">
 50
 51    function emailValidator(elem, helperMsg) {
 52        var emailExp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
 53        if(elem.value.match(emailExp)){
 54            return true;
 55        }else{
 56            alert(helperMsg);
 57            elem.focus();
 58            return false;
 59        }
 60    }
 61
 62    function removeMessage()
 63    {
 64        valIndex=0;
 65        var tableElement = document.getElementById("insert1");
 66        var rowLength = tableElement.rows.length;
 67        for (var i=0; i<(rowLength); i++)
 68        {
 69            tableElement.deleteRow('');
 70        }
 71    }
 72
 73    function guestHome() {
 74        location.href = "http://portal.esic.co.in:8080/webspace";
 75    }
 76
 77    function isSpclChar(elem, helperMsg){
 78        var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
 79        for (var i = 0; i < elem.value.length; i++) {
 80            if (iChars.indexOf(elem.value.charAt(i)) != -1) {
 81                alert(helperMsg);
 82                return false;
 83            }
 84        }
 85    }
 86
 87    function checkEmpty(){
 88        if(document.getElementById('unitName').value=="" ||document.getElementById('firstName').value=="" ||document.getElementById('lastName').value==""||document.getElementById('email').value==""){
 89            alert("All fields are mandatory");
 90        }
 91        else{
 92            document.signup.submit();
 93        }
 94    }
 95
 96</script>
 97
 98<body onLoad="document.signup.unitName.focus()">
 99    <div id="maincontent">
100        <div class="innercontent">
101
102            <table cellpadding="0" cellspacing="0" border="0" width="100%" class="pageHeader">
103                <tr>
104                    <td><spring:message code="esicsignup"/></td>
105
106                </tr>
107            </table>
108            <table cellpadding="0" cellspacing="0" border="0" width="100%">
109                <tr>
110                    <td><b><spring:message code="mandatory"/></b></td>
111                </tr>
112            </table>
113            <form:form name="signup" commandName="signup" method="post" action="${formAction}">
114                <table id="insert1" width="476" border="0" cellpadding="0" cellspacing="0" align="center" class="login">
115                    <tr>
116                        <td width="150" class="leftTopFormLabel" colspan="2"><b><liferay-ui:error exception="<%= CaptchaTextException.class %>" message="text-verification-failed" /></b></td>
117                    </tr>
118
119                    <tr>
120                        <td width="150" class="leftTopFormLabel" colspan="2"><b><form:errors path="unitName" cssStyle="color:red" /></b></td>
121                    </tr>
122                    <tr>
123                        <td width="150" class="leftTopFormLabel" colspan="2"><b><form:errors path="firstName" cssStyle="color:red" /></b></td>
124                    </tr>
125                    <tr>
126                        <td width="150" class="leftTopFormLabel" colspan="2"><b><form:errors path="lastName" cssStyle="color:red" /></b></td>
127                    </tr>
128                    <tr>
129                        <td width="150" class="leftTopFormLabel" colspan="2"><b><form:errors path="email" cssStyle="color:red" /></b></td>
130                    </tr>
131                    <tr>
132                        <td  width="150" class="leftTopFormLabel" colspan="2"><b><form:errors path="captchausertext" cssStyle="color:red" /></b></td>
133                    </tr>
134                </table>
135                <table id="insert2" width="476" border="0" cellpadding="0" cellspacing="0" align="center">
136                    <tr>
137                        <td colspan="2">&nbsp;</td>
138                    </tr>
139                    <tr>
140                        <td width="150" class="leftTopFormLabel"><spring:message code="unitName"/><span style="color:red"> *</span> :</td>
141                        <td width="252"><input name="unitName" type="text" id="unitName" value="" onchange="javascript:isSpclChar(document.getElementById('unitName'), 'Please enter a valid Unit Name')" title="Please Enter the Company Name" size="31" maxlength="50"/></td>
142                    </tr>
143                    <tr><td colspan="2">&nbsp;</td></tr>
144                    <tr>
145                        <td width="150" class="leftTopFormLabel"><spring:message code="firstName"/><span style="color:red"> *</span> :</td>
146                        <td><input name="firstName" type="text" id="firstName" value="" onchange="javascript:isSpclChar(document.getElementById('firstName'), 'Please enter a valid First Name')" size="31" maxlength="25"/></td>
147                    </tr>
148                    <tr><td colspan="2">&nbsp;</td></tr>
149                    <tr>
150                        <td width="150" class="leftTopFormLabel"><spring:message code="lastName"/><span style="color:red"> *</span> :</td>
151                        <td><input name="lastName" type="text" id="lastName" value="" onchange="javascript:isSpclChar(document.getElementById('lastName'), 'Please enter a valid Last Name')" size="31" maxlength="25"/></td>
152                    </tr>
153                    <tr><td colspan="2">&nbsp;</td></tr>
154                    <tr>
155                        <td width="150" class="leftTopFormLabel"><spring:message code="emailAddress"/><span style="color:red"> *</span> :</td>
156                        <td><input name="email" type="text" id="email" size="31" value="" maxlength="45" onchange="javascript:emailValidator(document.getElementById('email'), 'Please enter a valid Email Address')"/></td>
157                    </tr>
158                    <tr><td colspan="2">&nbsp;</td></tr>
159                    <tr>
160                        <td>&nbsp;</td>
161                        <td><liferay-ui:captcha url="http://localhost:8080/web/guest/home1?p_p_id=58&p_p_lifecycle=1&p_p_url_type=0&p_p_state=exclusive&p_p_mode=view&_58_struts_action=%2Flogin%2Fcaptcha" /></td>
162                    </tr>
163                    <tr>
164                        <td colspan="2">&nbsp;</td>
165                    </tr>
166                    <tr align="center" valign="middle">
167                        <td colspan="2" align="center" valign="bottom">
168                            <input type="button" name="button5" id="button5" onClick="javascript:checkEmpty()" value="<spring:message code="submit"/>"/>&nbsp;&nbsp;
169                            <input type="reset" name="button6" id="button6" value="<spring:message code="clear"/>"/>&nbsp;&nbsp;
170                            <input type="button" name="button7" id="button7" onClick="javascript:removeMessage();javascript:guestHome()" value="<spring:message code="cancel"/>"/>&nbsp;&nbsp;
171                            <p>&nbsp;</p>
172                        </td>
173                    </tr>
174                  
175                    </table>
176                </div>
177            </div>
178    </form:form>
179</body>



now, i am unable to validate the entered captcha. it is not throwing any exception. but it is not validating.

if u have some idea also, plz help.

Rgds,
Rajesh.
Sandeep Nair
RE: Liferay Captcha validation
March 24, 2010 11:19 PM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1721

Join Date: November 5, 2008

Recent Posts

Remove <portlet:actionURL var="captchaURL"/> from top

and add this inside your <td>

1    <portlet:actionURL windowState="<%= LiferayWindowState.EXCLUSIVE.toString() %>" var="captchaURL">
2        <portlet:param name="struts_action" value="/myportlet/captcha" />
3    </portlet:actionURL>
4
5    <liferay-ui:captcha url="<%= captchaURL %>" />


Make sure /myportlet/captcha maps to com.liferay.portal.captcha.CaptchaPortletAction in struts-config.xml

Regards,
Sandeep
Rajesh GR
RE: Liferay Captcha validation
March 25, 2010 12:11 AM
Answer

Rajesh GR

Rank: Regular Member

Posts: 157

Join Date: February 7, 2010

Recent Posts

HI thx for ur reply,

i am developing spring portlets. i tried this procedure of achieving it. but i am getting error like,

"can not find symbol captchaURL" for <liferay-ui:captcha url="<%= captchaURL %>" /> emoticon
Sandeep Nair
RE: Liferay Captcha validation
March 25, 2010 12:18 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1721

Join Date: November 5, 2008

Recent Posts

Are you using plugin sdk?
Rajesh GR
RE: Liferay Captcha validation
March 25, 2010 12:21 AM
Answer

Rajesh GR

Rank: Regular Member

Posts: 157

Join Date: February 7, 2010

Recent Posts

yes.
Sandeep Nair
RE: Liferay Captcha validation
March 25, 2010 12:23 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1721

Join Date: November 5, 2008

Recent Posts

Hi,

In that case can you please check this.

I havent tried it.

Regards,
Sandeep
Rajesh GR
RE: Liferay Captcha validation
March 25, 2010 12:30 AM
Answer

Rajesh GR

Rank: Regular Member

Posts: 157

Join Date: February 7, 2010

Recent Posts

hi sandeep, earlier i tried this one also, giving the same error for

<liferay-ui:captcha url="<%= captchaURL %>" />

then i had given something like this,

<liferay-ui:captcha url="http://localhost:8080/web/guest/home1?p_p_id=58&p_p_lifecycle=1&p_p_url_type=0&p_p_state=exclusive&p_p_mode=view&_58_struts_action=%2Flogin%2Fcaptcha" />

the image is displayed. but unable 2 validate it.
Sandeep Nair
RE: Liferay Captcha validation
March 25, 2010 1:26 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1721

Join Date: November 5, 2008

Recent Posts

Hi Rajesh,

Did you follow as mentioned in the link that i sent. It works for me when i follow that.

http://www.emforge.net/web/akakunin/home/-/blogs/implement-captcha-in-liferay-portlet

Regards,
Sandeep
Rajesh GR
RE: Liferay Captcha validation
March 25, 2010 1:49 AM
Answer

Rajesh GR

Rank: Regular Member

Posts: 157

Join Date: February 7, 2010

Recent Posts

Hi sandeep,

i am following it frm past 3 days. i am still facing 3 problems

1. Unable to import JSPPortlet in CaptchaSamplePortlet. i am using 5.2.1

2. <liferay-ui:captcha url="<%= captchaURL %>"/> "can not find symbol captchaURL" in jsp.

3. Exception("Internal Error! Captcha text not found in session");


plz guide me dude.
Sandeep Nair
RE: Liferay Captcha validation
March 25, 2010 2:11 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1721

Join Date: November 5, 2008

Recent Posts

Ok Here are the steps.

First of all heres the jsp that you need. I have kept it really simple

 1<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
 2<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>
 3<jsp:useBean id="name" class="java.lang.String" scope="request"/>
 4<portlet:defineObjects />
 5<form method="post" action="<portlet:actionURL/>">
 6    <portlet:resourceURL var="captchaURL"/>
 7    <liferay-ui:captcha url="<%= captchaURL %>"/>
 8    <input type="submit"/>
 9</form>


Next add this in your portlet class. This is used for displaying captcha image in jsp

1public void serveResource(ResourceRequest request, ResourceResponse response)
2            throws PortletException, IOException {
3        CaptchaUtil.serveImage(request, response);
4    }


Modify your processAction. Here when you hit submit form from jsp the captchaText is retrieved from request and compared with the image text. I have done a simple SOP which says Valid captcha or invalid captcha. You can handle the code as you like after you get the flag.

 1public void processAction(
 2            ActionRequest actionRequest, ActionResponse actionResponse)
 3        throws IOException, PortletException {
 4        if(checkCaptcha(actionRequest)){
 5            System.out.println("Valid captcha. Proceed further");
 6        }else{
 7            System.out.println("Invalid Captcha. Throw some custom exception which you will catch in jsp and display error message");
 8        }
 9        actionResponse.setPortletMode(PortletMode.VIEW);
10    }
11     private boolean checkCaptcha(PortletRequest request) throws PortletException {
12            String enteredCaptchaText = ParamUtil.getString(request, "captchaText");
13            boolean isValid = true;
14            PortletSession session = request.getPortletSession();
15            String captchaText = getCaptchaValueFromSession(session);
16            if (Validator.isNull(captchaText)) {
17                System.out.println("Internal Error! Captcha text not found in session");
18                isValid = false;
19            }
20            if (!captchaText.equals(enteredCaptchaText)) {
21                System.out.println("Invalid captcha text. Please reenter.");
22                isValid = false;
23            }
24            return isValid;
25        }
26
27        private String getCaptchaValueFromSession(PortletSession session) {
28            Enumeration<String> atNames = session.getAttributeNames();
29            while (atNames.hasMoreElements()) {
30                String name = atNames.nextElement();
31                if (name.contains("CAPTCHA_TEXT")) {
32                    return (String) session.getAttribute(name);
33                }
34            }
35            return null;
36        }


Regards,
Sandeep
Rajesh GR
RE: Liferay Captcha validation
March 25, 2010 2:39 AM
Answer

Rajesh GR

Rank: Regular Member

Posts: 157

Join Date: February 7, 2010

Recent Posts

Hi Sandeep,


thx 4 ur effort dude. i tried it.

but this problem still persist.

2. <liferay-ui:captcha url="<%= captchaURL %>"/> "can not find symbol captchaURL" in jsp.
Sandeep Nair
RE: Liferay Captcha validation
March 25, 2010 2:42 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1721

Join Date: November 5, 2008

Recent Posts

Make sure your portlet class is extending GenericPortlet.
Sandeep Nair
RE: Liferay Captcha validation
March 25, 2010 2:45 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1721

Join Date: November 5, 2008

Recent Posts

Hi,

I have attached the war. Unzip it and add it to your webapps folder. It has source too.

Regards,
Sandeep
Attachments: my-hello-world-portlet.rar (825.6k)
Rajesh GR
RE: Liferay Captcha validation
March 25, 2010 2:46 AM
Answer

Rajesh GR

Rank: Regular Member

Posts: 157

Join Date: February 7, 2010

Recent Posts

Hi Sandeep,

i am developing it in Spring Portlet and extending SimpleFormController dude.
Sandeep Nair
RE: Liferay Captcha validation
March 25, 2010 2:57 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1721

Join Date: November 5, 2008

Recent Posts

Oh... How are you redirecting it to the jsp that shows captcha. You have to write the following code in your java file before forwarding to that jsp

CaptchaUtil.serveImage(request, response);

Regards,
Sandeep
Rajesh GR
RE: Liferay Captcha validation
March 25, 2010 3:28 AM
Answer

Rajesh GR

Rank: Regular Member

Posts: 157

Join Date: February 7, 2010

Recent Posts

Hi Sandeep,

i think their is nothing like doGet() in simpleformcontroller.

tats y i used something like,

<td><img alt="captcha" class="captcha" src="CaptchaUtil.serveImage(request, response);" /></td>
<td>Text Verification<input name="enteredCaptchaText" size="10" type="text" value="" /></td>


it is not displaying any image, but displaying "captcha" text only.
Alexey Kakunin
RE: Liferay Captcha validation
March 25, 2010 2:08 PM
Answer

Alexey Kakunin

Rank: Liferay Master

Posts: 584

Join Date: July 7, 2008

Recent Posts

Hi!

Rajesh Babu:

2. <liferay-ui:captcha url="<%= captchaURL %>"/> "can not find symbol captchaURL" in jsp.


Could you check you have
1
2<portlet:resourceURL var="captchaURL"/>

in your code? Actually - it is defined variable captchaURL to be inserted later into <liferay-ui:captcha> tag
Rajesh GR
RE: Liferay Captcha validation
March 26, 2010 3:00 AM
Answer

Rajesh GR

Rank: Regular Member

Posts: 157

Join Date: February 7, 2010

Recent Posts

Hi Alexey,

thx for ur reply. u r exactly rite. i defined it like,

<portlet:resourceURL var="captchaURL"/>
<liferay-ui:captcha url="<%= captchaURL %>"/>


but still it is giving error as captchaURL not defined.
Arsh g
RE: Liferay Captcha validation
March 11, 2011 2:34 AM
Answer

Arsh g

Rank: New Member

Posts: 11

Join Date: February 18, 2011

Recent Posts

<liferay-ui:captcha url="http://localhost:8080/web/guest/home1?p_p_id=58&p_p_lifecycle=1&p_p_url_type=0&p_p_state=exclusive&p_p_mode=view&_58_struts_action=%2Flogin%2Fcaptcha" />

I used this but it not displaying image??
plz help
Arsh g
RE: Liferay Captcha validation
March 22, 2011 11:08 PM
Answer

Arsh g

Rank: New Member

Posts: 11

Join Date: February 18, 2011

Recent Posts

I solved the problem.
thanxs
Hadrien Mens-Pellen
RE: Liferay Captcha validation
April 7, 2011 1:09 AM
Answer

Hadrien Mens-Pellen

Rank: New Member

Posts: 21

Join Date: February 21, 2011

Recent Posts

Hi!

Can you try this (works for me).

<portlet:resourceURL var="captchaURL"/>
<liferay-ui:captcha url="${captchaURL}"/>
Danial Mustofa Habibi
RE: Liferay Captcha validation
December 28, 2011 6:28 AM
Answer

Danial Mustofa Habibi

Rank: Regular Member

Posts: 141

Join Date: November 1, 2011

Recent Posts

Sandeep Nair:
Ok Here are the steps.

First of all heres the jsp that you need. I have kept it really simple

 1<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
 2<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>
 3<jsp:useBean id="name" class="java.lang.String" scope="request"/>
 4<portlet:defineObjects />
 5<form method="post" action="<portlet:actionURL/>">
 6    <portlet:resourceURL var="captchaURL"/>
 7    <liferay-ui:captcha url="<%= captchaURL %>"/>
 8    <input type="submit"/>
 9</form>


Next add this in your portlet class. This is used for displaying captcha image in jsp

1public void serveResource(ResourceRequest request, ResourceResponse response)
2            throws PortletException, IOException {
3        CaptchaUtil.serveImage(request, response);
4    }


Modify your processAction. Here when you hit submit form from jsp the captchaText is retrieved from request and compared with the image text. I have done a simple SOP which says Valid captcha or invalid captcha. You can handle the code as you like after you get the flag.

 1public void processAction(
 2            ActionRequest actionRequest, ActionResponse actionResponse)
 3        throws IOException, PortletException {
 4        if(checkCaptcha(actionRequest)){
 5            System.out.println("Valid captcha. Proceed further");
 6        }else{
 7            System.out.println("Invalid Captcha. Throw some custom exception which you will catch in jsp and display error message");
 8        }
 9        actionResponse.setPortletMode(PortletMode.VIEW);
10    }
11     private boolean checkCaptcha(PortletRequest request) throws PortletException {
12            String enteredCaptchaText = ParamUtil.getString(request, "captchaText");
13            boolean isValid = true;
14            PortletSession session = request.getPortletSession();
15            String captchaText = getCaptchaValueFromSession(session);
16            if (Validator.isNull(captchaText)) {
17                System.out.println("Internal Error! Captcha text not found in session");
18                isValid = false;
19            }
20            if (!captchaText.equals(enteredCaptchaText)) {
21                System.out.println("Invalid captcha text. Please reenter.");
22                isValid = false;
23            }
24            return isValid;
25        }
26
27        private String getCaptchaValueFromSession(PortletSession session) {
28            Enumeration<String> atNames = session.getAttributeNames();
29            while (atNames.hasMoreElements()) {
30                String name = atNames.nextElement();
31                if (name.contains("CAPTCHA_TEXT")) {
32                    return (String) session.getAttribute(name);
33                }
34            }
35            return null;
36        }


Regards,
Sandeep


hi sandeep I've tried the method u provide but i got error like this
  1Internal Error! Captcha text not found in session
  220:28:47,134 ERROR [PortletServlet:96] javax.portlet.PortletException: java.lang.NullPointerException
  3javax.portlet.PortletException: java.lang.NullPointerException
  4    at com.liferay.portal.kernel.portlet.LiferayPortlet.callActionMethod(LiferayPortlet.java:156)
  5    at com.liferay.util.bridges.mvc.MVCPortlet.callActionMethod(MVCPortlet.java:227)
  6    at com.liferay.portal.kernel.portlet.LiferayPortlet.processAction(LiferayPortlet.java:69)
  7    at com.liferay.util.bridges.mvc.MVCPortlet.processAction(MVCPortlet.java:199)
  8    at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:70)
  9    at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:48)
 10    at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:92)
 11    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 12    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 13    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 14    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
 15    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551)
 16    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:488)
 17    at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:638)
 18    at com.liferay.portlet.InvokerPortletImpl.invokeAction(InvokerPortletImpl.java:687)
 19    at com.liferay.portlet.InvokerPortletImpl.processAction(InvokerPortletImpl.java:360)
 20    at com.liferay.portal.action.LayoutAction.processPortletRequest(LayoutAction.java:784)
 21    at com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:582)
 22    at com.liferay.portal.action.LayoutAction.execute(LayoutAction.java:232)
 23    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
 24    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
 25    at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:153)
 26    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
 27    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
 28    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
 29    at com.liferay.portal.servlet.MainServlet.callParentService(MainServlet.java:508)
 30    at com.liferay.portal.servlet.MainServlet.service(MainServlet.java:485)
 31    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 32    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 33    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 34    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 35    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
 36    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 37    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 38    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 39    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
 40    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 41    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 42    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 43    at com.liferay.portal.servlet.filters.strip.StripFilter.processFilter(StripFilter.java:309)
 44    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
 45    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 46    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 47    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 48    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
 49    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 50    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 51    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 52    at com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:121)
 53    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
 54    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 55    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 56    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 57    at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:182)
 58    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
 59    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 60    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 61    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 62    at com.liferay.portal.servlet.filters.autologin.AutoLoginFilter.processFilter(AutoLoginFilter.java:254)
 63    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
 64    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 65    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 66    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
 67    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
 68    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
 69    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
 70    at com.liferay.portal.servlet.FriendlyURLServlet.service(FriendlyURLServlet.java:134)
 71    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 72    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 73    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 74    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 75    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
 76    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 77    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 78    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 79    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
 80    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 81    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 82    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 83    at com.liferay.portal.servlet.filters.strip.StripFilter.processFilter(StripFilter.java:261)
 84    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
 85    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 86    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 87    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 88    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
 89    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 90    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 91    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 92    at com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:110)
 93    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
 94    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 95    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 96    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 97    at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:182)
 98    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
 99    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
100    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
101    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
102    at com.liferay.portal.servlet.filters.i18n.I18nFilter.processFilter(I18nFilter.java:222)
103    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
104    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
105    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
106    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
107    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
108    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
109    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
110    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
111    at com.liferay.portal.servlet.filters.cache.CacheFilter.processFilter(CacheFilter.java:442)
112    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
113    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
114    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
115    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
116    at com.liferay.portal.servlet.filters.etag.ETagFilter.processFilter(ETagFilter.java:45)
117    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
118    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
119    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
120    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
121    at com.liferay.portal.servlet.filters.autologin.AutoLoginFilter.processFilter(AutoLoginFilter.java:254)
122    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
123    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
124    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
125    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
126    at com.liferay.portal.servlet.filters.sso.ntlm.NtlmPostFilter.processFilter(NtlmPostFilter.java:81)
127    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
128    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
129    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
130    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
131    at com.liferay.portal.sharepoint.SharepointFilter.processFilter(SharepointFilter.java:179)
132    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
133    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
134    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
135    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
136    at com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter.processFilter(VirtualHostFilter.java:240)
137    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
138    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
139    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
140    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
141    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
142    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
143    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
144    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
145    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
146    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
147    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
148    at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
149    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
150    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
151    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
152    at com.liferay.portal.servlet.filters.threadlocal.ThreadLocalFilter.processFilter(ThreadLocalFilter.java:35)
153    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
154    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
155    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
156    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
157    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
158    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
159    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
160    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
161    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
162    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
163    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
164    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
165    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
166    at java.lang.Thread.run(Thread.java:619)
167Caused by: java.lang.NullPointerException
168    at com.registrasi.unhan.portlet.PendaftaranPortlet.checkCaptcha(PendaftaranPortlet.java:51)
169    at com.registrasi.unhan.portlet.PendaftaranPortlet.addPendaftar(PendaftaranPortlet.java:78)
170    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
171    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
172    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
173    at java.lang.reflect.Method.invoke(Method.java:597)
174    at com.liferay.portal.kernel.portlet.LiferayPortlet.callActionMethod(LiferayPortlet.java:138)
175    ... 162 more
17620:28:47,148 ERROR [jsp:154] java.lang.NullPointerException
177    at com.registrasi.unhan.portlet.PendaftaranPortlet.checkCaptcha(PendaftaranPortlet.java:51)
178    at com.registrasi.unhan.portlet.PendaftaranPortlet.addPendaftar(PendaftaranPortlet.java:78)
179    at com.liferay.portal.kernel.portlet.LiferayPortlet.callActionMethod(LiferayPortlet.java:138)
180    at com.liferay.util.bridges.mvc.MVCPortlet.callActionMethod(MVCPortlet.java:227)
181    at com.liferay.portal.kernel.portlet.LiferayPortlet.processAction(LiferayPortlet.java:69)
182    at com.liferay.util.bridges.mvc.MVCPortlet.processAction(MVCPortlet.java:199)
183    at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:70)
184    at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:48)
185    at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:92)
186    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
187    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
188    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
189    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
190    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551)
191    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:488)
192    at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:638)
193    at com.liferay.portlet.InvokerPortletImpl.invokeAction(InvokerPortletImpl.java:687)
194    at com.liferay.portlet.InvokerPortletImpl.processAction(InvokerPortletImpl.java:360)
195    at com.liferay.portal.action.LayoutAction.processPortletRequest(LayoutAction.java:784)
196    at com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:582)


My Code almost same just like u provide the difference only on action like this
 1        throws PortalException, SystemException,PortletException {
 2
 3        Pendaftaran pendaftar = ActionUtil.pendaftaranFromRequest(request);
 4
 5        ArrayList<String> errors = new ArrayList<String>();
 6        ServiceContext serviceContext = ServiceContextFactory.getInstance(
 7                Pendaftaran.class.getName(), request);
 8   
 9        log.info("masuk");
10        if (PdValidator.validatePendaftar(pendaftar, errors)&&checkCaptcha(request)) {
11            log.info("berhasil");
12
13            try {
14                PendaftaranLocalServiceUtil.addPendaftaran(pendaftar,
15                        pendaftar.getUserId(), serviceContext);
16               
17
18            } catch (SystemException e) {
19
20                errors.add("failed-to-add");
21
22            } catch (PortalException e) {
23
24                errors.add("failed-to-add");
25            }
26            
27            request.setAttribute("pendaftaran", pendaftar);
28            response.setRenderParameter("jspPage", FileJSP);
29               
30
31        } else
32
33        {
34
35            for (String error : errors) {
36                SessionErrors.add(request, error);
37            }
38
39
40        }
41       
42       
43
44    }

in my jsp I'm adding
1<portlet:resourceURL var="captchaURL"/>
2        <liferay-ui:captcha url="<%= captchaURL %>"/>
3        </aui:fieldset>

before my submit button
any idea how to resolve that??
thank's

regards

danial
Sandeep Nair
RE: Liferay Captcha validation
December 28, 2011 9:34 PM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1721

Join Date: November 5, 2008

Recent Posts

Is it possible for you to attach the portlet? The exception seems to come in PendaftaranPortlet.checkCaptcha method.

Regards,
Sandeep
Danial Mustofa Habibi
RE: Liferay Captcha validation
December 29, 2011 3:36 AM
Answer

Danial Mustofa Habibi

Rank: Regular Member

Posts: 141

Join Date: November 1, 2011

Recent Posts

Sandeep Nair:
Is it possible for you to attach the portlet? The exception seems to come in PendaftaranPortlet.checkCaptcha method.

Regards,
Sandeep

Ok I will Attach my Portlet...

Thank's For ur Help,, I've tried about portletsession and i get the session but can't get the captcha attribute from session...

I'm Using plugin SDK LR 6.0.6
Regards


Danial
Attachments: RegistrasiUnhan-portlet.rar (480.4k)
Sandeep Nair
RE: Liferay Captcha validation
December 29, 2011 3:36 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1721

Join Date: November 5, 2008

Recent Posts

Hi Danial,

Your code is working perfectly fine. I am attaching the java file

Note: I had to do some changes to make it working in my system

Removed ext-spring.xml as i m using mysql and removed datasource def in service.xml and did build service
Deleted Listener class as that was giving me error
Removed the check of validation for fields as i needed to quickly debug just captcha related code which was working just fine.
Attachments: PendaftaranPortlet.java (10.5k)
Danial Mustofa Habibi
RE: Liferay Captcha validation
December 29, 2011 4:02 AM
Answer

Danial Mustofa Habibi

Rank: Regular Member

Posts: 141

Join Date: November 1, 2011

Recent Posts

Sandeep Nair:
Hi Danial,

Your code is working perfectly fine. I am attaching the java file

Note: I had to do some changes to make it working in my system

Removed ext-spring.xml as i m using mysql and removed datasource def in service.xml and did build service
Deleted Listener class as that was giving me error
Removed the check of validation for fields as i needed to quickly debug just captcha related code which was working just fine.


Hi there It seem there's nothing change from java file u attaching with mine....
I still get the error
  1Internal Error! Captcha text not found in session
  218:53:01,566 ERROR [PortletServlet:96] javax.portlet.PortletException: java.lang.NullPointerException
  3javax.portlet.PortletException: java.lang.NullPointerException
  4    at com.liferay.portal.kernel.portlet.LiferayPortlet.callActionMethod(LiferayPortlet.java:156)
  5    at com.liferay.util.bridges.mvc.MVCPortlet.callActionMethod(MVCPortlet.java:227)
  6    at com.liferay.portal.kernel.portlet.LiferayPortlet.processAction(LiferayPortlet.java:69)
  7    at com.liferay.util.bridges.mvc.MVCPortlet.processAction(MVCPortlet.java:199)
  8    at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:70)
  9    at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:48)
 10    at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:92)
 11    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 12    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 13    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 14    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
 15    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551)
 16    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:488)
 17    at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:638)
 18    at com.liferay.portlet.InvokerPortletImpl.invokeAction(InvokerPortletImpl.java:687)
 19    at com.liferay.portlet.InvokerPortletImpl.processAction(InvokerPortletImpl.java:360)
 20    at com.liferay.portal.action.LayoutAction.processPortletRequest(LayoutAction.java:784)
 21    at com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:582)
 22    at com.liferay.portal.action.LayoutAction.execute(LayoutAction.java:232)
 23    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
 24    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
 25    at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:153)
 26    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
 27    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
 28    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
 29    at com.liferay.portal.servlet.MainServlet.callParentService(MainServlet.java:508)
 30    at com.liferay.portal.servlet.MainServlet.service(MainServlet.java:485)
 31    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 32    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 33    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 34    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 35    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
 36    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 37    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 38    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 39    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
 40    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 41    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 42    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 43    at com.liferay.portal.servlet.filters.strip.StripFilter.processFilter(StripFilter.java:309)
 44    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
 45    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 46    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 47    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 48    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
 49    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 50    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 51    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 52    at com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:121)
 53    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
 54    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 55    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 56    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 57    at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:182)
 58    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
 59    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 60    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 61    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 62    at com.liferay.portal.servlet.filters.autologin.AutoLoginFilter.processFilter(AutoLoginFilter.java:254)
 63    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
 64    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 65    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 66    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
 67    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
 68    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
 69    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
 70    at com.liferay.portal.servlet.FriendlyURLServlet.service(FriendlyURLServlet.java:134)
 71    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 72    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 73    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 74    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 75    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
 76    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 77    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 78    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 79    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
 80    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 81    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 82    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 83    at com.liferay.portal.servlet.filters.strip.StripFilter.processFilter(StripFilter.java:261)
 84    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
 85    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 86    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 87    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 88    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
 89    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 90    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 91    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 92    at com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:110)
 93    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
 94    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 95    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 96    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 97    at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:182)
 98    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
 99    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
100    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
101    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
102    at com.liferay.portal.servlet.filters.i18n.I18nFilter.processFilter(I18nFilter.java:222)
103    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
104    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
105    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
106    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
107    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
108    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
109    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
110    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
111    at com.liferay.portal.servlet.filters.cache.CacheFilter.processFilter(CacheFilter.java:442)
112    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
113    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
114    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
115    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
116    at com.liferay.portal.servlet.filters.etag.ETagFilter.processFilter(ETagFilter.java:45)
117    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
118    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
119    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
120    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
121    at com.liferay.portal.servlet.filters.autologin.AutoLoginFilter.processFilter(AutoLoginFilter.java:254)
122    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
123    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
124    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
125    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
126    at com.liferay.portal.servlet.filters.sso.ntlm.NtlmPostFilter.processFilter(NtlmPostFilter.java:81)
127    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
128    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
129    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
130    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
131    at com.liferay.portal.sharepoint.SharepointFilter.processFilter(SharepointFilter.java:179)
132    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
133    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
134    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
135    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
136    at com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter.processFilter(VirtualHostFilter.java:240)
137    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
138    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
139    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
140    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
141    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
142    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
143    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
144    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
145    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
146    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
147    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
148    at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
149    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
150    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
151    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
152    at com.liferay.portal.servlet.filters.threadlocal.ThreadLocalFilter.processFilter(ThreadLocalFilter.java:35)
153    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
154    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
155    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
156    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
157    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
158    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
159    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
160    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
161    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
162    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
163    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
164    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
165    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
166    at java.lang.Thread.run(Thread.java:619)
167Caused by: java.lang.NullPointerException
168    at com.registrasi.unhan.portlet.PendaftaranPortlet.checkCaptcha(PendaftaranPortlet.java:51)
169    at com.registrasi.unhan.portlet.PendaftaranPortlet.addPendaftar(PendaftaranPortlet.java:78)
170    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
171    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
172    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
173    at java.lang.reflect.Method.invoke(Method.java:597)
174    at com.liferay.portal.kernel.portlet.LiferayPortlet.callActionMethod(LiferayPortlet.java:138)
175    ... 162 more
17618:53:01,577 ERROR [jsp:154] java.lang.NullPointerException
177    at com.registrasi.unhan.portlet.PendaftaranPortlet.checkCaptcha(PendaftaranPortlet.java:51)
178    at com.registrasi.unhan.portlet.PendaftaranPortlet.addPendaftar(PendaftaranPortlet.java:78)
179    at com.liferay.portal.kernel.portlet.LiferayPortlet.callActionMethod(LiferayPortlet.java:138)
180    at com.liferay.util.bridges.mvc.MVCPortlet.callActionMethod(MVCPortlet.java:227)
181    at com.liferay.portal.kernel.portlet.LiferayPortlet.processAction(LiferayPortlet.java:69)
182    at com.liferay.util.bridges.mvc.MVCPortlet.processAction(MVCPortlet.java:199)
183    at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:70)
184    at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:48)
185    at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:92)
186    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
187    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
188    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
189    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
190    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551)
191    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:488)
192    at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:638)
193    at com.liferay.portlet.InvokerPortletImpl.invokeAction(InvokerPortletImpl.java:687)
194    at com.liferay.portlet.InvokerPortletImpl.processAction(InvokerPortletImpl.java:360)
195    at com.liferay.portal.action.LayoutAction.processPortletRequest(LayoutAction.java:784)
196    at com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:582)

I've managed to show the Captcha but still can't validate...even after I'm using java file u attach...
I've tried to remove my validator so it only validate chaptcha but still I show
1Internal Error! Captcha text not found in session

is there something wrong with my portlet session

is this the right syntax?for parameter "CAPTCHA_TEXT"
1if (name.contains("CAPTCHA_TEXT")) {
2                return (String) session.getAttribute(name);
3            }

in
 1private String getCaptchaValueFromSession(PortletSession session) {
 2        Enumeration<String> atNames = session.getAttributeNames();
 3        while (atNames.hasMoreElements()) {
 4            String name = atNames.nextElement();
 5            if (name.contains("CAPTCHA_TEXT")) {
 6                return (String) session.getAttribute(name);
 7            }
 8        }
 9        return null;
10    }

I'm using LR 6.0.6 emoticon

Thank's

Regards


Danial
Sandeep Nair
RE: Liferay Captcha validation
December 29, 2011 5:20 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1721

Join Date: November 5, 2008

Recent Posts

It has to be session problem but the strange thing is I havent done any modification related to that to make it work in mine. Can you place a debug in SimpleCaptchaImpl methods serveImage method and check if after setting in session is it available

Regards,
Sandeep
Danial Mustofa Habibi
RE: Liferay Captcha validation
December 29, 2011 4:35 PM
Answer

Danial Mustofa Habibi

Rank: Regular Member

Posts: 141

Join Date: November 1, 2011

Recent Posts

Sandeep Nair:
It has to be session problem but the strange thing is I havent done any modification related to that to make it work in mine. Can you place a debug in SimpleCaptchaImpl methods serveImage method and check if after setting in session is it available

Regards,
Sandeep



Hi there Thank's for your advice, yes it seem there's session problem,, I'm trying to deploy the portlet on other PC, and it's work, Anyway Thank's Again Sandeep For your help