WebRequestCreate() public method

Creates a web request with preemptive authentication.
public WebRequestCreate ( string url ) : WebRequest
url string URL
return System.Net.WebRequest
        private bool IsDavExEnabled()
        {
            string    davExUrl = instance.UrlWithContextPath + "/crx/server/crx.default/jcr:root/.1.json";
            Stopwatch responseTimeStopwatch = new Stopwatch();

            try {
                mLog.Debug("Get bundle list from URL: " + davExUrl);

                HttpWebRequest request = instance.WebRequestCreate(davExUrl);
                request.Method = "GET";

                responseTimeStopwatch.Start();
                using (WebResponse response = request.GetResponse()) {
                    responseTimeStopwatch.Stop();
                    return(true);
                }
            }
            catch (WebException ex) {
                if (ex.Status == WebExceptionStatus.Timeout)
                {
                    mLog.Debug("Unable to connect to " + davExUrl + " due to timeout. "
                               + "Configured timeout: " + AEMManager.Properties.Settings.Default.BundleListTimeout + "ms, "
                               + "measured response time: " + responseTimeStopwatch.ElapsedMilliseconds + "ms");
                }
                else
                {
                    mLog.Debug("Unable to connect to " + davExUrl + ": " + ex.Message);
                }
            }
            catch (Exception ex) {
                mLog.Error("Error getting DavEx status from URL: " + davExUrl, ex);
            }
            return(false);
        }
Example #2
0
        public static void StopInstance(AemInstance pInstance)
        {
            string shutdownUrl = pInstance.UrlWithContextPath + "/system/console/vmstat?shutdown_type=Stop";

            if (pInstance.AemInstanceType == AemInstanceType.AEM54)
            {
                shutdownUrl = pInstance.UrlWithoutContextPath + "/admin/shutdown";
            }

            try {
                mLog.Debug("Execute shutdown URL: " + shutdownUrl);

                pInstance.ConsoleOutputWindow.AppendConsoleLog("Shutting down instance...");

                HttpWebRequest request = pInstance.WebRequestCreate(shutdownUrl);
                request.Method = "POST";

                request.GetResponse();
            }
            catch (WebException ex) {
                mLog.Debug("Unable to connect to " + shutdownUrl + ": " + ex.Message);
            }
            catch (Exception ex) {
                mLog.Error("Error executing shutdown URL: " + shutdownUrl, ex);
            }
        }
Example #3
0
        public static BundleStatus GetCombinedBundleStatus(AemInstance pInstance)
        {
            if (pInstance == null)
            {
                return(BundleStatus.NO_ACTIVE_INSTANCE);
            }

            // check if process is running
            if (!pInstance.RemoteProcess)
            {
                Process process = pInstance.GetInstanceJavaProcess();
                if (process == null || process.HasExited)
                {
                    return(BundleStatus.DISABLED);
                }
            }

            // get bundle status
            BundleStatus bundleStatus          = BundleStatus.UNKNOWN;
            string       bundleListUrl         = pInstance.UrlWithContextPath + "/system/console/bundles/.json";
            Stopwatch    responseTimeStopwatch = new Stopwatch();

            try {
                mLog.Debug("Get bundle list from URL: " + bundleListUrl);

                HttpWebRequest request = pInstance.WebRequestCreate(bundleListUrl);
                request.Method           = "GET";
                request.Timeout          = AEMManager.Properties.Settings.Default.BundleListTimeout;
                request.ReadWriteTimeout = AEMManager.Properties.Settings.Default.BundleListTimeout;

                responseTimeStopwatch.Start();
                using (WebResponse response = request.GetResponse()) {
                    responseTimeStopwatch.Stop();

                    String responseText;
                    using (StreamReader streamReader = new StreamReader(response.GetResponseStream())) {
                        responseText = streamReader.ReadToEnd();
                    }

                    // parse JSON
                    bool   success = false;
                    object value   = JSON.JsonDecode(responseText, ref success);
                    if (success)
                    {
                        bundleStatus = GetCombinedBundleStatus(value, responseTimeStopwatch.ElapsedMilliseconds);
                    }
                    else
                    {
                        mLog.Warn("Parsing JSON response failed: " + responseText);
                    }
                }
            }
            catch (WebException ex) {
                if (ex.Status == WebExceptionStatus.Timeout)
                {
                    mLog.Debug("Unable to connect to " + bundleListUrl + " due to timeout. "
                               + "Configured timeout: " + AEMManager.Properties.Settings.Default.BundleListTimeout + "ms, "
                               + "measured response time: " + responseTimeStopwatch.ElapsedMilliseconds + "ms");
                }
                else
                {
                    mLog.Debug("Unable to connect to " + bundleListUrl + ": " + ex.Message);
                    bundleStatus = BundleStatus.UNKNOWN;
                }
            }
            catch (Exception ex) {
                mLog.Error("Error getting bundle list from URL: " + bundleListUrl, ex);
                bundleStatus = BundleStatus.UNKNOWN;
            }

            return(bundleStatus);
        }
Example #4
0
        public static void StopInstance(AemInstance pInstance)
        {
            string shutdownUrl = pInstance.UrlWithContextPath + "/system/console/vmstat?shutdown_type=Stop";
              if (pInstance.AemInstanceType == AemInstanceType.AEM54) {
            shutdownUrl = pInstance.UrlWithoutContextPath + "/admin/shutdown";
              }

              try {
            mLog.Debug("Execute shutdown URL: " + shutdownUrl);

            pInstance.ConsoleOutputWindow.AppendConsoleLog("Shutting down instance...");

            WebRequest request = pInstance.WebRequestCreate(shutdownUrl);
            request.Method = "POST";
            request.Timeout = 3000;

            request.GetResponse();
              }
              catch (WebException ex) {
            mLog.Debug("Unable to connect to " + shutdownUrl + ": " + ex.Message);
              }
              catch (Exception ex) {
            mLog.Error("Error executing shutdown URL: " + shutdownUrl, ex);
              }
        }
Example #5
0
        public static BundleStatus GetCombinedBundleStatus(AemInstance pInstance)
        {
            if (pInstance == null) {
            return BundleStatus.NO_ACTIVE_INSTANCE;
              }

              // check if process is running
              if (!pInstance.RemoteProcess) {
            Process process = pInstance.GetInstanceJavaProcess();
            if (process == null || process.HasExited) {
              return BundleStatus.DISABLED;
            }
              }

              // get bundle status
              BundleStatus bundleStatus = BundleStatus.UNKNOWN;
              string bundleListUrl = pInstance.UrlWithContextPath + "/system/console/bundles/.json";
              Stopwatch responseTimeStopwatch = new Stopwatch();
              try {
            mLog.Debug("Get bundle list from URL: " + bundleListUrl);

            WebRequest request = pInstance.WebRequestCreate(bundleListUrl);
            request.Method = "GET";
            request.Timeout = AEMManager.Properties.Settings.Default.BundleListTimeout;

            responseTimeStopwatch.Start();
            using (WebResponse response = request.GetResponse()) {
              responseTimeStopwatch.Stop();

              String responseText;
              using (StreamReader streamReader = new StreamReader(response.GetResponseStream())) {
            responseText = streamReader.ReadToEnd();
              }

              // parse JSON
              bool success = false;
              object value = JSON.JsonDecode(responseText, ref success);
              if (success) {
            bundleStatus = GetCombinedBundleStatus(value, responseTimeStopwatch.ElapsedMilliseconds);
              }
              else {
            mLog.Warn("Parsing JSON response failed: " + responseText);
              }
            }

              }
              catch (WebException ex) {
            if (ex.Status == WebExceptionStatus.Timeout) {
              mLog.Debug("Unable to connect to " + bundleListUrl + " due to timeout. "
            + "Configured timeout: " + AEMManager.Properties.Settings.Default.BundleListTimeout + "ms, "
            + "measured response time: " + responseTimeStopwatch.ElapsedMilliseconds + "ms");
            }
            else {
              mLog.Debug("Unable to connect to " + bundleListUrl + ": " + ex.Message);
              bundleStatus = BundleStatus.UNKNOWN;
            }
              }
              catch (Exception ex) {
            mLog.Error("Error getting bundle list from URL: " + bundleListUrl, ex);
            bundleStatus = BundleStatus.UNKNOWN;
              }

              return bundleStatus;
        }