P. 1
OA Framework with Captcha Webservice

OA Framework with Captcha Webservice

|Views: 107|Likes:
Published by Anuradha Anmol

More info:

Published by: Anuradha Anmol on Mar 30, 2011
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less






OA Framework with Captcha Webservice
Contributed by Anil Passi Saturday, 20 January 2007

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.

Will I be using BPEL for this exercise? Not really, however you can implement something similar in BPEL too. I prefer using BPEL when there are multiple Web Services involved.

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.

Which Webservice will I be using? I will be using free WebService from Textdisguise.com Their WSDL is http: //www.textdisguise.com/TextDisguise/CaptchaService/CaptchaService.asmx?WSDL You must register on their website, and they will email you username and password. I quite liked Web Service from Capchas.net too, however you can decide to use whatever suits your need.

Before we go into details, what are the steps in brief? Firstly, you may like to read this design approach on link Web Service Design approach in OA Framework. 1. Generate the stubs[java api for remote WebService] using WSDL URL. This will generate some java files which internally make calls to captcha Web Service 2. Create a field of type image, into which Captcha Image will be displayed. 3. In controller class processRequest[executed when page renders], we make a call to Webservice API [ stubs generated in Step-1]. The webservice will return the URL of the image on remote machine 4. Assign the URL to "image field" defined in step 2 5. When user submits the page, call webservice again to validate users response.

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.


Powered by Joomla!

Generated: 30 March, 2011, 08:44

to implement Captcha Webservice? /*===========================================================================+ | Copyright (c) 2001. Alternately. Where is the Controller Code for OA Framework. I will explain steps briefly here:1.A text field into which user will enter their response.Named "CaptchaImageField" of style Image You may even Right click on corporateBrandingImage. For the steps on how to create a simple HelloWorld Page in OAFramework. 2011. this time with new Image URL and a new KEY. This causes the Captcha Webservice to be called again. This gives users a possibility of attempting Captcha text entry as many times. 5.anilpassi.hello_01.webui. then I am displaying the debug text "Failure with CAPTCHA" In case the users response is incorrect.getParameter("captchaWordResponseField")). USA | | All rights reserved. you can store these in some global variable or a hidden sets of fields. 2.ak. Assign the image URL returned by Web Service to CaptchaImageField. pageContext. here are the java files generated.apps.com Powered by Joomla! Generated: 30 March. the OA Framework page Lets create three extra fields. Redwood Shores.toString() . lets create basic page/screen. The KEY along with user response will be sent to CAPTCHA Webservice. for debugging. 08:44 . has URL of the Image. Create instance of ClientAuthModel() and set userid and password. If the WebService API returns false. in OA Framework. Modify the controller code. CA. alongwith the KEY of Image. 2005 Oracle Corporation. the user will see a new image appearing on the page. The sourcecode is provided at the bottom of the article. that displays the results of Captcha WebService validation. The returned object[named word]. we render the page again[by redirecting the page to itself]. http://oracle. Field 3:-A button Go of type Submit Form You can optionally create another field. and also the KEY used for validation. However. pageContext. In that code.getSessionValue("captchaGUIDvalue"). please visit [link for simple OAF Page ] In this example. Create instance of CaptchaServiceStub() and invoke Webservice method GetNewWord() 3. Hence with every wrong attempt. Field 2:. to make calls to Captcha remote Web Service. [a piece of code that is executed when page renders]. This is done by ValidateImageWord(cm. Hence I am setting these two in session variables. Field 1:.Apps Anyway. The response text entered by user is sent to Web Service for validation. we make a call to Webservice. The result of the GetNewWord() is an Object of type CaptchaImageWordModel [word] 4. Now. | +===========================================================================+ | HISTORY | +===========================================================================*/ package oracle. and paste that into RNforButton.

* @param pageContext the current OA page context * @param webBean the web bean corresponding to the region */ public void processRequest(OAPageContext pageContext.OAControllerImpl. import xxfreecaptcha01.Apps import oracle.webui. cm = new ClientAuthModel().framework. You need to get one for yourself from textdisguise.VersionInfo.findChildRecursive("captchaImageGUID"). CaptchaServiceStub cs.setText(pageContext. // fieldHelloName.framework. /** * Controller for .findChildRecursive("CaptchaImageField").. word = cs.framework.getUrl()).java.apps.getCaptchaImageGuid()). i am changing authentication details here. String clientPassword = "!:ARlmLn.CaptchaServiceStub.framework. cm. Good Luck this time"). public static final boolean RCS_ID_RECORDED = VersionInfo.fnd. */ public class MainRNCO extends OAControllerImpl { public static final String RCS_ID="$Header$". import oracle. } catch ( Exception exx ) { fieldHelloName.putSessionValue("captchaGUIDvalue".beans. /** * Layout and page setup logic for a region.webui.CaptchaImageWordModel.webui.processRequest(pageContext.beans.message.apps. ClientAuthModel cm.GetNewWord(cm).com try { String clientGuid = "9Xfaf972b-ff85-483e-a132-b6c4f72e27e4".apps.anilpassi. CaptchaImageWordModel word.word.fnd.OAPageContext. "%packagename%").fnd.HashMap..OAImageBean .fnd.common." !!!! Exception " + exx). 2011.webui."Welcome.OAWebBean. OAWebBean webBean) { OAMessageTextInputBean fieldHelloName = (OAMessageTextInputBean)webBean.com Powered by Joomla! Generated: 30 March. import oracle.ClientAuthModel.webui.framework. import oracle. import xxfreecaptcha01. import oracle.setGuid(clientGuid).beans. cs = new CaptchaServiceStub(). cm.collections. import oracle.fnd.apps.fnd.OAException. cimage.recordClassVersion(RCS_ID.setPassword(clientPassword). pageContext.CDKN&%Q{s_h|u<r".OAMessageTextInputBean.apps.fnd.OAWebBeanConstants.util. import oracle.findChildRecursive("HelloName").sun. * @param pageContext the current OA page context * @param webBean the web bean corresponding to the region */ http://oracle. OAImageBean cimage = (OAImageBean)webBean. 08:44 . webBean).webui. import com. OAMessageTextInputBean fieldcaptchaGUID = (OAMessageTextInputBean)webBean.fnd.setSource(word.apps. } super. import oracle.setText(pageContext.framework. import xxfreecaptcha01.apps. } /** * Procedure to handle form submissions for form elements in * a region.framework.apps. //note.P.

String clientPassword = "!:ARlmLn.setText(pageContext."Failure with CAPTCHA" ).processFormRequest(pageContext.ValidateImageWord(cm. You need to get one for yourself from textdisguise.setGuid(clientGuid).getParameter("captchaWordResponseField")). cm.com String clientGuid = "9Xfaf972b-ff85-483e-a132-b6c4f72e27e4". CaptchaImageWordModel word. HashMap params = new HashMap(). cm. CaptchaServiceStub cs1.setPassword(clientPassword). if(ret.lang.getSessionValue("captchaGUIDvalue"). pageContext. word = cs1. pageContext.forwardImmediatelyToCurrentPage(params.toString() =="true") { fieldHelloName. CaptchaServiceStub cs. OAException.true.findChildRecursive("HelloName"). } else { fieldHelloName. * Date Created: Sun Jan 03 12:52:32 GMT 2007 * * <pre> http://oracle. webBean).toString() == "false") { cs1 = new CaptchaServiceStub().P.INFORMATION). pageContext. that will be used by Java OA Framework? Please find the three classes below package xxfreecaptcha01.Apps public void processFormRequest(OAPageContext pageContext.} } } How about the Stub Files.setText(pageContext. OAMessageTextInputBean fieldHelloName = (OAMessageTextInputBean)webBean. i am changing authentication details here. My GUID was=>" + pageContext.getSessionValue("captchaGUIDvalue") ).OAWebBeanConstants. } super.findChildRecursive("captchaWordResponseField").findChildRecursive("CaptchaImageField").CDKN&%Q{s_h|u<r". OAMessageTextInputBean fieldcaptchaGUID = (OAMessageTextInputBean)webBean.ADD_BREAD_CRUMB_NO).com Powered by Joomla! Generated: 30 March.Boolean ret. ClientAuthModel cm.findChildRecursive("captchaImageGUID"). 2011.toString() . OAMessageTextInputBean fieldcaptchaResponse = (OAMessageTextInputBean)webBean. java. ret = cs. cm = new ClientAuthModel(). /** * Generated by the Oracle9i JDeveloper Web Services Stub/Skeleton Generator. OAWebBean webBean) { try { //note. if (ret. cs = new CaptchaServiceStub(). 08:44 .GetNewWord(cm). } } catch ( Exception exx ) {throw new OAException("Exception occured" + exx.anilpassi. OAImageBean cimage = (OAImageBean)webBean."Success with CAPTCHA" ).

apache.encoding.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 class CaptchaImageWordModel { private String m_CaptchaImageGuid. /** * Generated by the Oracle9i JDeveloper Web Services Stub/Skeleton Generator.util. } public void setUrl(String Url) { m_Url = Url.apache.soap.apache. import java.BeanSerializer. } public String getCaptchaImageGuid() { return m_CaptchaImageGuid.QName.OracleSOAPHTTPConnection.jdeveloper. String Url) { m_CaptchaImageGuid = CaptchaImageGuid.net.com Powered by Joomla! Generated: 30 March. private String m_Url. } public String getUrl() { return m_Url. import org. * Date Created: Wed Jan 03 12:52:33 GMT 2007 * WSDL URL: http://www.soap. } } package xxfreecaptcha01.soap.w3c.webservices.transport.soap. 08:44 .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. 2011.textdisguise. import org.xml.Envelope.Vector.soap.0. } public void setCaptchaImageGuid(String CaptchaImageGuid) { m_CaptchaImageGuid = CaptchaImageGuid.messaging.dom.soap. import org.http. import org.com/TextDisguise/CaptchaService/CaptchaService.util. import org. import org. import oracle.Body. public CaptchaImageWordModel() { } public CaptchaImageWordModel(String CaptchaImageGuid.encoding. import java.Element. Current version is v1.apache.apache.URL. import oracle.Message.0. Release Date: 2005-12-22 http://oracle.runtime. import org.soap.apache. m_Url = Url.SOAPMappingRegistry.anilpassi.WrappedDocLiteralStub.soapenc.

msg.com/TextDisguise/CaptchaService/CaptchaService.getBody().textdisguise. Body requestBody = new Body().add(new Object[] {"cam".receiveEnvelope(). Vector requestData = new Vector(). cam}). xxfreecaptcha01. String wrappingName = "GetNewWord". msg.add(new Object[] {"cam". Message msg = new Message(). Vector requestBodyEntries = new Vector(). word}). captchaImageGuid}). requestData. Vector requestData = new Vector(). requestEnv).com Powered by Joomla! Generated: 30 March.getBodyEntries(). requestBodyEntries.add(new Object[] {"word". cam}). http://oracle. requestData.addElement(toElement(wrappingName. public CaptchaImageWordModel GetNewWord(ClientAuthModel cam) throws Exception { URL endpointURL = new URL(endpoint). Body requestBody = new Body().com/TextDisguise/CaptchaService/".setBody(requestBody).textdisguise.send(endpointURL.setBody(requestBody). 08:44 . Envelope requestEnv = new Envelope(). Message msg = new Message(). String targetNamespace = "http://www. } public Boolean ValidateImageWord(ClientAuthModel cam.add(new Object[] {"captchaImageGuid". requestBodyEntries. Envelope responseEnv = msg. requestEnv. String wrappingName = "ValidateImageWord". Vector responseData = responseBody. 2011. String targetNamespace = "http://www. targetNamespace. msg.elementAt(0).anilpassi.com/TextDisguise/CaptchaService/ValidateImageWord".setSOAPTransport(m_httpConnection). requestBody.setSOAPTransport(m_httpConnection).setBodyEntries(requestBodyEntries). private SOAPMappingRegistry m_smr = null. String word) throws Exception { URL endpointURL = new URL(endpoint). Body responseBody = responseEnv. private OracleSOAPHTTPConnection m_httpConnection = null. requestData)).class). "http://www. return (CaptchaImageWordModel)fromElement((Element)responseData.Apps */ public class CaptchaServiceStub extends WrappedDocLiteralStub { public CaptchaServiceStub() { m_httpConnection = new OracleSOAPHTTPConnection(). requestBody.asmx". requestData. msg. "http://www. requestData)).com/TextDisguise/CaptchaService/". targetNamespace.textdisguise.send(endpointURL. Envelope requestEnv = new Envelope().CaptchaImageWordModel.textdisguise. requestEnv.com/TextDisguise/CaptchaService/GetNewWord".textdisguise.addElement(toElement(wrappingName.setBodyEntries(requestBodyEntries). String captchaImageGuid. requestEnv). Vector requestBodyEntries = new Vector(). requestData. } public String endpoint = "http://www.

java. Vector responseData = responseBody.getBody().add(new Object[] {"captchaImageGuid".getBodyEntries().Boolean. java. String Password) { m_Guid = Guid.class). "http://www. Body responseBody = responseEnv.getBody(). * 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 class ClientAuthModel { private String m_Guid.anilpassi.com Powered by Joomla! Generated: 30 March. requestBodyEntries. Envelope responseEnv = msg.com/TextDisguise/CaptchaService/". requestData)). msg. Body responseBody = responseEnv.getBodyEntries(). requestEnv).elementAt(0). String wrappingName = "AbandonImageWord".setBody(requestBody). 08:44 .add(new Object[] {"cam". Vector responseData = responseBody. Vector requestBodyEntries = new Vector(). return (Boolean)fromElement((Element)responseData. Envelope requestEnv = new Envelope().class).Apps Envelope responseEnv = msg. } public Boolean AbandonImageWord(ClientAuthModel cam.addElement(toElement(wrappingName.com/TextDisguise/CaptchaService/AbandonImageWord". requestData.textdisguise. String targetNamespace = "http://www. Message msg = new Message(). targetNamespace. public ClientAuthModel() { } public ClientAuthModel(String Guid.send(endpointURL. requestEnv. requestBody.receiveEnvelope(). Vector requestData = new Vector(). 2011. captchaImageGuid}).receiveEnvelope().textdisguise.setSOAPTransport(m_httpConnection). Body requestBody = new Body(). requestData. http://oracle. cam}). private String m_Password.setBodyEntries(requestBodyEntries).lang. msg. return (Boolean)fromElement((Element)responseData.elementAt(0).lang. /** * Generated by the Oracle9i JDeveloper Web Services Stub/Skeleton Generator. } } package xxfreecaptcha01. String captchaImageGuid) throws Exception { URL endpointURL = new URL(endpoint).Boolean.

anilpassi. } } http://oracle. 2011.Apps m_Password = Password. } public void setGuid(String Guid) { m_Guid = Guid. 08:44 . } public void setPassword(String Password) { m_Password = Password. } public String getGuid() { return m_Guid. } public String getPassword() { return m_Password.com Powered by Joomla! Generated: 30 March.

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->