Solved

Redirect to a different page when the web server or app server is down

Posted on 2004-08-14
23
323 Views
Last Modified: 2012-05-05
Hi,

    Here is my requirement.

    a) user tries opening the signin.html that will be used to log in to the application
    b) if the webserver or app server is down at this time, instead of showing the signin.html,
        user should be taken to a maintenance.html ( Maintenance.html page will have more descriptive
        text for the user to read)
    c) Send email to the application DBA when (b) is true saying that the web/app server is/are down.

   How do I achieve this using javascript?

Thanks,
Kris
0
Comment
Question by:krissav71
  • 10
  • 9
  • 4
23 Comments
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
What is the acttion on the page to invoke step a) ?
Do you ask that the step b) is executed event when url for signin.html is entered in browsers address bar? Then it can not be executed. You need a page which will contain the script which can react to server down condition.

So when you have a page where the link for signin.html is contained, then would the server down check look like this: you have a script to check a presence of a image on the server where signin.html is located. If the image does not load then you can start your administrator mail and the redirect action.

0
 

Author Comment

by:krissav71
Comment Utility
Hi Zvonko,

Thanks for your response.

Step (a) is a page on the webserver that is used for signing in.
Users usually bookmark this page or type it.

Ideally I would want to redirect after the url for signin.html is entered.
Eg: I enter www.abc.com and if the server is down, I should be redirected to another page. Is this not possible.

I am new to JavaScript. I would request you to give me/refer to some code samples that can help me.

Thanks,
Kris
0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
No way.
The url alone cannot do anything.
When server is down and no page is loaded can the bookmark alone not react to anything.
0
 
LVL 5

Expert Comment

by:vilia
Comment Utility
If you change little bit requirements of the step "a", you could achieve what you are looking for.

Instead of going directly to singin.html, users shoud go to a "main.html".
The "main.html" redirects to the "signin.html" if available. If not javascript
makes automatical redirection to the "maintenance.html".

If this is acceptable solution, please let me know.
0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
Where should the main.html be loaded from? From the same server as signin.html?
0
 
LVL 5

Expert Comment

by:vilia
Comment Utility
> Where should the main.html be loaded from? From the same server as signin.html?

From different server (could be on the same hardware), or even a local drive if application is for custom users (b2b).

Different server: needs to be available 7/24, for example a dummy HTTP server.
signin.html: is on an application server (goes up and down)
0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
That's all I wanted to hear ;)
0
 

Author Comment

by:krissav71
Comment Utility
Hi Vilia,

The solution you are proposing is acceptable to me ( redirecting from main.html residing on a different server than the signin.html).

I think this will take care of redirecting when the webserver is down.

 I also want to find out if the app server is down and redirect the user to the custom error page.

The signin.html is on the web server. Once the user enters the UserId/Passwd and hits submit button, the app server is accessed. At this time, if the app server is down, the user should be redirected to a custom error page. This custom error page can reside on the webserver where the signin.html resides.

Incidently, if the app server is down, I get an error message "Application server is down" just below the submit button on the signin.html page. Here is a code snippet. The <%=error%> actually displays the error message. Can this value be used to check if the app server is down and then redirect to the custom error page?

<form action="<%=servletLoc%>?cmd=login&languageCd=<%=languageCd%>&sessionId=<%=sessionId%>" method="post" id="login" name="login" autocomplete="off" onSubmit="signin(document.login)">

      <h2>Welcome, Kris </h2>
      <h3>Employee Self Service</h3>
      <div class="signIn">User ID: <input type="text" id="userid" name="userid" class="signInInput"></div>
      <div class="signIn">Password: <input TYPE="password" id="pwd" name="pwd" class="signInInput"></div>
      <div class="signIn"><input type="submit" name="Submit" value="Sign In" class="signInSubmit"></div>
      <div id="error"><%=error%></div>

</form>

In either case (webserver/app server down), I want to trigger a mail automatically to the Adminstrator with appropriate message.Thank you all for your responses.

Thanks,
Kris
0
 
LVL 5

Expert Comment

by:vilia
Comment Utility
Lets separate two issues: Redirection and Mail


A.) Redirection

main.html starts a hidden popup window which has a timeout function. When specified timeout expires, the function checks connection to signin.html (in the parent window).

How to check connection in the parent window? – The most simple way is to use cookies, but where is a cross-domain security issue. One possibility is to check the parent’s Url. To do this kind of check we need following structure:
www.domain1.com/main.html
(starts popup and redirects to signinDummy.html)
www.domain2.com/signinDummy.html
      (refresh/redirect to signin.html only)
www.domain2.com/signin.html
      (no change)
popup timeout function
      (check parent url window to have
      any www.domain2.com  url, but not
      www.domain2.com/signinDummy.html
      if no error closes popup window
      else unhide itself, show error and send mail)


B.) Mail

Mail could be sent from the client computer or from a www.domain1.com cgi script. Sending from browser involves user’s interaction (confirmation).
It is better to send email from a CGI (www.domain1.com/cgi/sendEmail) without user interaction from popup timeout function.


Hoppe it helps, if there is anything unclear please let me know.
0
 

Author Comment

by:krissav71
Comment Utility
Hi Vilia,

    Thank you for responding.

    JavaScript is not my area of specialization. So please bear with me when I am asking you some basic questions.
    This requirement is urgent and I do not have much time to study/explore/learn. Hence, I am picking the brains of experts
    like you.

    My questions:

    a) Can you help me in understanding why signindummy.html is required? Both signindummy.html and signin.html reside on
        the same server. Can the popup timeout function not check for the domain of signin.html instead?

    b) Incase there is an error, can the popup timeout function redirect to another page residing on www.domain1.com ?

    c) You are right, I don't want a user interaction in order to send mail. This has to happen automatically. Is there a
       sendemail function readily available in CGI?

    d) Your solution above would help me in checking if the webserver is up/down. I will still need to check if the app server
        is up/down.

       In the code snippet above(8/16/2004), can <%=error%> be checked for a particular value and implement redirection?
       <%=error%> displays 'Application server down' on signin.html page. Instead, i would want to check if the text displayed
        by <%=error%> == 'Application server down' and then redirect to another page on www.domain1.com

       How easy or difficult this is?

       If you have some code samples for your proposed solution and willing to share that will be really helpful.


Thanks Vilia. Your help is appreciated. Now I have an approach to get started.


Thanks,
Kris  
0
 
LVL 5

Expert Comment

by:vilia
Comment Utility
Yes, I can help you. So let’s go by your questions:

08/17/2004 09:39AM PDT - A ----------------------------

www.domain1.com/main.html
      - starts popUpTO
      - redirects itself to signinDummy.html
It does not go directly to siginn.html as it will be impossible for popUpTO to detect the app-server is running.
The scenario is:
Appserver is running:
      S1- browser starts popUpTO
      S2- browser redirects itself to signinDummy.html
      S3- suginDummy.html redirects to sigin.html
      S4- the user does something or nothing
      S5 - popUpTO expires and checks parent’s url
            that is www.domain2.com/sigin.html
            or anything like
            www.domain2.com/…..
            but not
            www.domain2.com/siginDummy.html
      S6- As S5 has been satisfied kills itself
Appserver is NOT running:
      S1 - the same
      S2 - the same
      S3 - browser stays on
             www.domain2.com/siginDummy.html
             or goes to
             an search page
      S4 - the same
      S5 - popUpTO expires and checks parent’s url
              That is anything but not
              www.domain2.com/…..
              except (www.domain2.com/siginDummy.html)
      S6 - as S5 fails, the popUpTO triggers a sendMail proc
              displays an error message to the user, and ….
NOTE:
N1: The popUpTimeout needs to be minimal or the user in S4 can redirect the browser to an unknown Url, causing S5 to fail, even the appserver is running.
N2: Better solution is to use cookies as a “check element”, but:
- if domain1 is different than domain2 it is the security breach
- if an user disables cookies logic is going to fail

08/17/2004 09:39AM PDT - B ----------------------------

popUpTO Redirection can be to any Url

08/17/2004 09:39AM PDT - C ----------------------------

Yes there are examples on the Web. Let me know the OS where main.html is located, as well the Web Server (main.html).

08/17/2004 09:39AM PDT - D ----------------------------

This is little bit confusing.
If Appserver is not running it can not execute sigin.html so it is going to return nothing.
If Appserver is running, but DB Server is not running, the signin.html is going to return whatever <%=error%>  is.

----------------------------

And Finally you should make clear, what is meaning of: “the Application Server is down”.
Let’s say you run IIS as AppServer and MS SQL Server as DB Server.
Does “the Application Server is down” mean:
- IIS is Down, MSSQL status does not metter
- IIS is Up. MSSQL Server is Down
- Something else

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:krissav71
Comment Utility
Hi Vilia,

Thank you for the explanation. It helped me in clarifying my understanding.

My signin.html resides on the webserver(weblogic) running on Windows NT.

The Application server(Tuxedo) is also on windows NT.

"Application server down" means IIS is down and MSSQL status does not matter.

Let me know if you need any other details.

Thanks once again Vilia.

-Kris
0
 
LVL 5

Expert Comment

by:vilia
Comment Utility
One question before we go further:
The Weblogic server does not go down, Tuxedo is only one that goes up and down?

If this is true the task is much simpler.
0
 

Author Comment

by:krissav71
Comment Utility
Hi Vilia,

In my experience, I have found that the weblogic server goes down very rarely. And usually it is scheduled

App server has a higher probability of going down.

In the configuration file setting is such that, on any error, the page to be displayed is mentioned as signin.html
We would want to keep this setting as it is for all errors except when the server is down.

So even if you can help me in finding a solution for a situation when the app server is down and then sending a mail, that
would be really helpful.

Let me know if you have any questions that can help you in designing the solution.

Thanks a ton.

Kris
0
 
LVL 5

Expert Comment

by:vilia
Comment Utility
If the weblogic server is stable as you stated, I assume you do not need to check the one.

You need to check the Tuxedo Server availability only. You can do it by adding following logic to the beginning of your sigin.html

Can you publish
function signin(…) {
}

Maybe you have a portion of the solution already.
0
 

Author Comment

by:krissav71
Comment Utility
Hi Vilia,

Here is the code snippet that you may be refering to. This is part of the signin.html.

<meta http-equiv=refresh content=<%=sessionTimeout%>>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
<script language="JavaScript" type="text/javascript">
    function signin(form)
      {
      var now=new Date();
      form.timezoneOffset.value=now.getTimezoneOffset();
      return ;
      }
</script>


let me know if you need any other detail.

Thanks,
Kris
0
 
LVL 5

Accepted Solution

by:
vilia earned 500 total points
Comment Utility
Here is an example that checks url avialibility, sendMail needs to be added, I will try to do the one during weekend.

=== beforeSignin.jsp start =============
<!--
Check the "servletLoc" availability
by Vilia
(c) 2004
-->
<%@ page session="false" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
      <style type="text/css"> <!--
      BODY {
            background-color: #ffffff;
      }
      #hdr1 {
            font-family: Arial;
            font-size: 24px;
      }
      #table1 {
            border-style: solid;
            border-width: 1px 0px 0px 1px;
            border-color: #000000;
            margin: 0px;
            padding: 0;
      }
      #th1 {
            border-style: solid;
            border-width: 0px 1px 1px 0px;
            border-color: #000000;
            background-color: #dcdcdc;
            margin: 0px;
            padding: 2px;
            font-family: Arial;
            font-size: 12px;
            font-weight:bold;
      }
      #td1 {
            border-style: solid;
            border-width: 0px 1px 1px 0px;
            border-color: #000000;
            background-color: #f0f8f8;
            margin: 0px;
            padding: 2px;
            font-family: Arial;
            font-size: 12px;
      }
      #td1err {
            border-style: solid;
            border-width: 0px 1px 1px 0px;
            border-color: #000000;
            background-color: #f0f8f8;
            margin: 0px;
            padding: 2px;
            font-family: Arial;
            font-size: 12px;
            color: #ff0000;
      }
      --></style>
</head>
<jsp:useBean id="testUrl" scope="page" class="testremoteurl.Signin" />
      <body>
      <div id="hdr1">Show Testing Capabilities</div>
      <br>
      <%
      String[] testUrlList = {
            "http://www.ZZZyahoo.com", // unknown host
            "http://www.yahoo.com",  // ok
            "http://12.12.12.1",  // timeout
            "http://www.yahoo.com/noPageUrl"  // noPageUrl (HTTP response Err)
      };
      String[] testExplanation = {
            "Unknown Host",
            "Valid host",
            "Connection Timeout",
            "HTTP response Error (unknown page)"
      };
      %>
      <jsp:setProperty name="testUrl" property="timeout" value="3000" />
      <div>
      <table id="table1" cellspacing="0">
            <tr>
                  <td id="th1">Test Type</td>
                  <td id="th1">URL</td>
                  <td id="th1">Result</td>
            </tr>
            
      <%
      for(int i = 0; i < testUrlList.length; i++) {
      %>
            <tr>
                  <td id="td1"><%= testExplanation[i] %></td>
                  <td id="td1"><%= testUrlList[i] %></td>
                  <jsp:setProperty name="testUrl" property="url" value="<%= testUrlList[i] %>" />
      <%
                  if(!testUrl.isUrlAvailable()) {
      %>
                  <td id="td1err">
                        <jsp:getProperty name="testUrl" property="lastError" />
                  </td>
      <%
                  } else {
      %>
                  <td id="td1">passed</td>
      <%
                  };
      %>
            </tr>
            
      <%
      }
      %>
      </table>
      </dev>

      </body>
</html>

=== beforeSignin.jsp end =============

=== Signin.java start =============
/*
 * Created on Aug 20, 2004
 *
 */
package testremoteurl;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Properties;

/**
 * @author me: Vilia
 * (c) 2004
 */
public class Signin {
      private String lastError;
      private String sUrl;
      private int timeOut;

      public Signin() {
      }

      public void setUrl(String sUrl) {
            this.sUrl = sUrl;
      }

      public void setTimeout(String sTimeout) {
            timeOut = Integer.parseInt(sTimeout);
      }

      public boolean isUrlAvailable() {
            return isUrlAvailable(this.sUrl, this.timeOut);
      }

      /**
       * Check an Url availability
       *
       * @param sUrl            - An Url to be verified ("http://www.domain.com/page")
       * @param timeOut       - The connection time out [mS]
       *
       * @return boolean      - true : OK
       *                               - false : An Error, use getLastError() for more detailed
       *                                                 error explanation.
       */
      private boolean isUrlAvailable(String sUrl, int timeOut) {
            URL url;
            try {
                  if (timeOut > 0) {

                        Properties p = System.getProperties();
                        p.put(
                              "sun.net.client.defaultConnectTimeout",
                              String.valueOf(timeOut));
                        p.put(
                              "sun.net.client.defaultReadTimeout",
                              String.valueOf(timeOut));
                        System.setProperties(p);
                  }
                  url = new URL(sUrl);
            } catch (MalformedURLException mue) {
                  lastError = mue.getMessage();
                  return false;
            }
            try {
                  URLConnection uc = url.openConnection();
                  uc.connect();
                  if (uc instanceof HttpURLConnection) {
                        int respCode = ((HttpURLConnection) uc).getResponseCode();
                        if (respCode != 200) {
                              lastError = "HTTP Error: " + respCode;
                              return false;
                        }
                  }
            } catch (IOException ioe) {
                  if (ioe instanceof java.net.UnknownHostException) {
                        lastError = "Unknow Host: " + ioe.getMessage();
                  } else if (ioe instanceof java.net.ConnectException) {
                        lastError = ioe.getMessage();
                  } else {
                        lastError = ioe.toString();
                  }
                  return false;
            }

            return true;
      }

      /**
       * Return the Last error<br>
       * to be used immediately after an error detection
       *
       * @return String      - The last Error
       */
      public String getLastError() {
            return lastError;
      }

}

=== Signin.java end =============

=== result(html) start =============
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
      <head>
            <title></title>
      <style type="text/css"> <!--
      BODY {
            background-color: #ffffff;
      }
      #hdr1 {
            font-family: Arial;
            font-size: 24px;
      }
      #table1 {
            border-style: solid;
            border-width: 1px 0px 0px 1px;
            border-color: #000000;
            margin: 0px;
            padding: 0;
      }
      #th1 {
            border-style: solid;
            border-width: 0px 1px 1px 0px;
            border-color: #000000;
            background-color: #dcdcdc;
            margin: 0px;
            padding: 2px;
            font-family: Arial;
            font-size: 12px;
            font-weight:bold;
      }
      #td1 {
            border-style: solid;
            border-width: 0px 1px 1px 0px;
            border-color: #000000;
            background-color: #f0f8f8;
            margin: 0px;
            padding: 2px;
            font-family: Arial;
            font-size: 12px;
      }
      #td1err {
            border-style: solid;
            border-width: 0px 1px 1px 0px;
            border-color: #000000;
            background-color: #f0f8f8;
            margin: 0px;
            padding: 2px;
            font-family: Arial;
            font-size: 12px;
            color: #ff0000;
      }
      --></style>
      </head>
      <body>
            <div id="hdr1">Show Testing Capabilities</div>
            <br>
            <div>
            <table id="table1" cellspacing="0">
                  <tr>
                        <td id="th1">Test Type</td>
                        <td id="th1">URL</td>
                        <td id="th1">Result</td>
                  </tr>
                  
            
                  <tr>
                        <td id="td1">Unknown Host</td>
                        <td id="td1">http://www.ZZZyahoo.com</td>
                        <td id="td1">ddddd</td>
                  </tr>
                  
            
                  <tr>
                        <td id="td1">Valid host</td>
                        <td id="td1">http://www.yahoo.com</td>
                        <td id="td1">ddsdsdsdsd</td>
                  </tr>
                  
            
                  <tr>
                        <td id="td1">Connection Timeout</td>
                        <td id="td1">http://12.12.12.1</td>
                        <td id="td1err">error</td>
                  </tr>
                  
            
                  <tr>
                        <td id="td1">HTTP response Error (unknown page)</td>
                        <td id="td1">http://www.yahoo.com/noPageUrl</td>
                        <td id="td1">jhjhjh</td>
                  </tr>
                  
            
            </table>
            </div>

      </body>
</html>

=== result(html) end =============
0
 

Author Comment

by:krissav71
Comment Utility
Hi Vilia,

  Thank you for sending me the code.

   Here is what I did.

 1.  Created 3 files from the above code.

    a) Signin.jsp (changed the Ip Addr 12.12.12.1 to some valid value)
    b) Signin.java - Compiled this to get Signin.class
    c) Results.html

 2. Put all the 3 files on to the weblogic server.

 3. Opened the Signin.jsp in IE

I get the Signin.jsp page and it stays there. Do I need to do something more in order to get the test result?

Thanks.



0
 
LVL 5

Expert Comment

by:vilia
Comment Utility
No yo do not need to do anything else.

You do not need "result.html" it what signin.jsp sends to browser. I put the one only as result example

You should change:
     String[] testUrlList = {
          "http://www.ZZZyahoo.com", // unknown host
          "http://www.yahoo.com",  // ok
          "http://12.12.12.1",  // timeout
          "http://www.yahoo.com/noPageUrl"  // noPageUrl (HTTP response Err)
     };
     String[] testExplanation = {
          "Unknown Host",
          "Valid host",
          "Connection Timeout",
          "HTTP response Error (unknown page)"
     };
to
     String[] testUrlList = {
          "http://www.ZZZyahoo.com", // unknown host
          "http://www.yahoo.com",  // ok
          "http://12.12.12.1",  // timeout
          "http://www.yahoo.com/noPageUrl",  // noPageUrl (HTTP response Err)
          "http://mydomain/testUrl"  // Tuxedo login url
     };
     String[] testExplanation = {
          "Unknown Host",
          "Valid host",
          "Connection Timeout",
          "HTTP response Error (unknown page)",
          "Tuxedo login URL"
     };

(Signin.jsp needs to run on the WL server)

The class file needs to be in:
     ......./WEB-INF/classes/testremoteurl
0
 

Author Comment

by:krissav71
Comment Utility
Hi Vilia,

I was not able to work on this. I'll resume this activity on Tuesday next. I'll let you know the outcome.

Thanks,
Kris
0
 

Author Comment

by:krissav71
Comment Utility
Hi Vilia,

    I am still caught up in some priority work. I wasn't able to spend any time on this.

    I am going ahead and giving the points to you. You have the 500 points. Thank you for your help and support.
 
    I'll let you know if I need your help when I resume work on this.

Thanks,
Kris
0
 
LVL 5

Expert Comment

by:vilia
Comment Utility
Hi Kris,
I will be on vacation untill the second portion of september.

If you are not satisfied with solution, please feel free to withdraw points. Btw, I did not get a chanse to make the mail part, I can do the on in the third quorter.

Vilia
0
 

Author Comment

by:krissav71
Comment Utility
Thanks Vilia. I sure will seek your help if needed. Sure, the mail portion can be done in the 3rd qtr.

I'll keep you posted. Until then, happy vacation.

Thanks,
Kris
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now