Methods Summary |
---|
public void | doGet(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 DaytimeServer | getDaytimeServer()
// 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.String | getRegistryHost()
// Return either the hostname given by "registryHost" or
// if no name was given return null to imply localhost
return getInitParameter("registryHost");
|
private java.lang.String | getRegistryName()
String name = getInitParameter("registryName");
return (name == null ? "DaytimeServlet" : name);
|
private int | getRegistryPort()
try { return Integer.parseInt(getInitParameter("registryPort")); }
catch (NumberFormatException e) { return Registry.REGISTRY_PORT; }
|