Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

RMI problems

0 views
Skip to first unread message

Lorenzo

unread,
Jun 7, 2001, 11:39:03 AM6/7/01
to
Hi to everybody !!! :)

I'm very new to RMI. I am trying to learn it, but i have a lot of
problems that i don't understand. So, I've the following simple
applications :


FIRST

import java.util.*;
import java.rmi.*;
import StrongComputer;

public class RmiServer {
public static void main (String args[]) {
// Crea ed installa un security manager apposito.
System.setSecurityManager(new RMISecurityManager());
try {
// Crea una istanza dell'oggetto remoto
System.out.println("Creazione oggetto remoto");
StrongComputer sc = new StrongComputer();
// Bind l'oggetto remoto nel remote registry. Si usa il metodo
// statico rebind() per evitare conflitti
// con assegnazioni precedenti.
System.out.println("Bind con nome simbolico: StrongComputer");
Naming.rebind("StrongComputer", sc);
System.out.println("StrongComputer é adesso disponibile");
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}

SECOND

import java.awt.event.*;
import java.net.MalformedURLException;
import java.rmi.*;
import StrongComputer;
import java.applet.Applet;
import java.awt.*;


public class RmiClientApplet extends Applet {
TextArea TA;
Button But;
StrongComputerInterface sci;

public void init(){
setLayout(null);
TA=new TextArea();
TA.setBounds(10,10,400,200);
TA.setEditable(false);
TA.setFont(new Font("TimesNewRoman",0,18));
add(TA);
But=new Button();
But.setBounds(10,250,100,20);
But.setLabel("Chiama");
But.setFont(new Font("TimesNewRoman",0,18));
add(But);
repaint();
try{
TA.append("Crea ed installa un security manager \n");
System.setSecurityManager(new RMISecurityManager());
}
catch(SecurityException se){
TA.append("Security Manager già installato\n");
}
TA.append("Ottiene un riferimento di un oggetto remoto con lookup
\n");
// Ottiene un riferimento di un oggetto remoto con lookup.
try {
String url = new String ("//localhost/StrongComputer");
TA.append("lookup StrongComputerServer, url = " + url+"\n");
// Questo è il meccanismo fondamentale per ottenere il riferimento
// all'oggetto remoto messo a disposizione dal server rmi.
sci = (StrongComputerInterface)Naming.lookup(url);
TA.append("_Client Pronto\n");
}
catch (Exception e) {
System.out.println("Error in getting StrongComputerServer" + e);
}
}
public boolean processEvent(Event event){
if ((event.target==But) && (event.id==Event.ACTION_EVENT )){
try{
TA.append("Invocazione del metodo remoto \n");
float res=sci.StrongComputing(2,2);
TA.append("Il quadrato di 2 é: "+res+"\n");
}
catch(RemoteException e){TA.append("Eccezione remota");}
}
return true;
}
}

THIRD
import java.rmi.*;
public interface StrongComputerInterface extends Remote {
public float StrongComputing(float f, int i) throws RemoteException;
}


FOURTH
import java.rmi.*;
import java.rmi.server.*;
import java.io.*;
import StrongComputerInterface;
/**
Questa classe é l’oggetto remoto che viene referenziato dallo
skeleton sul lato server e dallo stub sul client
*/
public class StrongComputer extends UnicastRemoteObject
implements StrongComputerInterface {
// Costruttore di classe
public StrongComputer() throws RemoteException{}
//computazione pesante
public float StrongComputing(float f, int i) throws
RemoteException{
System.out.println("Esecuzione del metodo remoto");
float res= (float)java.lang.Math.pow(2,2);
System.out.println("Il risultato é: "+res);
return res;
}
}


Well, i've the above code, every things seems work well when i compile
the each files and i'm creating the Skel and the Stub file's until
when i start the rmiregistry .. but when i'm going to start the
Server,

java RmiServer i get the following errors

Creation the remote object
Bind whit the symbolic name : StongComputer
java.security.AccessControlException: access denied
(java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnection(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown
Source)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown
Source)
at sun.rmi.transport.tpc.TCPEndpoint.newSocket(Unknown Source)
at sun.rmi.transport.tpc.TCPChannel.createConnection(Unknown Source)
at sun.rmi.transport.tpc.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
at sun.rmi.registry.registry.RegistryImpl_Stub.rebind(Unknown Source)
at sun.rmi.Naming.rebind(Unknown Source)
at RmiServer.main(RmiServer.java:17)
access denied (java.net.SocketPermission 127.0.0.1:1099
connect,resolve)

Can anybody of you tell me why it doesn't work? Or let me know a
simple applications that do the same things of the above code?

PS: the environment where i work is Windows NT WorkStation 4.0 SP5.

and the java.policy file is the following

// Standard extensions get all permissions by default

grant codeBase "file:${java.home}/lib/ext/*" {
permission java.security.AllPermission;
};

// default permissions granted to all domains

grant {
// Allows any thread to stop itself using the java.lang.Thread.stop()
// method that takes no argument.
// Note that this permission is granted by default only to remain
// backwards compatible.
// It is strongly recommended that you either remove this permission
// from this policy file or further restrict it to code sources
// that you specify, because Thread.stop() is potentially unsafe.
// See "http://java.sun.com/notes" for more information.
permission java.lang.RuntimePermission "stopThread";

// allows anyone to listen on un-privileged ports
permission java.net.SocketPermission "localhost:1024-", "listen";

// "standard" properies that can be read by anyone

permission java.util.PropertyPermission "java.version", "read";
permission java.util.PropertyPermission "java.vendor", "read";
permission java.util.PropertyPermission "java.vendor.url", "read";
permission java.util.PropertyPermission "java.class.version", "read";
permission java.util.PropertyPermission "os.name", "read";
permission java.util.PropertyPermission "os.version", "read";
permission java.util.PropertyPermission "os.arch", "read";
permission java.util.PropertyPermission "file.separator", "read";
permission java.util.PropertyPermission "path.separator", "read";
permission java.util.PropertyPermission "line.separator", "read";

permission java.util.PropertyPermission "java.specification.version",
"read";
permission java.util.PropertyPermission "java.specification.vendor",
"read";
permission java.util.PropertyPermission "java.specification.name",
"read";

permission java.util.PropertyPermission
"java.vm.specification.version", "read";
permission java.util.PropertyPermission
"java.vm.specification.vendor", "read";
permission java.util.PropertyPermission "java.vm.specification.name",
"read";
permission java.util.PropertyPermission "java.vm.version", "read";
permission java.util.PropertyPermission "java.vm.vendor", "read";
permission java.util.PropertyPermission "java.vm.name", "read";
};

Any suggestions would be greatly appreciated!!
Thanks!!

Lorenzo

Roedy Green

unread,
Jun 7, 2001, 5:12:02 PM6/7/01
to
On 7 Jun 2001 08:39:03 -0700, lorenzo...@tiscalinet.it (Lorenzo)
wrote or quoted :

>import StrongComputer;

You may just have a typo problem. StongComputer or StrongComputer

For more detail, please look up the key words mentioned in this post in
the Java Glossary at: http://mindprod.com/gloss.html
If you don't see what you were looking for, complain!
or send your contribution for the glossary.

--
Roedy Green, Canadian Mind Products
Custom computer programming since 1963. Ready to take on new work.

Maris Orbidans

unread,
Jun 11, 2001, 10:34:14 AM6/11/01
to
hi

Add to java.policy this line

permission java.net.SocketPermission "*:1099", "connect,resolve";


Maris Orbidans


Lorenzo <lorenzo...@tiscalinet.it> wrote in message
news:e20c619.01060...@posting.google.com...

0 new messages