Author: sohil.shah(a)jboss.com
Date: 2009-04-08 01:31:56 -0400 (Wed, 08 Apr 2009)
New Revision: 13178
Modified:
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/CMSException.java
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/jcr/JCRCMS.java
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/jcr/ha/HAJCRCMS.java
Log:
JBPORTAL-2354 - HA-CMS: NullPointerException after fail-over
Modified:
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/CMSException.java
===================================================================
---
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/CMSException.java 2009-04-08
05:13:26 UTC (rev 13177)
+++
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/CMSException.java 2009-04-08
05:31:56 UTC (rev 13178)
@@ -32,6 +32,7 @@
private static final long serialVersionUID = 3646107693814633408L;
public static final int INVALID_ARCHIVE = 1;
+ public static final int SERVICE_UNAVAILABLE=2;
private int errorCode = 0;
@@ -71,6 +72,11 @@
return pathFormatFailure;
}
+ public boolean isServiceUnavailable()
+ {
+ return (this.errorCode == SERVICE_UNAVAILABLE);
+ }
+
public String getMessageKey()
{
String key = "";
@@ -81,6 +87,10 @@
key = "INVALID_ARCHIVE_MESSAGE";
break;
+ case SERVICE_UNAVAILABLE:
+ key = "SERVICE_UNAVAILABLE";
+ break;
+
default:
key = "";
break;
Modified:
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/jcr/JCRCMS.java
===================================================================
---
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/jcr/JCRCMS.java 2009-04-08
05:13:26 UTC (rev 13177)
+++
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/jcr/JCRCMS.java 2009-04-08
05:31:56 UTC (rev 13178)
@@ -59,12 +59,9 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-import org.hibernate.Transaction;
-
import javax.transaction.Status;
import javax.transaction.UserTransaction;
import javax.transaction.TransactionManager;
-import javax.naming.InitialContext;
import javax.jcr.Repository;
import javax.jcr.Session;
@@ -112,6 +109,8 @@
private JNDI.Binding jndiBinding;
private String cmsSessionFactory;
+
+ private boolean isServiceAvailable;
private InvocationHandler handler = new InvocationHandler()
{
@@ -362,6 +361,8 @@
{
tm.commit();
}
+
+ this.isServiceAvailable = true;
}
catch(Exception e)
{
@@ -375,7 +376,9 @@
}
public void stopService()
- {
+ {
+ this.isServiceAvailable = false;
+
TransactionManager tm = null;
boolean isStartedHere = false;
try
@@ -418,8 +421,38 @@
}
public Object execute(Command cmd) throws CMSException
+ {
+ if(!this.isServiceAvailable)
+ {
+ throw new CMSException(CMSException.SERVICE_UNAVAILABLE);
+ }
+
+ return this.executeCommand(cmd);
+ }
+
+ /**
+ * Checks for existence of default CMS content.
+ *
+ * @return
+ * @throws Exception
+ */
+ public boolean contentExists() throws Exception
{
- org.apache.jackrabbit.core.XASession session = null;
+ Session session = null;
+ try
+ {
+ session = jcr.login("anonid", "");
+ return session.itemExists("/default");
+ }
+ finally
+ {
+ RepositoryUtil.safeLogout(session);
+ }
+ }
+
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ private Object executeCommand(Command cmd) throws CMSException
+ {
+ org.apache.jackrabbit.core.XASession session = null;
Object obj = null;
boolean isClusterDelegatedRequest = false; //used to indicate this request is from
another cluster node instead of the master node
boolean clusterWorkflowStatus = false;
@@ -571,7 +604,7 @@
}
return obj;
}
-
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+
private void startJCR() throws Exception
{
// Serialize the embedded configuration
@@ -612,26 +645,6 @@
}
/**
- * Checks for existence of default CMS content.
- *
- * @return
- * @throws Exception
- */
- public boolean contentExists() throws Exception
- {
- Session session = null;
- try
- {
- session = jcr.login("anonid", "");
- return session.itemExists("/default");
- }
- finally
- {
- RepositoryUtil.safeLogout(session);
- }
- }
-
- /**
* Initilizes the repository with initial/boot content
*
* @throws Exception
@@ -688,7 +701,7 @@
Command saveCMD = getCommandFactory().createFolderSaveCommand(folder);
try
{
- execute(saveCMD);
+ executeCommand(saveCMD);
}
catch (CMSException e)
{
@@ -757,7 +770,7 @@
Command newFileCMD = getCommandFactory().createNewFileCommand(file,
content);
JCRCMS.turnOffWorkflow();
- execute(newFileCMD);
+ executeCommand(newFileCMD);
}
catch (Exception e)
Modified:
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/jcr/ha/HAJCRCMS.java
===================================================================
---
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/jcr/ha/HAJCRCMS.java 2009-04-08
05:13:26 UTC (rev 13177)
+++
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/jcr/ha/HAJCRCMS.java 2009-04-08
05:31:56 UTC (rev 13178)
@@ -109,7 +109,9 @@
{
CMSException cmsException = (CMSException)returnValue;
if(cmsException.toString().indexOf("Access to this resource is
denied") != -1 ||
- cmsException.hasPathFormatFailure())
+ cmsException.hasPathFormatFailure() ||
+ cmsException.isServiceUnavailable()
+ )
{
throw cmsException;
}