OA Framework With Captcha Webservice
OA Framework With Captcha Webservice
OA Framework With Captcha Webservice
In this article, I am explaining a step by step approach to implement a Captcha Web Service from Oracle's Java based
OA Framework. In this OA Framework tutorial, we will display a captcha image within a OA Framework page. Also, the
user will be able to enter the response to Captcha Image. The response will be validated against the Captcha
Webservice.
Why use a Webservice, when you can get Open Source software like jCaptcha.
This is your personal choice. Both options are equally feasible and usefull depending upon your need.
However in my case, I preferred Captcha Webservice for below reasons:-
1. All functionality enhancements are available to you by Webservice Provider.
2. No maintenance on our system, to do bug-fixes[if any] to captcha generation logic.
In jDeveloper, right click on project to create a Webservice Stub from your WSDL.
Enter the URL of Webservice [or call it a WSDL as they say].I am creating these in package named xxfreecaptcha01.
However, you can create these classes in any package as you wish.
The IDE of jDeveloper will create the classes based on definition of WebService in WSDL Document.
All complexities related to SOAP etc are taken care of by these Stubs.
For us, usage of Captcha is like calling any ordinary java Program.
NOTE: Very Important: The Stub classes and methods created by jDeveloper 9.0.3 is different from Netbeans, Eclipse
for the very SAME WSDL.
Infact, I found that even jDeveloper 10.1.3 would create different definition of Stubs. This is not a problem though, as
they all work. However this experience of mine proves that different vendors/products parse WSDL differently. All this
despite all of these following same specification.
Anyway, here are the java files generated, to make calls to Captcha remote Web Service.
Modify the controller code, [a piece of code that is executed when page renders].
In that code, we make a call to Webservice. The sourcecode is provided at the bottom of the article.
However, I will explain steps briefly here:-
1. Create instance of ClientAuthModel() and set userid and password.
2. Create instance of CaptchaServiceStub() and invoke Webservice method GetNewWord()
3. The result of the GetNewWord() is an Object of type CaptchaImageWordModel [word]
4. The returned object[named word], has URL of the Image, and also the KEY used for validation.
The KEY along with user response will be sent to CAPTCHA Webservice. Hence I am setting these two in session
variables.
Alternately, you can store these in some global variable or a hidden sets of fields.
5. Assign the image URL returned by Web Service to CaptchaImageField.
The response text entered by user is sent to Web Service for validation, alongwith the KEY of Image.
This is done by
ValidateImageWord(cm, pageContext.getSessionValue("captchaGUIDvalue").toString() ,
pageContext.getParameter("captchaWordResponseField"));
If the WebService API returns false, then I am displaying the debug text "Failure with CAPTCHA"
In case the users response is incorrect, we render the page again[by redirecting the page to itself].
This causes the Captcha Webservice to be called again, this time with new Image URL and a new KEY.
Hence with every wrong attempt, the user will see a new image appearing on the page.
This gives users a possibility of attempting Captcha text entry as many times.
import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageTextInputBean;
import oracle.apps.fnd.framework.webui.beans.OAImageBean ;
import oracle.apps.fnd.framework.OAException;
import xxfreecaptcha01.CaptchaImageWordModel;
import xxfreecaptcha01.CaptchaServiceStub;
import xxfreecaptcha01.ClientAuthModel;
import com.sun.java.util.collections.HashMap;
import oracle.apps.fnd.framework.webui.OAWebBeanConstants;
/**
* Controller for ...
*/
public class MainRNCO extends OAControllerImpl {
public static final String RCS_ID="$Header$";
public static final boolean RCS_ID_RECORDED =
VersionInfo.recordClassVersion(RCS_ID, "%packagename%");
/**
* Layout and page setup logic for a region.
* @param pageContext the current OA page context
* @param webBean the web bean corresponding to the region
*/
public void processRequest(OAPageContext pageContext, OAWebBean webBean) {
OAMessageTextInputBean fieldHelloName =
(OAMessageTextInputBean)webBean.findChildRecursive("HelloName");
OAMessageTextInputBean fieldcaptchaGUID =
(OAMessageTextInputBean)webBean.findChildRecursive("captchaImageGUID");
CaptchaServiceStub cs;
ClientAuthModel cm;
CaptchaImageWordModel word;
cm = new ClientAuthModel();
cm.setGuid(clientGuid);
cm.setPassword(clientPassword);
cs = new CaptchaServiceStub();
word = cs.GetNewWord(cm);
pageContext.putSessionValue("captchaGUIDvalue",word.getCaptchaImageGuid());
cimage.setSource(word.getUrl());
} catch ( Exception exx ) {
fieldHelloName.setText(pageContext," !!!! Exception " + exx);
}
super.processRequest(pageContext, webBean);
}
/**
* Procedure to handle form submissions for form elements in
* a region.
* @param pageContext the current OA page context
* @param webBean the web bean corresponding to the region
*/
http://oracle.anilpassi.com Powered by Joomla! Generated: 30 March, 2011, 08:44
Apps
try {
//note, i am changing authentication details here. You need to get one for yourself from textdisguise.com
String clientGuid = "9Xfaf972b-ff85-483e-a132-b6c4f72e27e4";
String clientPassword = "!:ARlmLn,P;CDKN&%Q{s_h|u<r";
CaptchaServiceStub cs;
CaptchaServiceStub cs1;
ClientAuthModel cm;
java.lang.Boolean ret;
OAMessageTextInputBean fieldHelloName =
(OAMessageTextInputBean)webBean.findChildRecursive("HelloName");
OAMessageTextInputBean fieldcaptchaGUID =
(OAMessageTextInputBean)webBean.findChildRecursive("captchaImageGUID");
OAMessageTextInputBean fieldcaptchaResponse =
(OAMessageTextInputBean)webBean.findChildRecursive("captchaWordResponseField");
cm = new ClientAuthModel();
cm.setGuid(clientGuid);
cm.setPassword(clientPassword);
cs = new CaptchaServiceStub();
ret = cs.ValidateImageWord(cm, pageContext.getSessionValue("captchaGUIDvalue").toString() ,
pageContext.getParameter("captchaWordResponseField"));
if(ret.toString() =="true") {
fieldHelloName.setText(pageContext,"Success with CAPTCHA" );
} else {
fieldHelloName.setText(pageContext,"Failure with CAPTCHA" );
}
super.processFormRequest(pageContext, webBean);
if (ret.toString() == "false") {
cs1 = new CaptchaServiceStub();
word = cs1.GetNewWord(cm);
HashMap params = new HashMap();
pageContext.forwardImmediatelyToCurrentPage(params,true,OAWebBeanConstants.ADD_BREAD_CRUMB_NO);
My GUID was=>" + pageContext.getSessionValue("captchaGUIDvalue") );
How about the Stub Files, that will be used by Java OA Framework?
Please find the three classes below
package xxfreecaptcha01;
/**
* Generated by the Oracle9i JDeveloper Web Services Stub/Skeleton Generator.
* Date Created: Sun Jan 03 12:52:32 GMT 2007
*
* <pre>
http://oracle.anilpassi.com Powered by Joomla! Generated: 30 March, 2011, 08:44
Apps
* <s:complexType name="CaptchaImageWordModel">
* <s:sequence>
* <s:element minOccurs="0" maxOccurs="1" name="CaptchaImageGuid" type="s:string"/>
* <s:element minOccurs="0" maxOccurs="1" name="Url" type="s:string"/>
* </s:sequence>
* </s:complexType>
* </pre>
*/
public CaptchaImageWordModel()
{
}
package xxfreecaptcha01;
import oracle.soap.transport.http.OracleSOAPHTTPConnection;
import org.apache.soap.encoding.soapenc.BeanSerializer;
import org.apache.soap.encoding.SOAPMappingRegistry;
import org.apache.soap.util.xml.QName;
import java.util.Vector;
import org.w3c.dom.Element;
import java.net.URL;
import org.apache.soap.Body;
import org.apache.soap.Envelope;
import org.apache.soap.messaging.Message;
import oracle.jdeveloper.webservices.runtime.WrappedDocLiteralStub;
/**
* Generated by the Oracle9i JDeveloper Web Services Stub/Skeleton Generator.
* Date Created: Wed Jan 03 12:52:33 GMT 2007
* WSDL URL: http://www.textdisguise.com/TextDisguise/CaptchaService/CaptchaService.asmx?WSDL
*
* Web service that allows users to create CAPTCHA-like ("Completely Automated Public Turing test to Tell Computers
and Humans Apart") images and validate the response entered. Current version is v1.0.0. Release Date: 2005-12-22
http://oracle.anilpassi.com Powered by Joomla! Generated: 30 March, 2011, 08:44
Apps
*/
return (CaptchaImageWordModel)fromElement((Element)responseData.elementAt(0),
xxfreecaptcha01.CaptchaImageWordModel.class);
}
public Boolean ValidateImageWord(ClientAuthModel cam, String captchaImageGuid, String word) throws Exception
{
URL endpointURL = new URL(endpoint);
package xxfreecaptcha01;
/**
* Generated by the Oracle9i JDeveloper Web Services Stub/Skeleton Generator.
* Date Created: Wed Jan 03 12:52:32 GMT 2007
*
* <pre>
* <s:complexType name="ClientAuthModel">
* <s:sequence>
* <s:element minOccurs="0" maxOccurs="1" name="Guid" type="s:string"/>
* <s:element minOccurs="0" maxOccurs="1" name="Password" type="s:string"/>
* </s:sequence>
* </s:complexType>
* </pre>
*/
public ClientAuthModel()
{
}
m_Password = Password;
}