Monday, March 22, 2010

How to Access Spring Application Context from JSR-168 Portlet

Step 1 :

Make sure you have spring-webmvc-portlet.jar in your project classpath

Step 2 :
Make sure you defined your spring files in web.xml like this
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext-dao.xml
classpath:applicationContext-services.xml
classpath:applicationContext-schedule.xml
classpath:applicationContext-ajax.xml
</param-value>
</context-param>

Optional
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

Step 3 :
Access like this.

PortletContext pc = this.getPortletContext();
ApplicationContext context = PortletApplicationContextUtils.getWebApplicationContext(pc);
SessionConfigure sessionConfigure = (SessionConfigure) context.getBean("sessionConfigure");

Tuesday, March 9, 2010

Basic Log4j tutorial

Step 1 :

create file log4j.properties in $project_home/src/

log4j.appender.portlet = org.apache.log4j.FileAppender
# log file will be in tomcat/logs/
log4j.appender.portlet.File = ${catalina.home}/logs/privatemessage.log
log4j.appender.portlet.Append = false
log4j.appender.portlet.layout = org.apache.log4j.PatternLayout
log4j.appender.portlet.layout.ConversionPattern = %d{ABSOLUTE} [%t] %-5p %-30.30c{2} %x - %m %n

# only log errors
log4j.rootCategory=WARN, portlet
# log trace messages from this package and sub packages
log4j.logger.com.cisco.project=TRACE


Step 2 :

add these lines to web.xml
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>

Step 3 :
Use logger in your java classes, before add log4j library to your project classpath
// add imports
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

// define
private static Log logger = LogFactory.getLog(PostLogin.class);

// use this way
logger.trace(" Begin PostLoginHook.... ");

if ( logger.isDebugEnabled() ) {
logger.debug("inside method");
}



Thursday, March 4, 2010

Liferay 5.2.3 Solr Integration

Liferay Solr Integration

Environment:
Liferay 5.2.3 or 5.2.5
Solr 1.4
solr-web-5.2.3.1.war

Follow these steps

Step 1:

Add the below line to catalina.sh or catalina.bat, i.e setting the $SOLR_HOME dir
(/content/liferay/data/solr)

set JAVA_OPTS=%JAVA_OPTS% -Dsolr.solr.home="C:\solr1"

Step 2:

Copy conf directory from solr downloaded (apache-solr-1.4.0\example\solr\conf) to the $SOLR_HOME (/content/liferay/data/solr) from step 1

Step 3:

Replace $SOLR_HOME/conf/schema.xml with solr-web-5.2.3.1/WEB-INF/conf/schema.xml

Step 4:
Edit $SOLR_HOME/conf/solrconfig.xml
change this line with appropriate dir ...
to /content/liferay/data/solr/data/

Step 5:
Restart

Step 6:
deploy your solr-web from control panel or deploy dir, also you can download that from here solr-web-5.2.3.1

Step 7:
run reindex in liferay control panel->server administration

Step 8:
Restart




Wednesday, March 3, 2010

Liferay Jackrabbit Oracle integration

Follow these steps to integrate Liferay, Jackrabbit, and Oracle.

Step 1 :

Copy the below lines into portal-ext.properties

dl.hook.impl=com.liferay.documentlibrary.util.JCRHook
jcr.initialize.on.startup=true
jcr.workspace.name=liferay
jcr.node.documentlibrary=documentlibrary
jcr.jackrabbit.repository.root=${liferay.home}/data/jackrabbit
jcr.jackrabbit.config.file.path=${jcr.jackrabbit.repository.root}/repository.xml
jcr.jackrabbit.repository.home=${jcr.jackrabbit.repository.root}/home
jcr.jackrabbit.credentials.username=none
jcr.jackrabbit.credentials.password=none



Step 2 :

Replace the content of liferay-installation/data/jackrabbit/repository.xml with below xml text and then restart

<?xml version="1.0"?> <Repository> <!--<FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem"> <param name="path" value="${rep.home}/repository" /> </FileSystem>--> <!-- Database File System (Cluster Configuration) This is sample configuration for oracle persistence that can be used for clustering Jackrabbit. For other databases, change the connection, credentials, and schema settings. --> <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem"> <param name="driver" value="oracle.jdbc.driver.OracleDriver"/> <param name="url" value="" /> <param name="user" value="" /> <param name="password" value="" /> <param name="schema" value="oracle"/> <param name="schemaObjectPrefix" value="J_R_FS_"/> </FileSystem> <Security appName="Jackrabbit"> <AccessManager class="org.apache.jackrabbit.core.security.SimpleAccessManager" /> <LoginModule class="org.apache.jackrabbit.core.security.SimpleLoginModule"> <param name="anonymousId" value="anonymous" /> </LoginModule> </Security> <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="liferay" /> <Workspace name="${wsp.name}"> <!--<FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem"> <param name="path" value="${wsp.home}" /> </FileSystem> <PersistenceManager class="org.apache.jackrabbit.core.persistence.bundle.BundleFsPersistenceManager" />--> <!-- Database File System and Persistence (Cluster Configuration) This is sample configuration for mysql persistence that can be used for clustering Jackrabbit. For other databases, change the connection, credentials, and schema settings. --> <PersistenceManager class="org.apache.jackrabbit.core.state.db.SimpleDbPersistenceManager"> <param name="driver" value="oracle.jdbc.driver.OracleDriver"/> <param name="url" value="" /> <param name="user" value="" /> <param name="password" value="" /> <param name="schema" value="oracle"/> <param name="schemaObjectPrefix" value="J_PM_${wsp.name}_" /> <param name="externalBLOBs" value="false" /> </PersistenceManager> <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem"> <param name="driver" value="oracle.jdbc.driver.OracleDriver"/> <param name="url" value="" /> <param name="user" value="" /> <param name="password" value="" /> <param name="schema" value="oracle"/> <param name="schemaObjectPrefix" value="J_FS_${wsp.name}_"/> </FileSystem> </Workspace> <Versioning rootPath="${rep.home}/version"> <!--<FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem"> <param name="path" value="${rep.home}/version" /> </FileSystem> <PersistenceManager class="org.apache.jackrabbit.core.persistence.bundle.BundleFsPersistenceManager" />--> <!-- Database File System and Persistence (Cluster Configuration) This is sample configuration for mysql persistence that can be used for clustering Jackrabbit. For other databases, change the connection, credentials, and schema settings. --> <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem"> <param name="driver" value="oracle.jdbc.driver.OracleDriver"/> <param name="url" value="" /> <param name="user" value="" /> <param name="password" value="" /> <param name="schema" value="oracle"/> <param name="schemaObjectPrefix" value="J_V_FS_"/> </FileSystem> <PersistenceManager class="org.apache.jackrabbit.core.state.db.SimpleDbPersistenceManager"> <param name="driver" value="oracle.jdbc.driver.OracleDriver"/> <param name="url" value="" /> <param name="user" value="" /> <param name="password" value="" /> <param name="schema" value="oracle"/> <param name="schemaObjectPrefix" value="J_V_PM_" /> <param name="externalBLOBs" value="false" /> </PersistenceManager> </Versioning> <!-- Cluster Configuration This is sample configuration for mysql persistence that can be used for clustering Jackrabbit. For other databases, change the connection, credentials, and schema settings. --> <!--<Cluster id="node_1" syncDelay="5"> <Journal class="org.apache.jackrabbit.core.journal.DatabaseJournal"> <param name="revision" value="${rep.home}/revision"/> <param name="driver" value="oracle.jdbc.driver.OracleDriver"/> <param name="url" value="" /> <param name="user" value="" /> <param name="password" value="" /> <param name="schema" value="oracle"/> <param name="schemaObjectPrefix" value="J_C_"/> </Journal> </Cluster>--> </Repository>