<HTML>
<%@ page import="hello.Hello, oracle.aurora.jndi.sess_iiop.ServiceCtx, javax.naming.Context, javax.naming.InitialContext, java.util.Hashtable"  %>

<HEAD> <TITLE> The CallCORBA JSP  </TITLE> </HEAD>
<BODY>
<BR>
<%  
    String surl = request.getParameter("surl");
    String inJServer = System.getProperty("oracle.jserver.version");

    if ((surl != null) || (inJServer != null)) { 
 %>

        <h2><BLOCKQUOTE><BIG><PRE>
           <%= doCallCORBA(surl, inJServer) %>
        </PRE></BIG></BLOCKQUOTE></h2>
        <HR>
 <% }
    if (inJServer == null)
    { // not running in JServer, ask for a CORBA service URL
 %>    
      <P><B>Enter a CORBA service URL:</B></P>
      <FORM METHOD=get> 
      <INPUT TYPE=text NAME="surl" SIZE=40 
             VALUE="sess_iiop://localhost:2481:ORCL">
      <INPUT TYPE=submit VALUE="Ask Oracle">
      </FORM>

<%  } %>

 </BODY>
</HTML>

<%! private String doCallCORBA(String serviceURL, String inJServer) 
    {
      Context ic = null;
      Hello hello = null;
      try {
        if (inJServer != null) {
          // use simplified and optimized lookup in JServer 
          ic = new InitialContext();
          hello = (Hello) ic.lookup("/test/myHello");
        } else if (serviceURL != null) { 
          // not running in JServer, use standard lookup	
          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);
          hello = (Hello)ic.lookup (serviceURL + "/test/myHello");
        }
        return ("Hello, I'm a CORBA object in Oracle 8i.\n" 
              + hello.helloWorld());
      } catch (Exception e) { return "Error occurred: " + e; }
    }
%>
