RMI -IIOP with an Applet

i am trying a to make simple HelloWorld applet over RMI-IIOP.. Code given as ..

//interface class

import java.rmi.Remote;

import java.rmi.RemoteException;

public interface HelloInterface extends Remote{

String sayHello() throws RemoteException;

}

// Server implementing the interface..

import javax.rmi.PortableRemoteObject;

import java.rmi.*;

import javax.naming.*;

import java.util.Hashtable;

public class HelloServer extends PortableRemoteObject implements HelloInterface {

String Name;

public HelloServer(String name) throws RemoteException{

super();

Name=name;

}

public String sayHello() throws RemoteException {

System.out.println("Hello " + Name);

return Name;

}

public static void main(String str[]){

try{

HelloServer objHello=new HelloServer("Nitin");

Hashtable props = new Hashtable();

props.put("java.naming.factory.initial","com.sun.jndi.cosnaming.CNCtxFactory");

props.put("java.naming.provider.url","iiop://192.168.4.146:900");

Context ctx = new InitialContext(props);

ctx.rebind("objhello", objHello);

System.out.println("HEllo Server bound in registry");

}catch(Exception e){

e.printStackTrace();

}

}

}

// Hello Applet

import java.applet.Applet;

import java.awt.Graphics;

import javax.naming.*;

import java.rmi.RMISecurityManager;

import java.util.Hashtable;

import javax.rmi.PortableRemoteObject;

public class HelloApplet extends Applet {

String message=null;

public void init(){

try{

Hashtable props = new Hashtable();

props.put("java.naming.factory.initial","com.sun.jndi.cosnaming.CNCtxFactory");

props.put("java.naming.provider.url","iiop://192.168.4.146:900");

Context ctx = new InitialContext(props);

HelloInterface obj = (HelloInterface) PortableRemoteObject.narrow(ctx.lookup("objhello"),HelloInterface.class);

//obj=(HelloInterface) Naming.lookup("//" + getCodeBase().getHost() + "/objhello");

message=obj.sayHello();

}catch(Exception e){

e.printStackTrace();

}

}

public void paint(Graphics g){

g.drawString(message,25 ,50);

}

}

now while exicuting the programe

first i will run the ordb by command prompt as

c:\>start ordb -OBDInitialPort 900

then i run my hello server

which bind the object in registry..

now i run my applet programe..

after that when i run my applet programe through appletviewer it print ''Nitin''...but when i run my applet programe through hello.html

it gives an exception as

Exception in thread "Thread-6" java.security.AccessControlException: access deni

ed (java.lang.RuntimePermission modifyThread)

at java.security.AccessControlContext.checkPermission(AccessControlConte

xt.java:264)

at java.security.AccessController.checkPermission(AccessController.java:

427)

at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)

at sun.applet.AppletSecurity.checkAccess(AppletSecurity.java:138)

at java.lang.Thread.checkAccess(Thread.java:1218)

at java.lang.Thread.setName(Thread.java:1001)

at com.sun.corba.se.impl.transport.SelectorImpl.run(SelectorImpl.java:23

9)

while i set the policy

grant {

permission java.lang.RuntimePermission "modifyThreadGroup";

permission java.lang.RuntimePermission "modifyThread";

};

in java.policy.I dont know why this exception is coming.If any budy know about that then plz help me out from this problem....

Message was edited by:

tonitin.gupta

[3791 byte] By [tonitin.guptaa] at [2007-9-25]
# 1
What does your java.policy file look like?
c2gilla at 2007-7-14 > top of java,Core,Core APIs...