// DeptServlet.java

package hr;

import java.rmi.RemoteException;
import java.io.IOException;
import java.util.*;
import javax.servlet.http.*;
import javax.servlet.*;
import javax.ejb.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;

public class DeptServlet extends HttpServlet
{
    private static Context nctx = null;

    public static final String hrBean = "java:comp/env/ejb/Hr";
    public static HrRemoteHome hrHome = null;
    public static HrRemote hrRemote = null;

    ServletOutputStream out;

    public void init() throws ServletException
    {
        setup();
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
    {
        response.setContentType("text/html");
        out = response.getOutputStream();
    
        run();

        out.close();
    }

    public void setup()
    {
        try {
            nctx = new InitialContext();

            hrHome = (HrRemoteHome)PortableRemoteObject.narrow(nctx.lookup(hrBean),
                                                               HrRemoteHome.class);
            hrRemote = hrHome.create();
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("Setup failed: " + e.getMessage());
        }
    }

    public void run()
    {
        System.out.println("DeptServlet.run(): client started...");
        //TODO: implement servlet client
    }

}
