Oracle8i Enterprise JavaBeans Developer's Guide and Reference Release 3 (8.1.7) Part Number A83725-01 |
|
You invoke a server object from an applet in the same manner as from a client. The only differences are the following:
ORBdisableLocator
, ORBClass
, and ORBSingletonClass.
The security sandbox constricts your applet from accessing anything on the local disk or from connecting to a remote host other than the host that the applet was downloaded from. If you create a signed JAR file as a trusted party, you can bypass the sandbox security. See http://java.sun.com
for more information on applet sandbox security and signed JAR files.
You perform the JNDI lookup within the applet the same as within any Oracle Java client, except that you set the following property within the initial context:
env.put(ServiceCtx.APPLET_CLASS, this);
By default, you do not need to install any JAR files on the client to run the applet. However, if you want to place the Oracle JAR files on the client machine, set the ClassLoader
property in the InitialContext
environment, as follows:
env.put('ClassLoader', this.getClass().getClassLoader());
The following shows the init
method within an applet that invokes the Bank example. The applet sets up the initial context--including setting the APPLET_CLASS
property--and performs the JNDI lookup giving the URL.
public void init() { // This GUI uses a 2 by 2 grid of widgets. setLayout(new GridLayout(2, 2, 5, 5)); // Add the four widgets. add(new Label("Account Name")); add(_nameField = new TextField()); add(_checkBalance = new Button("Check Balance")); add(_balanceField = new TextField()); // make the balance text field non-editable. _balanceField.setEditable(false); try { // Initialize the ORB (using the Applet).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);
env.put(ServiceCtx.APPLET_CLASS, this);
Context ic = new InitialContext(env);
_manager = (AccountManager)ic.lookup
} catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); throw new RuntimeException(); } }
("sess_iiop://hostfunk:2222/test/myBank");
Within the action
method, the applet invokes methods off of the retrieved object. In this example, the open
method of the retrieved AccountManager
object is invoked.
public boolean action(Event ev, Object arg) {
if(ev.target == _checkBalance) {
// Request the account manager to open a named account.
// Get the account name from the name text widget.
Bank.Account account = _manager.open(_nameField.getText());
// Set the balance text widget to the account's balance.
_balanceField.setText(Float.toString(account.balance()));
return true;
}
return false;
}
Oracle8i supports only the following Java plug-ins for the HTML page that loads in the applet: JDK 1.1, Java 2, and Oracle JInitiator. Each plug-in contains different syntax for the applet information. However, each HTML page may contain definitions for the following two properties:
ORBdisableLocator
set to TRUE--Required for all applets.
ORBClass
and ORBSingletonClass
definitions--Required for the applets that use the Java 2 or JInitiator plug-in.
The examples in the following sections show how to create the correct HTML definition for each plug-in type. Each HTML definition defines the applet bank example.
<pre> <html> <title>Applet talking to 8i</title> <h1>applet talking to 8i using java plug in 1.1 </h1> <hr> The bank example Specify the plugin in codebase, the class within the CODE parameter, the JAR files in the ARCHIVE parameter, the plugin version in the type parameter, and set ORBdisableLocator to true. <OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
WIDTH = 500 HEIGHT = 50
codebase="http://java.sun.com/products/plugin/1.1/
<COMMENT> Set the plugin version in the type, set ORBdisableLocator to true, the applet class within the java_CODE tag, the JAR files in the java_ARCHIVE tag, and the plug-in source site within the pluginspage tag.
jinstall-11-win32.cab#Version=1,1,0,0">
<PARAM NAME = CODE VALUE = OracleClientApplet.class >
<PARAM NAME = ARCHIVE VALUE = "oracleClient.jar,
aurora_client.jar,vbjorb.jar,vbjapp.jar" >
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.1">
<PARAM NAME="ORBdisableLocator" VALUE="true"><EMBED type="application/x-java-applet;version=1.1"
ORBdisableLocator="true"
java_CODE = OracleClientApplet.class
java_ARCHIVE = "oracleClient.jar,
aurora_client.jar,vbjorb.jar,vbjapp.jar"
WIDTH = 500 HEIGHT = 50
pluginspage="http://java.sun.com/products/plugin/1.1/plugin-install.html">
<NOEMBED></COMMENT> </NOEMBED></EMBED> </OBJECT> </center> <hr> </pre>Example 5-4 HTML Definition for Java 2 Plug-in
<pre> <html> <title>applet talking to 8i</title> <h1>applet talking to 8i using Java plug in 1.2 </h1> <hr> The bank example Specify the plugin in codebase, the class within the CODE parameter, the JAR files in the ARCHIVE parameter, the plugin version in the type parameter, and set ORBdisableLocator to true. <OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
WIDTH = 500 HEIGHT = 50
codebase="http://java.sun.com/products/plugin/1.2/jinstall-11-win32.cab#
<COMMENT> Set the plugin version in the type, set ORBdisableLocator to true, the ORBClass and ORBSingletonClass to the correct ORB class, the applet class within the java_CODE tag, the JAR files in the java_ARCHIVE tag, and the plug-in source site within the pluginspage tag.
Version=1,1,0,0">
<PARAM NAME = CODE VALUE = OracleClientApplet.class >
<PARAM NAME = ARCHIVE VALUE = "oracleClient.jar,
aurora_client.jar,vbjorb.jar,vbjapp.jar" >
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.1.2">
<PARAM NAME="ORBdisableLocator" VALUE="true">
<PARAM NAME="org.omg.CORBA.ORBClass" VALUE="com.visigenic.vbroker.orb.ORB">
<PARAM NAME="org.omg.CORBA.ORBSingletonClass"
VALUE="com.visigenic.vbroker.orb.ORB"><EMBED type="application/x-java-applet;version=1.1.2"
ORBdisableLocator="true"
org.omg.CORBA.ORBClass="com.visigenic.vbroker.orb.ORB"
org.omg.CORBA.ORBSingletonClass="com.visigenic.vbroker.orb.ORB"
java_CODE = OracleClientApplet.class
java_ARCHIVE = "oracleClient.jar,
aurora_client.jar,vbjorb.jar,vbjapp.jar"
WIDTH = 500 HEIGHT = 50
pluginspage="http://java.sun.com/products/plugin/1.2/plugin-install.html">
<NOEMBED></COMMENT> </NOEMBED></EMBED> </OBJECT> </center> <hr> </pre>Example 5-5 HTML Definition for JInitiator Plug-in
<h1> applet talking to 8i using JInitiator 1.1.7.18</h1> <COMMENT> Set the plugin version in the type, set ORBdisableLocator to true, the ORBClass and ORBSingletonClass to the correct ORB class, the applet class within the java_CODE tag, the source of the applet in the java_CODEBASE and the JAR files in the java_ARCHIVE tag.<EMBED type="application/x-jinit-applet;version=1.1.7.18"
java_CODE="OracleClientApplet"
java_CODEBASE="http://hostfunk:8080/applets/bank"
java_ARCHIVE="oracleClient.jar,aurora_client.jar,vbjorb.jar,vbjapp.jar"
WIDTH=400
HEIGHT=100
ORBdisableLocator="true"
org.omg.CORBA.ORBClass="com.visigenic.vbroker.orb.ORB"
org.omg.CORBA.ORBSingletonClass="com.visigenic.vbroker.orb.ORB"
serverHost="orasundb"
serverPort=8080
<NOEMBED> </COMMENT> </NOEMBED> </EMBED>
|
![]() Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|