FileDocCategorySizeDatePackage
DaytimeClientServlet.javaAPI DocExample2049Tue Jan 25 10:45:14 GMT 2000None

DaytimeClientServlet

public class DaytimeClientServlet extends HttpServlet

Fields Summary
DaytimeServer
daytime
Constructors Summary
Methods Summary
public voiddoGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)

    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();

    // Get a daytime object if we haven't before
    if (daytime == null) {
      daytime = getDaytimeServer();
      if (daytime == null) {
        // Couldn't get it, so report we're unavailable.
        throw new UnavailableException(this, "Could not locate daytime");
      }
    }

    // Get and print the current time on the (possibly remote) daytime host
    out.println(daytime.getDate().toString());
  
protected DaytimeServergetDaytimeServer()

    // Set the security manager if it hasn't been done already.
    // Provides protection from a malicious DaytimeServer stub.
    if (System.getSecurityManager() == null) {
      System.setSecurityManager(new RMISecurityManager());
    }

    try {
      Registry registry =
        LocateRegistry.getRegistry(getRegistryHost(), getRegistryPort());
      return (DaytimeServer)registry.lookup(getRegistryName());
    }
    catch (Exception e) {
      getServletContext().log(e, "Problem getting DaytimeServer reference");
      return null;
    }
  
private java.lang.StringgetRegistryHost()

    // Return either the hostname given by "registryHost" or
    // if no name was given return null to imply localhost 
    return getInitParameter("registryHost");
  
private java.lang.StringgetRegistryName()

    String name = getInitParameter("registryName");
    return (name == null ? "DaytimeServlet" : name);
  
private intgetRegistryPort()

    try { return Integer.parseInt(getInitParameter("registryPort")); }
    catch (NumberFormatException e) { return Registry.REGISTRY_PORT; }