Thursday, 7 August 2014

Maven Portlet Development - For Command Prompt Lovers


  • Navigate to the folder where you want to create Liferay plugin
  • Execute the command mvn archetype:generate. This will take some time for the first time. You might need to rerun this command for twice to get it complete.
  • It will ask to choose a number or apply filter. Enter filter for Liferay, simply type liferay and hit enter.
  • Select proper archetype for particular pulgin e.g for Liferay portlet pulgin select liferay-portlet-archetype
  • Enter liferay portlet archetype version. E. g. Version of Liferay, for our case we need to choose 6.2.0-RC5.
  • Define value for property 'groupId': :org.wellOfJava.portlet. i. e. groupId will identify your project uniquely across all projects.
  • Define value for property 'artifactId': : sample-portlet. i. e. Name of the portlet. 
  • Define value for property 'version':  1.0-SNAPSHOT: : 1.0-SNAPSHOT  (or here you can just press enter)
  • Define value for property 'package':  org.wellOfJava.portlet: : org.wellOfJava.portlet. That will be package structure of your portlet.
  • Add properties tag in pom.xml after </dependencies> tag and before </project> end tag
  • <properties>
    <liferay.version>6.2.0-RC5</liferay.version>
    <liferay.maven.plugin.version>6.2.0-RC5</liferay.maven.plugin.version>
    </properties>
    
  • Navigate to the directory, where pom.xml of the plugin exist. Execute the command mvn clean install –DskipTests. For building war file
  • After successful build import into eclipse

Wednesday, 30 July 2014

Simple Captcha Text Producer Implementation

This blog is in reference to the Liferay hook in Marketplace. Following is the link for the Captcha Internationalization.
Captcha Internationalization Hook

Same Concept can be used to implement multilingual Captcha for any web site.

Simple Captcha is the opensource implementation for captcha service. Please check the following URL for more details about SimpleCaptcha.
http://simplecaptcha.sourceforge.net/

Simple Captcha is providing textProducer for Captcha implementation. The textProducer class produces a string with some random Character or Numbers or Alphanumeric. Just simply add that captcha as attribute into the Session. Give an input Field in the HTML form for user to insert captcha text. Once user submits the form, compare the input field with the value stored in the session. This is how captcha will work.

Simple captcha is providing textProducer for Arabic, Chinese and Digits. Most of the time digit in captcha will work fine. In case customer asks for regional language for the captcha. You need to simply make your own implementation for the textProducer. Please refer the implementation of the ArabicTextProducer from SimpleCaptcha.
http://sourceforge.net/p/simplecaptcha/code/ci/master/tree/Java/src/nl/captcha/text/producer/ArabicTextProducer.java

You just need to implement TextProducer interface from SimpleCaptcha and provide your own implementation for your language. You can refer following code that I have developed for Gujarati text producer. 

package com.wellofjava.captcha.text.producer;

import nl.captcha.text.producer.DefaultTextProducer;
import nl.captcha.text.producer.TextProducer;

public class GujaratiTextProducer implements TextProducer {

    static final int DEFAULT_LENGTH = 5;

 private static char[] GUJARATI_CHARS = { '\u0627', '\u0A85', '\u0A86',
   '\u0A87', '\u0A88', '\u0A89', '\u0A8A', '\u0AE6', '\u0AE7',
   '\u0AE8', '\u0AE9', '\u0AEA', '\u0AEB', '\u0AEC' };
  
    private final TextProducer _txtProd;
    
    public GujaratiTextProducer() {
        this(DEFAULT_LENGTH);
    }
    
    public GujaratiTextProducer(int length) {
        _txtProd = new DefaultTextProducer(length, GUJARATI_CHARS);
    }
    
    @Override
    public String getText() {
        return _txtProd.getText();
    }
}

Tuesday, 22 July 2014

Liferay HSQL DB Access

        Normally at the time of development, we have fixed name of database which will be used for production environment. We configure the same DB in our local or development environment for the build. But in case of doing POC, preparing demo for PreSales or making some reusable component, we might not have access to such environment, or as per the system requirement, It might not be a good idea to spend time after configuring other DB.

        Liferay is using HSQL database by default. Here is the steps to access that HSQL database using DatabaseManager.


  1. Go to {server}\lib\ext , Make you have hsql.jar file under that location. If it's not there. Find the location of that jar.
  2. Open command prompt with the location of step-1
  3. Run this command in command prompt "java -cp hsql.jar org.hsqldb.util.DatabaseManager"
  4. Database manager will open as per the below image.
  5. Select "HSQL Database Engine Standalone" for dropbox of type.
  6. Now in URL text field you need to enter location of the DB file. So if you check in your Liferay bundle. There would be lportal HSql DB in "{liferay-portal}\data\hsql" directory. So you need to give path to DB as like "{liferay-portal}\data\hsql\lportal", here lportal is the DB.
  7. Username will be 'SA' and password will be blank. 
        Once the DB is connected. You will be able to see the list of the tables on the left hand side. As well you can execute any query using the same browser.


       One important point, If the Liferay instance is running. There would be lock on DB. So you won't be able to access the DB. 

Monday, 14 July 2014

Mobile/SMS Verification


        Now a days, Most of the site needs to verify the mobile number and email address of their users for security purpose. Liferay is providing email verification OOB. I have developed a reusable component to verify mobile number of the customer using SMS service.

        This plugin will help to integrate that functionality directly to the Liferay portal.

        Key Features
  • Admin can enable/disable mobile verification very easily.
  • Mobile verification can be set to be mandatory/optional.
  • Further development depending upon mobile verification can be done easily. As mobile number and its status is stored in User Custom Attribute.

        Component is available in Liferay Marketplace.
        Mobile Verification

        Let me know if you need any further information about this component. 

Tuesday, 1 July 2014

LDAP server Error Codes

Code(decimal)Error code (string)Description
0LDAP_SUCCESSSuccess
1LDAP_OPERATIONS_ERROROperations error
2LDAP_PROTOCOL_ERRORProtocol error
3LDAP_TIMELIMIT_EXCEEDEDTimelimit exceeded
4LDAP_SIZELIMIT_EXCEEDEDSizelimit exceeded
5LDAP_COMPARE_FALSECompare false
6LDAP_COMPARE_TRUECompare true
7LDAP_STRONG_AUTH_NOT_SUPPORTEDStrong authentication not supported
8LDAP_STRONG_AUTH_REQUIREDStrong authentication required
9LDAP_PARTIAL_RESULTSPartial results
16LDAP_NO_SUCH_ATTRIBUTENo such attribute
17LDAP_UNDEFINED_TYPEUndefined attribute type
18LDAP_INAPPROPRIATE_MATCHINGInappropriate matching
19LDAP_CONSTRAINT_VIOLATIONConstraint violation
20LDAP_TYPE_OR_VALUE_EXISTSType or value exists
21LDAP_INVALID_SYNTAXInvalid syntax
32LDAP_NO_SUCH_OBJECTNo such object
33LDAP_ALIAS_PROBLEMAlias problem
34LDAP_INVALID_DN_SYNTAXInvalid DN syntax
35LDAP_IS_LEAFObject is a leaf
36LDAP_ALIAS_DEREF_PROBLEMAlias dereferencing problem
48LDAP_INAPPROPRIATE_AUTHInappropriate authentication
49LDAP_INVALID_CREDENTIALSInvalid credentials
50LDAP_INSUFFICIENT_ACCESSInsufficient access
51LDAP_BUSYDSA is busy
52LDAP_UNAVAILABLEDSA is unavailable
53LDAP_UNWILLING_TO_PERFORMDSA is unwilling to perform
54LDAP_LOOP_DETECTLoop detected

64LDAP_NAMING_VIOLATIONNaming violation
65LDAP_OBJECT_CLASS_VIOLATIONObject class violation
66LDAP_NOT_ALLOWED_ON_NONLEAFOperation not allowed on nonleaf
67LDAP_NOT_ALLOWED_ON_RDNOperation not allowed on RDN
68LDAP_ALREADY_EXISTSAlready exists
69LDAP_NO_OBJECT_CLASS_MODSCannot modify object class
70LDAP_RESULTS_TOO_LARGEResults too large

80LDAP_OTHERUnknown error
81LDAP_SERVER_DOWNCan't contact LDAP server
82LDAP_LOCAL_ERRORLocal error
83LDAP_ENCODING_ERROREncoding error
84LDAP_DECODING_ERRORDecoding error
85LDAP_TIMEOUTTimed out
86LDAP_AUTH_UNKNOWNUnknown authentication method
87LDAP_FILTER_ERRORBad search filter
88LDAP_USER_CANCELLEDUser cancelled operation
89LDAP_PARAM_ERRORBad parameter to an ldap routine
90LDAP_NO_MEMORYOut of memory

Monday, 26 August 2013

Issue with android webview

I was working with android application. I have found an issue in webview component of android. Html is being rendered in web view easily for older versions of android. But in case of android 4.2.2, i have found that it is rendering blank screen in web view.

I have not dig into the issue alot. But i could solve the issue using adding one property in menifest file of my application.


android:hardwareAccelerated="false"
This line disables hardware acceleration.

Tuesday, 2 April 2013

Openfire Custom IQ Handler


XMPP is providing plenty of Rosters. That we can use to develop a full fledged chat application. But Openfire is delighting its developers by providing custom plugins development.

I have been needed to add a plugin that would be helpful to search users from the server. On the application side i needed a list of users with some patterns.

I have developed following plugin code for that. This plugin gets installed on server side. It mainly deals with a custom IQ. Whenever application will request for that particular custom IQ. Server will pass flow to this custom plugin.

For developing custom iq. You need to extend IQHandler class. As well need to implement some of the methods from that class to provide your functionality.

public class SearchIQhanlder extends IQHandler { // extend IQ handler class to create a custom iq request
    private IQHandlerInfo info;
    
    public SearchIQhanlder(String moduleName)
    {
  super(moduleName);
  info = new IQHandlerInfo("query", "custom:iq:Search"); // provide a custom unique query signature for your IQ
    }
    
    public IQHandlerInfo getInfo()
    {
 return info;
    }
    
    public IQ handleIQ(IQ packet) throws UnauthorizedException{ // this method will handle the request. all login will go into this method.
 IQ result = IQ.createResultIQ(packet);
 try {
  // if you want to handle specific query. you need to check for its type. I needed this as i have wrote the plugin to provide some information to application. If you are setting some values on server side. You should use set type.
  IQ.Type type = packet.getType(); 
  result.setChildElement("query", "custom:iq:Search");
  Element query = result.getChildElement();
  // conditionally hanlde get or set type of IQ. I was not using set type. So i have make it as "not acceptable"
  if (type.equals(IQ.Type.get)) {
  } else {
      result.setChildElement(packet.getChildElement().createCopy());
      result.setChildElement("coord", "custom:iq:Search#response");    
      result.setError(PacketError.Condition.not_acceptable);
  }
  return result;
 } catch (Exception e) {
  // if you face any issue while processing. You can response back with "bad request"
  result.setChildElement(packet.getChildElement().createCopy());
  result.setChildElement("coord", "custom:iq:Search#response");    
  result.setError(PacketError.Condition.bad_request);
 } 
 return result;
    }
    
    public void initialize(XMPPServer server) {
 super.initialize(server);
    }    
}

Now you need to create one plugin class. That class would be extending plugin class. In that class you need to create one instance of IQ handler class that you have developed. Assign that handler class to IQ router. IQ router is kind bus of openfire that is managing roster requests.

 IQHandler handler = new SearchIQhanlder("SearchIQhanlder");
 IQRouter iqRouter = XMPPServer.getInstance().getIQRouter();
 iqRouter.addHandler(handler);  

On the application side you need to create one new IQ to request for your custom IQHanlder. Following is the example of what i have created.

<iq type='get' id='search' from='"+ Datas.jid.getLittleJid() + "'>
<query xmlns='custom:iq:Search'>
<search>"+ usernamefield.getText() +"</search>
</query>
</iq>

That is all to create a custom IQHandler. It is very easy to create such IQ. As well this would be very helpful for application development.

Let me know if you need any help regarding the same.