Browse Source

applicationPath cli handler updates

jrivard 10 years ago
parent
commit
36208ca1bf

+ 44 - 31
pwm/servlet/src/password/pwm/PwmApplication.java

@@ -151,6 +151,8 @@ public class PwmApplication {
     private PwmApplication(final PwmEnvironment pwmEnvironment)
     private PwmApplication(final PwmEnvironment pwmEnvironment)
             throws PwmUnrecoverableException
             throws PwmUnrecoverableException
     {
     {
+        verifyIfApplicationPathIsSetProperly(pwmEnvironment);
+
         this.pwmEnvironment = pwmEnvironment;
         this.pwmEnvironment = pwmEnvironment;
         this.configuration = pwmEnvironment.config;
         this.configuration = pwmEnvironment.config;
         this.applicationMode = pwmEnvironment.applicationMode;
         this.applicationMode = pwmEnvironment.applicationMode;
@@ -171,8 +173,6 @@ public class PwmApplication {
     {
     {
         final Date startTime = new Date();
         final Date startTime = new Date();
 
 
-        verifyIfApplicationPathIsSetProperly(pwmEnvironment);
-
         // initialize log4j
         // initialize log4j
         if (initLogging) {
         if (initLogging) {
             final String log4jFileName = configuration.readSettingAsString(PwmSetting.EVENTS_JAVA_LOG4JCONFIG_FILE);
             final String log4jFileName = configuration.readSettingAsString(PwmSetting.EVENTS_JAVA_LOG4JCONFIG_FILE);
@@ -674,57 +674,70 @@ public class PwmApplication {
         return webInfPath;
         return webInfPath;
     }
     }
 
 
-    private static void verifyIfApplicationPathIsSetProperly(final PwmEnvironment pwmEnvironment)
+    private void verifyIfApplicationPathIsSetProperly(final PwmEnvironment pwmEnvironment)
             throws PwmUnrecoverableException
             throws PwmUnrecoverableException
     {
     {
-        final File webInfPath = pwmEnvironment.webInfPath;
         final File applicationPath = pwmEnvironment.applicationPath;
         final File applicationPath = pwmEnvironment.applicationPath;
+        File webInfPath = pwmEnvironment.webInfPath;
 
 
         if (applicationPath == null) {
         if (applicationPath == null) {
             throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_STARTUP_ERROR, "unable to determine valid applicationPath"));
             throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_STARTUP_ERROR, "unable to determine valid applicationPath"));
         }
         }
+        LOGGER.trace("examining applicationPath of " + applicationPath.getAbsolutePath() + "");
 
 
         if (!applicationPath.exists()) {
         if (!applicationPath.exists()) {
-            throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_STARTUP_ERROR, "applicationPath \"" + applicationPath.getAbsolutePath() + "\" does not exist"));
+            throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_STARTUP_ERROR, "applicationPath " + applicationPath.getAbsolutePath() + " does not exist"));
         }
         }
 
 
         if (!applicationPath.canRead()) {
         if (!applicationPath.canRead()) {
-            throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_STARTUP_ERROR, "unable to read from applicationPath \"" + applicationPath.getAbsolutePath() + "\""));
+            throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_STARTUP_ERROR, "unable to read from applicationPath " + applicationPath.getAbsolutePath() + ""));
         }
         }
 
 
         if (!applicationPath.canWrite()) {
         if (!applicationPath.canWrite()) {
-            throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_STARTUP_ERROR, "unable to write to applicationPath \"" + applicationPath.getAbsolutePath() + "\""));
-        }
-
-        if (webInfPath == null) {
-            return;
+            throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_STARTUP_ERROR, "unable to write to applicationPath " + applicationPath.getAbsolutePath() + ""));
         }
         }
 
 
-        final File infoFile = new File(webInfPath.getAbsolutePath() + File.separator + PwmConstants.APPLICATION_PATH_INFO_FILE);
-        if (pwmEnvironment.applicationPathType == PwmEnvironment.ApplicationPathType.derived) {
-            LOGGER.trace("checking " + infoFile.getAbsolutePath() + " status, (applicationPath=" + PwmEnvironment.ApplicationPathType.derived);
-            if (infoFile.exists()) {
-                final String errorMsg = "The file \"" + infoFile.getAbsolutePath() + "\" exists, but applicationPath was not explicitly specified."
-                        + "  This file must be removed, or an explicit applicationPath parameter must be specified.";
-                throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_STARTUP_ERROR,errorMsg));
-            } else {
-                LOGGER.trace(infoFile.getAbsolutePath() + " does not exist");
+        boolean applicationPathIsWebInfPath = false;
+        if (applicationPath.equals(webInfPath)) {
+            applicationPathIsWebInfPath = true;
+        } else if (applicationPath.getAbsolutePath().endsWith("/WEB-INF")) {
+            final File webXmlFile = new File(applicationPath.getAbsolutePath() + File.separator + "web.xml");
+            if (webXmlFile.exists()) {
+                applicationPathIsWebInfPath = true;
             }
             }
         }
         }
+        if (applicationPathIsWebInfPath) {
+            if (webInfPath == null) {
+                webInfPath = applicationPath;
+                pwmEnvironment.webInfPath = applicationPath;
+            }
 
 
-        if (webInfPath.equals(applicationPath)) {
-            LOGGER.trace("webInfPath and applicationPath are same");
-            return;
+            LOGGER.trace("applicationPath appears to be servlet /WEB-INF directory");
         }
         }
 
 
-        if (pwmEnvironment.applicationPathType == PwmEnvironment.ApplicationPathType.specified) {
-            try {
-                final FileOutputStream fos = new FileOutputStream(infoFile);
-                final Properties outputProperties = new Properties();
-                outputProperties.setProperty("lastApplicationPath", applicationPath.getAbsolutePath());
-                outputProperties.store(fos, "Marker file to record a previously specified applicationPath");
-            } catch (IOException e) {
-                LOGGER.warn("unable to write marker properties file in WEB-INF directory");
+        final File infoFile = new File(webInfPath.getAbsolutePath() + File.separator + PwmConstants.APPLICATION_PATH_INFO_FILE);
+        if (applicationPathIsWebInfPath) {
+            if (pwmEnvironment.applicationPathType == PwmEnvironment.ApplicationPathType.derived) {
+                LOGGER.trace("checking " + infoFile.getAbsolutePath() + " status, (applicationPathType=" + PwmEnvironment.ApplicationPathType.derived + ")");
+                if (infoFile.exists()) {
+                    final String errorMsg = "The file " + infoFile.getAbsolutePath() + " exists, and an applicationPath was not explicitly specified."
+                            + "  This happens when an applicationPath was previously configured, but is not now being specified."
+                            + "  An explicit applicationPath parameter must be specified, or the file can be removed if the applicationPath should be changed to the default /WEB-INF directory.";
+                    throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_STARTUP_ERROR, errorMsg));
+                } else {
+                    LOGGER.trace("marker file " + infoFile.getAbsolutePath() + " does not exist");
+                }
+            }
+        } else {
+            if (pwmEnvironment.applicationPathType == PwmEnvironment.ApplicationPathType.specified) {
+                try {
+                    final FileOutputStream fos = new FileOutputStream(infoFile);
+                    final Properties outputProperties = new Properties();
+                    outputProperties.setProperty("lastApplicationPath", applicationPath.getAbsolutePath());
+                    outputProperties.store(fos, "Marker file to record a previously specified applicationPath");
+                } catch (IOException e) {
+                    LOGGER.warn("unable to write applicationPath marker properties file " + infoFile.getAbsolutePath() + "");
+                }
             }
             }
         }
         }
     }
     }

+ 1 - 1
pwm/servlet/src/password/pwm/http/ContextManager.java

@@ -257,6 +257,7 @@ public class ContextManager implements Serializable {
         } else {
         } else {
             errorMsg = throwable.getMessage();
             errorMsg = throwable.getMessage();
             startupErrorInformation = new ErrorInformation(PwmError.ERROR_APP_UNAVAILABLE, msgPrefix + errorMsg);
             startupErrorInformation = new ErrorInformation(PwmError.ERROR_APP_UNAVAILABLE, msgPrefix + errorMsg);
+            throwable.printStackTrace();
         }
         }
 
 
         try {
         try {
@@ -266,7 +267,6 @@ public class ContextManager implements Serializable {
         }
         }
 
 
         outputError(startupErrorInformation.getDetailedErrorMsg());
         outputError(startupErrorInformation.getDetailedErrorMsg());
-        throwable.printStackTrace();
     }
     }
 
 
     public void shutdown() {
     public void shutdown() {

+ 2 - 2
pwm/servlet/src/password/pwm/i18n/Error.properties

@@ -114,8 +114,8 @@ Error_Activation=Unable to activate your account using the information you have
 Error_DB_Unavailable=Database Unavailable.  If this error occurs repeatedly please contact your help desk.
 Error_DB_Unavailable=Database Unavailable.  If this error occurs repeatedly please contact your help desk.
 Error_LocalDB_Unavailable=LocalDB Unavailable.  Please contact your administrator.
 Error_LocalDB_Unavailable=LocalDB Unavailable.  Please contact your administrator.
 Error_App_Unavailable=The application is unavailable or is restarting.  If this error occurs repeatedly please contact your help desk.
 Error_App_Unavailable=The application is unavailable or is restarting.  If this error occurs repeatedly please contact your help desk.
-Error_IncorrectRequestSequence=An out of order page request has been received.  Please try again.
-Error_UnreachableCloudService=Cloud Service was unreachable.
+Error_IncorrectRequestSequence=An out of order page request has been received.  Please do not use the browser back button.  Please try again.
+Error_UnreachableCloudService=A remote service was unreachable.
 Error_InvalidSecurityKey=Security Key is missing or invalid.
 Error_InvalidSecurityKey=Security Key is missing or invalid.
 Error_Clearing_Responses=An error occurred during the clearing of the response questions.  Please contact your administrator.
 Error_Clearing_Responses=An error occurred during the clearing of the response questions.  Please contact your administrator.
 Error_ServiceUnreachable=A required service is unavailable.  Please try again later.
 Error_ServiceUnreachable=A required service is unavailable.  Please try again later.

+ 1 - 0
pwm/servlet/src/password/pwm/util/cli/MainClass.java

@@ -237,6 +237,7 @@ public class MainClass {
                     } catch (CliException e) {
                     } catch (CliException e) {
                         System.out.println(e.getMessage());
                         System.out.println(e.getMessage());
                         System.exit(-1);
                         System.exit(-1);
+                        return;
                     }
                     }
 
 
                     System.exit(0);
                     System.exit(0);