JAVA RMI - Can't create server, because casting to it's interface doesn't work?
Hi
well I have a method in my client, where I am trying to create the server instance using the my inteface RemInterface which is the extension of Remote interface. The interface RemInterface is in the same package. But it just doesn't cast. :S it offers me to import <currentpackagename>.RemInterface But it's not necessary to import it since it's there automatically cause it's in the same package and also this works fine RemInterface myServer = null;
So what could be the real problem of this?
Here it is:
Code:
private void showGUI() {
//Create and set up the window.
JFrame window = new JFrame("Shared Whiteboard Client");
window.setPreferredSize(new Dimension(450, 300));
window.setResizable(false);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MainWindow crazy = new MainWindow();
crazy.addComponents(window.getContentPane());
// Java RMI part
String url = "//127.0.0.1/WhiteboardServer";
RemInterface myServer = null;
// Here is my problem:
myServer = new (RemInterface)Naming.lookup(url);
//Display the window.
window.pack();
window.setLocationRelativeTo(null);
window.setVisible(true);
}
If I try to compile, I get the error, which is exactly that line I've been talking about - myServer = new (RemInterface)Naming.lookup(url);
Code:
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - Erroneous ctor sym type: <any>
at whiteboardclientrmi.MainWindow.showGUI(MainWindow.java:51)
at whiteboardclientrmi.MainWindow.access$400(MainWindow.java:25)
at whiteboardclientrmi.MainWindow$5.run(MainWindow.java:154)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:646)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:607)
at java.awt.EventQueue$1.run(EventQueue.java:605)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:616)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
BUILD SUCCESSFUL (total time: 5 seconds)
Re: JAVA RMI - Can't create server, because casting to it's interface doesn't work?
Quote:
Uncompilable source code
What happens when you try to compile the source using the javac command?
Try separating that compound statement into simple, single statements and printing out the results of each step.
Re: JAVA RMI - Can't create server, because casting to it's interface doesn't work?
Code:
myServer = new (RemInterface)Naming.lookup(url);
Why are you calling new?
Re: JAVA RMI - Can't create server, because casting to it's interface doesn't work?
;D Thanks indeed you were right, it solved the problem.
But still I now have a different problem, it says:
Code:
Exception in thread "AWT-EventQueue-0" java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1034)
at java.net.Socket.connect(Socket.java:524)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:189)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:595)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:322)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:84)
at whiteboardclientrmi.MainWindow.showGUI(MainWindow.java:51)
at whiteboardclientrmi.MainWindow.access$400(MainWindow.java:22)
at whiteboardclientrmi.MainWindow$5.run(MainWindow.java:163)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:646)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:607)
at java.awt.EventQueue$1.run(EventQueue.java:605)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:616)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
And the client method currently looks like this:
Code:
private void showGUI() {
//Create and set up the window.
JFrame window = new JFrame("Shared Whiteboard Client");
window.setPreferredSize(new Dimension(450, 300));
window.setResizable(false);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MainWindow crazy = new MainWindow();
crazy.addComponents(window.getContentPane());
// Java RMI part
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
String url = "//127.0.0.1/WhiteboardServer";
RemInterface myServer = null;
try {
myServer = (RemInterface)Naming.lookup(url);
} catch (NotBoundException ex) {
Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
} catch (MalformedURLException ex) {
Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
} catch (RemoteException ex) {
Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
}
//Display the window.
window.pack();
window.setLocationRelativeTo(null);
window.setVisible(true);
}
Re: JAVA RMI - Can't create server, because casting to it's interface doesn't work?
Quote:
java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
Now you need to give your code permission. How are you executing the code that gets this exception?
Re: JAVA RMI - Can't create server, because casting to it's interface doesn't work?
Quote:
Originally Posted by
Norm
Now you need to give your code permission. How are you executing the code that gets this exception?
How can I do that?
I'm executing everything using Netbeans...
Re: JAVA RMI - Can't create server, because casting to it's interface doesn't work?
Sorry, I don't know anything about how to use your IDE.
Re: JAVA RMI - Can't create server, because casting to it's interface doesn't work?
Quote:
Originally Posted by
Norm
Sorry, I don't know anything about how to use your IDE.
Can you tell me how it can be compiled and run and security enabled in command line maybe? I'm using linux ubuntu 11.10 64 bit
Re: JAVA RMI - Can't create server, because casting to it's interface doesn't work?
Re: JAVA RMI - Can't create server, because casting to it's interface doesn't work?
Alright, thanks for your help. ;)