8.1. Building a simple portal

The simple grid portal has a login screen as shown in Figure 8-1.

Figure 8-1. Sample grid portal login screen


After the user has successfully authenticated with a user ID and password, the welcome screen is presented, as shown in Figure 8-2 on page 217.

Figure 8-2. Simple grid portal welcome screen


From the left portion of the welcome screen, the user is able to submit an application by selecting a grid application from the list and clicking Submit Grid Application. With the buttons on the top right portion of the screen, the user is able to retrieve information about the grid application such as the status and the run results. Clicking the Logout button shows the login screen again.

Let us see how this may be implemented by using an application server such as WebSphere Application Server. Figure 8-3 on page 218 shows the high-level view of a simple grid portal application flow.

Figure 8-3. Simple grid portal application flow


The login.html produces the login screen, where the user enters the user ID and password. The control is passed to the Login Servlet with the user ID and password as input arguments. The user is authenticated by the servlet. If successful, the user is presented with a welcome screen with the welcome.html file. Otherwise, the user is presented with an unsuccessful login screen with the unsuccessfulLogin.html file. See Figure 8-4 on page 219.

Figure 8-4. Simple grid portal login flow


Example 8-1 shows sample script code for the login.html to display the sample login screen.

Tip

The login servlet is associated with login.html with the following statement:

<FORM name="form" method="post" action="Login">


Example 8-1. Sample login.html script
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM WebSphere Studio">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="theme/Master.css" rel="stylesheet"
   type="text/css">
<TITLE>login.html</TITLE>
</HEAD>
<BODY>
<FORM name="form" method="post" action="Login">
<TABLE border="1" width="662" height="296">
   <TBODY>
      <TR>
         <TD width="136" height="68"></TD>
         <TD width="518" height="68"></TD>
       </TR>
       <TR>
          <TD width="136" height="224"></TD>
          <TD width="518" height="224">
          <P>Userid: <INPUT type="text" name="userid" size="20"
maxlength="20"></P>
          <P>Password: <INPUT type="password" name="password" size="20"
             maxlength="20"></P>
          <INPUT type="submit" name="loginOkay" value="Login"></TD>
      </TR>
   </TBODY>
</TABLE>
</FORM>
</BODY>
</HTML

Example 8-2 shows sample Login.java servlet code.

Tip

The class definition clause extends HttpServlet distinguishes a servlet. Another distinguishing mark of a servlet is the input parameters (HttpServletRequest req, HttpServletResponse res).


The arguments from the login.html are passed to the Login.java servlet through the HttpServletRequest req parameter. When the authentication is successful, the control is passed to wecome.html using a redirect command, rd.forward(request, response).

Example 8-2. Sample Login.java servlet code
package com.ibm.itso.mygridportal.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @version 1.0
 * @author
 */
public class Login extends HttpServlet {

   /**
   * @see javax.servlet.http.HttpServlet#void
(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
   */
   public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
      performTask(req, resp);
   }

   /**
   * @see javax.servlet.http.HttpServlet#void
(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
   */
   public void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
      performTask(req, resp);
   }
   public void performTask(
      HttpServletRequest request,
      HttpServletResponse response)
      throws ServletException {

      /**
      * Add your authentication code here
      */
      /**
      * If authentication successful
      */
      System.out.println("Login: forwarding to welcome page");
      try {
         RequestDispatcher rd =
            getServletContext().getRequestDispatcher("welcome.html");
         rd.forward(request, response);
      } catch (java.io.IOException e) {
         System.out.println(e);
      }
      /**
      * If authentication failed
      */
      try {
         RequestDispatcher rd =
            getServletContext().getRequestDispatcher 
               ("unsuccessfulLogin.html");
         rd.forward(request, response);
      } catch (java.io.IOException e) {
         System.out.println(e);
      }
   }
}

The file welcome.html produces the welcome screen. From here, the user may select a grid application from the list and submit. Clicking Submit Grid Application button sends control to the application servlet. The selected grid application is identified in the servlet and appropriate routines are invoked as shown in Figure 8-5 on page 222.

Figure 8-5. Simple grid portal application submit flow


The welcome.html script is provided in Example 8-3 on page 223.

Tip

The application servlet is associated with welcome.html with following statement:

<FORM name="form" method="post" action="Application">


Tip

The application selection list is produced by the nested statements:

<SELECT size="4" name="appselect">
   <OPTION value="weather">WeatherSimulation</OPTION>
   <OPTION value="gene">GeneProject</OPTION>
   <OPTION value="test">TestApp</OPTION>
   <OPTION value="demo" selected>DemoApp</OPTION>
</SELECT>


Example 8-3. Simple grid portal welcome.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<%@ page
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM WebSphere Studio">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="theme/Master.css" rel="stylesheet"
   type="text/css">
<TITLE>welcome.jsp</TITLE>
</HEAD>
<BODY>
<FORM name="form" method="post" action="Application">
<H1 align="center">Welcome to Grid Portal Demo</H1>
<TABLE border="1" width="718" height="262">
   <TBODY>
      <TR>
         <TD width="209" height="37"></TD>
         <TD width="501" height="37">
         <TABLE border="1" width="474">
            <TBODY>
               <TR>
                   <TD width="20%"><INPUT type="submit" name="status"
                      value="My Application Status"></TD>
                   <TD width="20%"><INPUT type="submit" name="result"
                      value="My Application Results"></TD>
                   <TD width="20%"></TD>
                   <TD width="20%"></TD>
                   <TD width="20%"><INPUT type="submit" name="logout"
                      value="Logout"></TD>
               </TR>
            </TBODY>
         </TABLE>
         </TD>
      </TR>
      <TR>
         <TD width="209" height="225" valign="top">
         <P>Select an  application and click Grid Application Application
         button below.</P><SELECT size="4" name="appselect">
            <OPTION value="weather">WeatherSimulation</OPTION>
            <OPTION value="gene">GeneProject</OPTION>
            <OPTION value="test">TestApp</OPTION>
            <OPTION value="demo" selected>DemoApp</OPTION>
            </SELECT><br>
            <INPUT type="submit" name="submit" value="Submit Grid
  Application"><BR>

            </TD>
            <TD width="501" height="225">
            <P>This grid portal is a demontration to show how easily you can
submit an application to the grid for execution. In this demo you will be able
to:
            </P>
            <UL>
               <LI>Submit your application to the grid</LI>
               <LI>Query your application status</LI>
               <LI>Query your results</LI>
            </UL>

            <P>You may now submit an application to the grid. <BR>Please note:
this portal is designed for demonstration purposes only.
         </P>
         </TD>
      </TR>
   </TBODY>
</TABLE>
</FORM>
</BODY>
</HTML>

The Application.java servlet code is shown in Example 8-4 on page 225.

Tip

Determine which application was selected:

private void submitApplication() {
   if (appselect[0].equals("weather"))
      submitWeather();
   else if (appselect[0].equals("gene"))
      submitGene();
   else if (appselect[0].equals("test"))
      submitTest();
   else if (appselect[0].equals("demo"))
      submitDemo();
   else
      invalidSelection();
}


Tip

Determine if the Submit Grid Application button was checked:

      String[] submit;
      String[] appselect;
         try {
            // Which button selected?
            submit = req.getParameterValues("submit");
            // Which application was selected?
            appselect = req.getParameterValues("appselect");

            if (submit != null && submit.length > 0)
               submitApplication(); // submit Application.
               ...
            else
               invalidInput();
       } catch (Throwable theException) {
          // uncomment the following line when unexpected exceptions are
occuring to aid in debugging the problem
          // theException.printStackTrace();
          throw new ServletException(theException);
       }


Example 8-4. Simple grid portal Application.java servlet code
// 5630-A23, 5630-A22, (C) Copyright IBM Corporation, 2003
// All rights reserved. Licensed Materials Property of IBM
// Note to US Government users: Documentation related to restricted rights
// Use, duplication or disclosure is subject to restrictions set forth in GSA
ADP Schedule with IBM Corp.
// This page may contain other proprietary notices and copyright information,
the terms of which must be observed and followed.
//
// This program may be used, executed, copied, modified and distributed
// without royalty for the purpose of developing, using,
// marketing, or distributing.
//
package com.ibm.itso.mygridportal.web;

import java.io.IOException;
import javax.servlet.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.*;

/**
 * @version 1.0
 * @author
 */
public class Application extends HttpServlet {
   HttpServletRequest req; //request
   HttpServletResponse res; //response
   JSPBean jspbean = new JSPBean();
   PrintWriter out;
   String[] submit;
   String[] getresult;
   String[] getstatus;
   String[] logout;
   String[] appselect;
   /**
   * @see javax.servlet.http.HttpServlet#void
(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
   */
   public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
      performTask(req, resp);
   }

   /**
   * @see javax.servlet.http.HttpServlet#void
(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
   */
   public void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
      performTask(req, resp);
   }

   public void performTask(
      HttpServletRequest request,
      HttpServletResponse response)
      throws ServletException {

      req = request;
      res = response;

      res.setContentType("text/html");
      res.setHeader("Pragma", "no-cache");
      res.setHeader("Cache-control", "no-cache");
      try {
         out = res.getWriter();
      } catch (IOException e) {
         System.err.println("Application:getWriter:" + e);
      }

      // --- Read and validate user input, initialize. ---
      try {
         // Which button selected?
         submit = req.getParameterValues("submit");
         getresult = req.getParameterValues("result");
         getstatus = req.getParameterValues("status");
         logout = req.getParameterValues("logout");

         // Which application was selected?
         appselect = req.getParameterValues("appselect");

         if (submit != null && submit.length > 0)
            submitApplication(); // submit Application.
         else if (getresult != null && getresult.length > 0)
            getResult(); // get run result.
         else if (getstatus != null && getstatus.length > 0)
            getStatus(); // get Application status.
         else if (logout != null && logout.length > 0)
            doLogout(); // logout.
         else
            invalidInput();
      } catch (Throwable theException) {
         // uncomment the following line when unexpected exceptions are
occuring to aid in debugging the problem
         // theException.printStackTrace();
         throw new ServletException(theException);
      }

   }

   private void submitApplication() {
      if (appselect[0].equals("weather"))
         submitWeather();
      else if (appselect[0].equals("gene"))
         submitGene();
      else if (appselect[0].equals("test"))
         submitTest();
      else if (appselect[0].equals("demo"))
         submitDemo();
      else
         invalidSelection();
   }

   private void submitWeather() {
   /**
   * Add code to submit the weather application here
   */
   }

   private void submitGene() {
   /**
   * Add code to submit the gene application here
   */
   }

   private void submitTest() {
   /**
   * Add code to submit the test application here
   */
   }

   private void submitDemo() {
   /**
   * Add code to submit the demo application here
   */
   }

   private void getResult() {
   /**
   * Add code to get the Application results here
   */
   }

   private void getStatus() {
   /**
   * Add code to get the Application status here
   */
   }

   private void doLogout() {
      System.out.println("doLogout: forwarding to login page");
      try {
         RequestDispatcher rd =
            getServletContext().getRequestDispatcher("login.html");
         rd.forward(req, res);
      } catch (javax.servlet.ServletException e) {
         System.out.println(e);
      } catch (java.io.IOException e) {
         System.out.println(e);
      }
   }

   private void invalidSelection() {
      // Something was wrong with the client input
      try {
         RequestDispatcher rd =
            getServletContext().getRequestDispatcher("invalidSelection.html");
         rd.forward(req, res);
      } catch (javax.servlet.ServletException e) {
         System.out.println(e);
      } catch (java.io.IOException e) {
         System.out.println(e);
      }
   }

   private void invalidInput() {
      // Something was wrong with the client input
      try {
         RequestDispatcher rd =
            getServletContext().getRequestDispatcher("invalidInput.html");
         rd.forward(req, res);
      } catch (javax.servlet.ServletException e) {
         System.out.println(e);
      } catch (java.io.IOException e) {
         System.out.println(e);
      }
   }

   private void sendResult(String[] list) {
      int size = list.length;
      for (int i = 0; i < size; i++) {
         String s = list[i];
         out.println(s + "<br>");
         //System.out.println("s=" + s); //trace
      } //end for
   }

}

From the welcome screen, the user may also request application status, application results, and logout. Figure 8-6 on page 230 shows the flow. When the user clicks My Application Status, My Application Results, or Logout, the Application Servlet is called.

Figure 8-6. Simple grid portal application information and logout flow


Tip

Determine which button is pressed from welcome.html:

<TD width="20%"><INPUT type="submit" name="status"
   value="My Application Status"></TD>
<TD width="20%"><INPUT type="submit" name="data"
   value="My Application Results"></TD>
<TD width="20%"></TD>
<TD width="20%"></TD>
<TD width="20%"><INPUT type="submit" name="logout"
   value="Logout"></TD>


Tip

Determine which button is pressed:

      String[] getresult;
      String[] getstatus;
      String[] logout;
         try {
            // Which button selected?
            getresult = req.getParameterValues("result");
            getstatus = req.getParameterValues("status");
            logout = req.getParameterValues("logout");

            if (submit != null && submit.length > 0)
               submitApplication(); // submit Application.
            else if (getresult != null && getresult.length > 0)
               getResult(); // get application run results.
            else if (getstatus != null && getstatus.length > 0)
               getStatus(); // get application status.
            else if (logout != null && logout.length > 0)
               doLogout(); // logout.
            else
               invalidInput();
       } catch (Throwable theException) {
          // uncomment the following line when unexpected exceptions are
occuring to aid in debugging the problem
          // theException.printStackTrace();
          throw new ServletException(theException);
       }


Tip

How to redirect to an html page:

private void doLogout() {
   try {
      RequestDispatcher rd =
         getServletContext().getRequestDispatcher("login.html");
      rd.forward(req, res);
   } catch (javax.servlet.ServletException e) {
      System.out.println(e);
   } catch (java.io.IOException e) {
      System.out.println(e);
   }
}


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.134.79.121