-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
1.2.1
-
generic
-
generic
Name: clC74495 Date: 09/16/99
1. Steps
- In client code, set SocketFactory to customized one like this;
---------------------------------
RMISocketFactory.setSocketFactory(new
RMISocketFactory);
---------------------------------
- Start up the client with Java Plug-in
- look up the RMI server
- starting communication
- you will see the error message in the following;
2. Source Code for Client
* You don't need the code for server to meet the error.
---------------------------------
// SetSocket.java
import java.applet.*;
import java.rmi.server.*;
import java.rmi.Naming;
import java.net.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class SetSocket extends Applet implements ActionListener{
Server server; // remote interface named Server
TextField textfield;
Label label;
Button button;
/** init method */
public void init(){
// show default SocketFactory
System.out.println("Defined Socket Factory->"+RMISocketFactory.getSocketFactory());
// set RMISocketFactory to customized one
RMISocketFactory sf = new MyRMISocketFactory();
try{
RMISocketFactory.setSocketFactory(sf);
System.out.println("Set Socket Factory done ...\n"
+ "Defined Socket Factory->"
+ RMISocketFactory.getSocketFactory());
} catch (Exception ex) {
System.out.println("Set Scket Factory: an exception occurred:");
ex.printStackTrace();
System.out.println("Defined Socket Factory(err)->"+RMISocketFactory.getSocketFactory());
}
// call a method which is specially added to MyRMISocketFactory
// You'll meet an exception if you have failed to set SocketFactory
((MyRMISocketFactory)RMISocketFactory.getSocketFactory()).addedMethod();
try{
server = (Server)Naming.lookup("//"+
getCodeBase().getHost()+"/RMIServer");
System.out.println("Lookup is successfully completed");
}catch(Exception re){
re.printStackTrace();
}
draw();
}
public void draw(){
// show components to confirm server response
textfield= new TextField("input_string");
label= new Label("still_blank_label");
label.setBackground(Color.blue);
button = new Button("push!");
button.addActionListener(this);
add(label);
add(button);
add(textfield);
}
// send a String to the server and receive changed String by server
public void actionPerformed(ActionEvent ae){
String rmiSt=null;
String st=textfield.getText();
try{
rmiSt = server.reply(st);
System.out.println("returned String is :"+rmiSt);
}catch(Exception rex){
rex.printStackTrace();
}
label.setText(rmiSt);
repaint();
}
---------------------------------
// MyRMISocketFactory.java
import java.net.*;
import java.io.*;
public class MyRMISocketFactory extends java.rmi.server.RMISocketFactory{
public Socket createSocket(String host,int port) throws IOException {
return new Socket(host, port);
}
public ServerSocket createServerSocket(int port) throws IOException {
return new ServerSocket(port);
}
public void addedMethod(){
System.out.println("This RMISocketFactory is successfully set to customized one!!");
}
}
---------------------------------
3. error message
--------------------------------------------------
Set Socket Factory: an exception occurred:
java.net.SocketException: factory already defined
at java.rmi.server.RMISocketFactory.setSocketFactory(RMISocketFactory.java:100)
at SetSocket.init(SetSocket.java:26)
at sun.applet.AppletPanel.run(AppletPanel.java:357)
at java.lang.Thread.run(Thread.java:479)
Defined Socket Factory(err)->sun.plugin.RMIPluginSocketFactory@4effdbe7
--------------------------------------------------
4. Any information
- The contents of our RMISocketFactory is not concerned with this error. You can see our MyRMISocketFactory class is really simple. It just extends RMISocketFactory class.
5. additional information
- We think Java Plug-in itself has already set SocketFactory for corresponding to WWW proxy.
(Review ID: 95320)
======================================================================