/**
 * Copyright (c) 2001 Alexander V. Konstantinou (akonstan@acm.org)
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  Alexander V. Konstantinou makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 */

import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.registry.*;

/**
 * Test remote server
 *
 * @version $Revision: 1.1 $ ; $Date: 2001/12/10 20:43:29 $
 * @author Alexander V. Konstantinou (akonstan@acm.org)
 */
public class TestServer extends UnicastRemoteObject implements TestRemote {

  /** Hard-coded registry port */
  public static final int REGISTRY_PORT = 7123;

  /**
   */
  public TestServer() throws RemoteException {
    super();
  }

  /**
   * Returns the string argument in lower case
   */
  public String toLowerCase(String str) throws java.rmi.RemoteException {
    System.out.println(new java.util.Date() + " toLowerCase(" + str +
		       "): invoked by " +
		       SecureRMISocketFactory.getLocalThreadLastReadPrincipal());

    if (str == null) {
      return(null);
    } else {
      return(str.toLowerCase());
    }
  }

  /**
   */
  public static void main(String[] args) throws Exception {    
    System.out.println("System time: " + new java.util.Date());

    //

    System.out.println("Registering secure RMI socket factory ...");

    java.rmi.server.RMISocketFactory.setSocketFactory
      (new SecureRMISocketFactory());

    // 

    System.out.println("Starting RMI registry on port " + REGISTRY_PORT +
		       " ...");

    Registry registry = LocateRegistry.createRegistry(REGISTRY_PORT);

    //

    String name = "rmi://localhost:" + REGISTRY_PORT + "/Test";

    System.out.println("Binding TestRemote server to " + name + " ...");

    TestServer server = new TestServer();

    Naming.bind(name, server);

    System.out.println("Test object bound to " + name);
  }
}


