Working SPNEGO HTTP client
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / internal / runtime / CmsContextImpl.java
index 7a0f3388c07a4f79cabdd6928de9fa210e3bc511..cc98072a3827fd7a5836f700dab6a47fc7a0e2e1 100644 (file)
@@ -91,7 +91,16 @@ public class CmsContextImpl implements CmsContext {
 //
 //             }.open();
 
-               checkReadiness();
+               new Thread(() -> {
+                       while (!checkReadiness()) {
+                               try {
+                                       Thread.sleep(500);
+                               } catch (InterruptedException e) {
+                               }
+                       }
+               }, "Check readiness").start();
+               
+               // checkReadiness();
 
                setInstance(this);
        }
@@ -104,10 +113,13 @@ public class CmsContextImpl implements CmsContext {
         * Checks whether the deployment is available according to expectations, and
         * mark it as available.
         */
-       private void checkReadiness() {
+       private boolean checkReadiness() {
                if (isAvailable())
-                       return;
-               if (cmsDeployment != null && userAdmin != null) {
+                       return true;
+               if (cmsDeployment == null)
+                       return false;
+
+               if (((CmsDeploymentImpl) cmsDeployment).allExpectedServicesAvailable() && userAdmin != null) {
                        String data = KernelUtils.getFrameworkProp(KernelUtils.OSGI_INSTANCE_AREA);
                        String state = KernelUtils.getFrameworkProp(KernelUtils.OSGI_CONFIGURATION_AREA);
                        availableSince = System.currentTimeMillis();
@@ -124,8 +136,11 @@ public class CmsContextImpl implements CmsContext {
                        if (log.isTraceEnabled())
                                log.trace("Kernel initialization took " + initDuration + "ms");
                        tributeToFreeSoftware(initDuration);
+
+                       return true;
                } else {
-                       throw new IllegalStateException("Deployment is not available");
+                       return false;
+                       // throw new IllegalStateException("Deployment is not available");
                }
        }
 
@@ -238,15 +253,9 @@ public class CmsContextImpl implements CmsContext {
                return getInstance();
        }
 
-//     /** Required by USER login module. */
-//     public synchronized static UserAdmin getUserAdmin() {
-//             return getInstance().userAdmin;
-//     }
-
        /** Required by SPNEGO login module. */
-       @Deprecated
        public synchronized static GSSCredential getAcceptorCredentials() {
-               // FIXME find a cleaner way
+               // TODO find a cleaner way
                return ((CmsUserAdmin) getInstance().userAdmin).getAcceptorCredentials();
        }