Search This Blog

Friday, January 21, 2011

Deploying Hippo on JBoss 4.2.3GA and PostgresQL 8.3

For a client of us we developed a public website with the Hippo CMS. Hippo CMS is a Java based Content Management System based on the Content Repository API. Hippo runs standard on Apache Tomcat and Mysql. We wanted to deploy Hippo on JBoss 4.2.3GA with Postgres 8.3. Below is a step-by-step guide to deploy Hippo 7, the cms.war artifact, on Jboss with Postgres 8.3.


1. Create a PostgresQL database
Before you can deploy the cms.war file a PostgresQL database must be created. Hippo demands a database encoding of Latin1. If your PostgresQL database server is installed with a different encoding, excluding C or POSIX, you may not be able to create a Latin1 encoded database. If this is the case you can do one of the following:
    1. Re-install the database server with a Latin1, C or POSIX locale. By using the C or POSIX locale you can create a database with any encoding you like, including Latin1.
    2. Create a database with an encoding the current database server supports, for example UTF-8, and change the encoding of the database with the following SQL statement: ALTER DATABASE dbX SET client_encoding TO latin1; Make sure you restart the database server.
2. Add the postgress JDBC-driver to the /server/default/lib


3. Create a datasource
Create a datasource in Jboss by creating a postgres-ds.xml in the /server/default/deploy directory with the following contents:

<?xml version="1.0" encoding="UTF-8"?>
<datasources>
    <local-tx-datasource>
        <jndi-name>jdbc/repositoryDS</jndi-name>
        <connection-url>jdbc:postgresql://localhost:5432/hippo</connection-url>
        <driver-class>org.postgresql.Driver</driver-class>
        <user-name>postgres</user-name>
        <password>postgres</password>-->
        <blocking-timeout-millis>5000</blocking-timeout-millis> 
          <idle-timeout-minutes>5</idle-timeout-minutes> 
     <prepared-statement-cache-size>50</prepared-statement-cache-size>
       </local-tx-datasource>
</datasources>

4. Add a resource-ref to the cms.war web.xml
Add the following resource-ref to the web.xml of the cms.war file:
 <resource-ref>
        <res-ref-name>jdbc/repositoryDS</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>

You can add this element just before the closing </web-app> element.

5. Add a jboss-web.xml file to root of the WEB-INF directory of the cms.war
The jboss-web.xml defines the mapping between the datasource and the resource-ref. This file should have the following contents:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<resource-ref>
  <res-ref-name>jdbc/repositoryDS</res-ref-name> 
  <jndi-name>java:/jdbc/repositoryDS</jndi-name> 
</resource-ref>
</jboss-web>

6. Modify the location of the repository.xml in the web.xml of the cms.war
We have to create a custom repository.xml file which configures Hippo for using PostgresQL. The location of the repository path should be modified so that it can find out repository.xml file. Change the location of the repository.xml file in de web.xml file to the following:
<servlet>
        <servlet-name>Repository</servlet-name>
        <servlet-class>org.hippoecm.repository.RepositoryServlet</servlet-class>
        <init-param>
            <param-name>repository-config</param-name>
            <param-value>repository.xml</param-value>
            <description>The location of the repository configuration file.
                Unless the location
                starts with file://, the location is retrieved from within the application
                package as
                resource.</description>
        </init-param>
        <load-on-startup>4</load-on-startup>
    </servlet>

7. Add the customized repository.xml file to the cms.war file
The following repository.xml file should be added to the the cms.war file in the directory: WEB-INF/classes/org/hippoecm/repository. The bundle-cache is enabled in the following repository.xml which greatly improves the performance of the Hippo cms system. The cache size is set to 256MB but can be altered when needed.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.5//EN"
      "http://jackrabbit.apache.org/dtd/repository-1.5.dtd">
<Repository>

    <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
        <param name="url" value="java:comp/env/jdbc/repositoryDS" />
        <param name="driver" value="javax.naming.InitialContext" />
        <param name="schemaObjectPrefix" value="repository_" />
        <param name="schema" value="postgresql" />
    </FileSystem>

    <Security appName="Jackrabbit">
        <SecurityManager class="org.hippoecm.repository.security.SecurityManager" />
        <AccessManager class="org.hippoecm.repository.security.HippoAccessManager" />
        <LoginModule class="org.hippoecm.repository.security.HippoLoginModule" />
    </Security>

    <Workspaces rootPath="${rep.home}/workspaces"
        defaultWorkspace="default" />
    <Workspace name="${wsp.name}">
        <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
            <param name="url" value="java:comp/env/jdbc/repositoryDS" />
            <param name="driver" value="javax.naming.InitialContext" />
            <param name="schemaObjectPrefix" value="${wsp.name}_" />
            <param name="schema" value="postgresql" />
        </FileSystem>

        <PersistenceManager
            class="org.apache.jackrabbit.core.persistence.bundle.PostgreSQLPersistenceManager">
            <param name="driver" value="javax.naming.InitialContext" />
            <param name="url" value="java:comp/env/jdbc/repositoryDS" />
            <param name="schemaObjectPrefix" value="${wsp.name}_" />
            <param name="externalBLOBs" value="true" />
            <param name="consistencyCheck" value="true" />
            <param name="consistencyFix" value="true" />
            <param name="bundleCacheSize" value="256"/>
        </PersistenceManager>

        <SearchIndex
            class="org.hippoecm.repository.FacetedNavigationEngineThirdImpl">
            <param name="indexingConfiguration" value="indexing_configuration.xml" />
            <param name="indexingConfigurationClass"
                value="org.hippoecm.repository.query.lucene.ServicingIndexingConfigurationImpl" />
            <param name="path" value="${wsp.home}/index" />
            <param name="useCompoundFile" value="true" />
            <param name="minMergeDocs" value="1000" />
            <param name="volatileIdleTime" value="10" />
            <param name="maxMergeDocs" value="1000000000" />
            <param name="mergeFactor" value="5" />
            <param name="maxFieldLength" value="10000" />
            <param name="bufferSize" value="1000" />
            <param name="cacheSize" value="1000" />
            <param name="forceConsistencyCheck" value="true" />
            <param name="enableConsistencyCheck" value="true" />
            <param name="autoRepair" value="true" />
            <param name="analyzer"
                value="org.apache.lucene.analysis.standard.StandardAnalyzer" />
            <param name="queryClass" value="org.apache.jackrabbit.core.query.QueryImpl" />
            <param name="respectDocumentOrder" value="false" />
            <param name="resultFetchSize" value="2147483647" />
            <param name="extractorPoolSize" value="0" />
            <param name="extractorTimeout" value="100" />
            <param name="extractorBackLogSize" value="100" />
            <param name="textFilterClasses"
                value="org.apache.jackrabbit.extractor.PlainTextExtractor,org.apache.jackrabbit.extractor.MsWordTextExtractor,org.apache.jackrabbit.extractor.MsExcelTextExtractor,org.apache.jackrabbit.extractor.MsPowerPointTextExtractor,org.apache.jackrabbit.extractor.PdfTextExtractor,org.apache.jackrabbit.extractor.OpenOfficeTextExtractor,org.apache.jackrabbit.extractor.RTFTextExtractor,org.apache.jackrabbit.extractor.HTMLTextExtractor,org.apache.jackrabbit.extractor.XMLTextExtractor" />
        </SearchIndex>
    </Workspace>

    <Versioning rootPath="${rep.home}/version">
        <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
            <param name="url" value="java:comp/env/jdbc/repositoryDS" />
            <param name="driver" value="javax.naming.InitialContext" />
            <param name="schemaObjectPrefix" value="version_" />
            <param name="schema" value="postgresql" />
        </FileSystem>

        <PersistenceManager
            class="org.apache.jackrabbit.core.persistence.bundle.PostgreSQLPersistenceManager">
            <param name="driver" value="javax.naming.InitialContext" />
            <param name="url" value="java:comp/env/jdbc/repositoryDS" />
            <param name="schemaObjectPrefix" value="version_" />
            <param name="externalBLOBs" value="true" />
            <param name="consistencyCheck" value="true" />
            <param name="consistencyFix" value="true" />
            <param name="bundleCacheSize" value="256"/>
        </PersistenceManager>
    </Versioning>

    <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
        <param name="path" value="${rep.home}/repository/index" />
        <param name="forceConsistencyCheck" value="true" />
        <param name="enableConsistencyCheck" value="true" />
    </SearchIndex>

    <DataStore class="org.apache.jackrabbit.core.data.db.DbDataStore">
        <param name="url" value="java:comp/env/jdbc/repositoryDS" />
        <param name="driver" value="javax.naming.InitialContext" />
        <param name="databaseType" value="postgresql" />
        <param name="minRecordLength" value="1024" />
        <param name="maxConnections" value="5" />
        <param name="copyWhenReading" value="true" />
    </DataStore>
</Repository>

8. Optionally: change the heap and permsize settings of JBoss.
I use the following memory settings for my configuration. Modify this in the run.bat startup script: set JAVA_OPTS=%JAVA_OPTS% -Xms256m -Xmx768m -XX:MaxPermSize=256m
    Thats it!

    6 comments:

    Jeroen Reijn said...

    Hi Jamie,

    thank you for this great post! I hope it can help others out while working the Hippo, JBoss and Postgres! I've added your blog entry to the Articles page on the Hippo wiki.

    Cheers,

    Jeroen

    Anonymous said...

    I'm trying to do the same, but every time I run the first time, I got an exception like "ERROR [org.hippoecm.repository.RepositoryServlet.init():179] Error while setting up JCR repository:
    javax.jcr.RepositoryException: Unable to update item: node /"

    with the root cause "Caused by: org.apache.jackrabbit.core.state.ItemStateException: failed to read bundle: 67fedacb-7790-45ae-b174-fc23f4033ec7: java.lang.IllegalArgumentException: Invalid namespace index: 3158064"

    No hints in the lists... Do you have any idea?

    Jamie Craane said...

    Mmm. Not sure about the exact cause but when I used a version greater than Postgres 8.3 I got similar exceptions. Are you using Postgres 8,3?

    Also, is your database Latin 1 encoded?

    Regards,
    Jamie

    Anonymous said...

    Yeah, 9.
    I solved the problem, wrong jdbc driver..

    http://hippo.2275632.n2.nabble.com/Postgres-9-and-JCr-Hippo-td6240670.html

    Anonymous said...

    great work, thank you for the post.
    Can you put your email adress or contact form that we can contact you.
    Thank you

    Ecommerce developer said...

    Thanks for the sharing of such information for it .simple and effective blogs.I read all comments.It will be great .Good and informative.