user1221292
user1221292

Reputation: 127

File Transfer RMI

I am just following a tutorial on how to send files using RMI.

Tutorial: Link

I encounter an error when i try to run my server. The only change i have made different from the tutorial is i have changed my port to 1097 instead of the default 1099.

How can i resolve this error?

This is the error i receive:

C:\Program Files\Java\jdk1.7.0_09\bin\FT_RMI>java -Djava.security.policy=policy.
txt FileServer
FileServer: access denied ("java.net.SocketPermission" "127.0.0.1:1097" "connect
,resolve")
java.security.AccessControlException: access denied ("java.net.SocketPermission"
 "127.0.0.1:1097" "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.checkConnect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at java.net.Socket.<init>(Unknown Source)
        at java.net.Socket.<init>(Unknown Source)
        at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown S
ource)
        at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown S
ource)
        at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
        at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
        at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
        at sun.rmi.server.UnicastRef.newCall(Unknown Source)
        at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
        at java.rmi.Naming.rebind(Unknown Source)
        at FileServer.main(FileServer.java:11)

Line 11 is Naming.rebind().

Here:

FileInterface fi = new FileImpl("FileServer");
     Naming.rebind("//127.0.0.1:1097/FileServer", fi);

I have tried changing the address to localhost, but the same error occurs.

SOLUTION

Point to the specific java policy file, either in JRE folder or a specific policy file.

java -Djava.security.policy="C:\\FT_RMI\\java.policy" FileServer

Upvotes: 0

Views: 3728

Answers (2)

user207421
user207421

Reputation: 311002

You are running your server under a SecurityManager. Unless you are using the RMI codebase feature or you have another specific security requirement that dictates its use in the server, just remove it.

Upvotes: 0

muruga
muruga

Reputation: 1073

You have to allow the socket connect on your security properties under JRE. You can see this under jre/lib/security/java.policy

Upvotes: 3

Related Questions