<HTML>
<%@ page import="employee.Employee, employee.EmployeeHome, employee.EmpRecord, oracle.aurora.jndi.sess_iiop.ServiceCtx, javax.naming.Context, javax.naming.InitialContext, java.util.Hashtable"  %>

<HEAD> <TITLE> The CallEJB JSP  </TITLE> </HEAD>
<BODY BGCOLOR="white">
<BR>
<%  
    String empNum = request.getParameter("empNum");
    String surl = request.getParameter("surl");
    String inJServer = System.getProperty("oracle.jserver.version");
    
    if (empNum != null) { %>

      <h2><BLOCKQUOTE><BIG><PRE>
        <%= doCallEJB(Integer.parseInt(empNum), surl, inJServer) %>
      </PRE></BIG></BLOCKQUOTE></h2>
      <HR>
<%  }  %>

<P><B>Enter the following data:
   <FORM METHOD=get> 
     Employee Number: <INPUT TYPE=text NAME="empNum" SIZE=10 value="7654">
<%   if (inJServer == null) { 
      // not running in JServer, need a service URL 
%>
     <P> EJB Service URL: <INPUT TYPE=text NAME="surl" SIZE=40 
                              VALUE="sess_iiop://localhost:2481:ORCL">
   <% } %>
<INPUT TYPE=submit VALUE="Ask Oracle">
</FORM>
</BODY>
</HTML>

<%! private String doCallEJB(int empno, String serviceURL, String inJServer) {
    try {
      Context ic = null;
      EmployeeHome home = null;
      if (inJServer == null)
	{ // not running in JServer, usual client setup
          Hashtable env = new Hashtable();
          env.put(Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");
          env.put(Context.SECURITY_PRINCIPAL, "scott");
          env.put(Context.SECURITY_CREDENTIALS, "tiger");
          env.put(Context.SECURITY_AUTHENTICATION, ServiceCtx.NON_SSL_LOGIN);
          ic = new InitialContext (env);
          home = (EmployeeHome)ic.lookup (serviceURL + 
                           "/test/employeeBean");

        }
	else { // in JServer, use simplified and optimized lookup
          ic = new InitialContext();
          home = (EmployeeHome)ic.lookup ("/test/employeeBean");
        }
      Employee testBean = home.create();
      EmpRecord empRec = empRec = testBean.query (empno);
      return "Hello, I'm an EJB in Oracle 8i.\n  Employee " + 
              empRec.ename + " earns $" + empRec.sal;
    } catch (Exception e) { return "Error occurred: " + e;}
  } 
%>
