Saturday 22 August 2015

Debug enabling on Servers

WEBLOGIC Server : folder path : /user_projects/domains/base_domain/bin/setDomainEnv.sh

JAVA_OPTIONS="${JAVA_OPTIONS} ${JAVA_PROPERTIES} -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=25801,server=y,suspend=n 
  .........." 

JBOSS Server : folder path : bin/standalone-conf.bat

"%JAVA%" -agentlib:jdwp=transport=dt_socket,address=25801,server=y,suspend=n %JAVA_OPTS% ^
"-Dorg.jboss.boot.log.file=%JBOSS_LOG_DIR%\boot.log" ^
"-Dlogging.configuration=file:%JBOSS_CONFIG_DIR%/logging.properties" ^
    -jar "%JBOSS_HOME%\jboss-modules.jar" ^
    -mp "%JBOSS_MODULEPATH%" ^
    -jaxpmodule "javax.xml.jaxp-provider" ^
     org.jboss.as.standalone ^
    -Djboss.home.dir="%JBOSS_HOME%" ^
     %*



TOMCAT Server : folder path : bin/catalina.bat

%_EXECJAVA% -agentlib:jdwp=transport=dt_socket,address=25801,server=y,suspend=n %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%

Liferay 6.x cstom plugin or out of box web services consumption via Java program

Required class path dependencies are :


  1. portal-client
  2. axis
  3. axis-jaxrpc
  4. commons-logging
  5. commons-discovery
  6. wsdl4j

Java code:

public class CompetencyRemoteAuth {

                static final Logger LOGGER = LoggerFactory
                                                .getLogger(CompetencyRemoteAuth.class);

                static final String LIFERAY_USER_NAME = "satya.kolliboina@gmail.com";
                static final String LIFERAY_USER_PASSWORD = "test1";

                static final String USER_SERVICE = "Portal_UserService";
                static final String COMPANY_SERVICE = "Portal_CompanyService";
                static final String Competency_AUTHENTICATION_SERVICE = "Plugin_Competency_CompetencyAuthenticationService";
                static final String Competency_REGISTRATION_SERVICE = "Plugin_Competency_RegistrationService";

                /**
                * @param args
                */
                public static void main(String[] args) {
                                try {
                                                System.out.println("UserEmail: " + args[0] + "...user pwd:"+args[1]);
                                                URL CompetencyAuthenticationServiceEndPoint = _getURL(args[0],args[1], Competency_AUTHENTICATION_SERVICE);
                                             
                                                System.out.println("Try lookup CompetencyAuthentication Service by End Point: "         + CompetencyAuthenticationServiceEndPoint + "...");
                                             
                                                URL companyServiceEndPoint = _getURL(args[0],args[1], COMPANY_SERVICE);
                                             
                                                System.out.println("Try lookup company Service by End Point: "               + CompetencyAuthenticationServiceEndPoint + "...");
                                             
                                                CompetencyAuthenticationServiceSoapServiceLocator CompetencyAuthenticationLocator = new CompetencyAuthenticationServiceSoapServiceLocator();
                                                CompetencyAuthenticationServiceSoap CompetencyAuthenticationService = CompetencyAuthenticationLocator.getPlugin_Competency_CompetencyAuthenticationService(CompetencyAuthenticationServiceEndPoint);
                                                                             
                                                ((Plugin_Competency_CompetencyAuthenticationServiceSoapBindingStub) competencyAuthenticationService)
                                                .setUsername(args[0]);
                                                ((Plugin_Competency_CompetencyAuthenticationServiceSoapBindingStub) competencyAuthenticationService)
                                                .setPassword(args[1]);
             
                                             
                                                CompanyServiceSoapServiceLocator locatorCompany = new CompanyServiceSoapServiceLocator();
                                                CompanyServiceSoap companyService = locatorCompany.getPortal_CompanyService(companyServiceEndPoint);
                                                CompanySoap companySoap = companyService.getCompanyByVirtualHost("localhost");

                                                System.out.println("Get UserID" + "...");
                                                long userId = 0;
                                             
                                             
                                                userId = CompetencyAuthenticationService.CompetencyAuthentication(args[0], args[1], args[2]);
                                                System.out.println("UserId for user named " + args[0]   + " is " + userId);

                                             

                                } catch (RemoteException re) {
                                                LOGGER.error(re.getClass().getCanonicalName()
                                                                                + re.getMessage());
                                } catch (ServiceException se) {
                                                LOGGER.error(se.getClass().getCanonicalName()
                                                                                + se.getMessage());
                                }
                }
             
                /**
                * Get the URL Liferay SOAP Service
                *
                 * @param remoteUser
                * @param password
                * @param serviceName
                * @return
                */
                private static URL _getURL(String remoteUser, String password, String serviceName) {
//http://localhost:9090/CompetencyAuthentication-portlet/api/axis/Plugin_Competency_CompetencyAuthenticationService?wsdl
                                final String LIFERAY_PROTOCOL = "http://";
                                final String LIFERAY_TCP_PORT = "9090";
                                final String LIFERAY_FQDN = "127.0.0.1";
                                String LIFERAY_AXIS_PATH = "";
                             
                                try {
                                                if(serviceName.split("_")[0].equalsIgnoreCase("Plugin")){
                                                                LIFERAY_AXIS_PATH = "/CompetencyMobility-portlet/api/secure/axis/";
                                                }else{
                                                                LIFERAY_AXIS_PATH = "/api/secure/axis/";
                                                }
                                                return new URL(LIFERAY_PROTOCOL
                                                                                + URLEncoder.encode(remoteUser, "UTF-8") + ":"
                                                                                + URLEncoder.encode(password, "UTF-8") + "@" + LIFERAY_FQDN
                                                                                + ":" + LIFERAY_TCP_PORT + LIFERAY_AXIS_PATH + serviceName);
                                } catch (Exception e) {
                                                LOGGER.error(e.getMessage());
                                                e.printStackTrace();
                                                return null;
                                }
                }
}

Tuesday 18 August 2015

Coding standards to develop artifact

1. If we get any errors, while performing add/update operations then return previous request & response (which contains user entered data). By using the snippet:

PortalUtil.copyRequestParameters(request, response);

2. If necessary we need to write custom validator, to validate custom entities.

3. While writing implementation to CRUD operations in Liferay's service builder xxxxLocalServiceImpl class, make sure that you are not re-writing available operations in xxxxLocalServiceBaseImpl.

xxxLocalServiceBaseImpl CRUD operations are available. We are extending it in our xxxxLocalServiceImpl. So, no need to write again those CRUD operations on xxxxLocalServiceImpl class.