/* JFox, the OpenSource J2EE Application Server
 *
 * Distributable under GNU LGPL license by gun.org
 * more details please visit http://www.huihoo.org/jfox
 */
package org.jfox.examples.web;

import java.io.IOException;
import javax.ejb.EJBMetaData;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jfox.examples.ejb.stateless.TestStateless;
import org.jfox.examples.ejb.stateless.TestStatelessHome;

/**
 * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
 */

public class TestStatelessServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/plain");
        try {
            Context ctx = new InitialContext();
            Object obj = ctx.lookup("/ejb/TestStatelessEJB");
            TestStatelessHome home = (TestStatelessHome) javax.rmi.PortableRemoteObject.narrow(obj, TestStatelessHome.class);
            TestStateless hello = home.create();
            EJBMetaData meta = home.getEJBMetaData();
            ServletOutputStream out = response.getOutputStream();
            out.println("result returned by jfox application server:");
            out.println("EJBMetaData: " + meta);
            out.println("Voice from TestStateless: " + hello.getVoice());
        }
        catch(Exception e) {
            throw new ServletException(e);
        }

    }
}
