I'm trying to connect a client and remote server through RMI and I get this error message:
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.net.MalformedURLException: unknown protocol: c
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Unknown Source)
at RmiClient.getMessage(RmiClient.java:11)
at RmiClient.main(RmiClient.java:26)
Caused by: java.net.MalformedURLException: unknown protocol: c
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at sun.rmi.server.LoaderHandler.pathToURLs(Unknown Source)
at sun.rmi.server.LoaderHandler.getDefaultCodebaseURLs(Unknown Source)
at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
at java.rmi.server.RMIClassLoader$2.loadClass(Unknown Source)
at java.rmi.server.RMIClassLoader.loadClass(Unknown Source)
at sun.rmi.server.MarshalInputStream.resolveClass(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
... 4 more
The following may be the cause of the problem:
The server has this line:
Naming.rebind("rmi://172.31.24.66:1099/RmiServer", obj);
which refers to the private IP address of an EC2 instance. The client on the other hand has this line - which is line 11 from above:
RmiServerIntf obj = (RmiServerIntf)Naming.lookup("rmi://54.229.66.114:1099/RmiServer");
which is the public IP of that instance. Also, on the client side I set the codebase property as:
System.setProperty("java.rmi.server.codebase", "C:\\Users\\spacitron\\Projects\\RMIClient\\bin");
If I try to add the same line on the server I get a "permission denied" error.
A codebase is a list of URLs. What you have specified is a file name, not a URL.
It is also a rather useless filename, unless the client is on the same host as the server, in which case it is difficult to see why you're using the codebase feature at all. Even if you have a shared drive it is just as easy to specify directories in the client's CLASSPATH as it is to use java.rmi.server.codebase. A codebase URL needs to be usable by the recipient. That's why they are almost always HTTP URLs, or maybe FTP URLs.
try down grading your jdk7 below update 21/jdk6 below update 45.
compile and test again of this work problem is java.rmi.server.useCodebaseOnly system property
please check below link for solution for both version of jdk's
http://docs.oracle.com/javase/7/docs/technotes/guides/rmi/relnotes.html
Related
Say I have class SuperNode and an interface Node:
SuperNode implements Node
I have a RMI-Implementation server side and I'm trying to just send the Node over from a method without the user having the source file for SuperNode but they do have the interface Node.
public Node RMIImplServer.getNode();
When I do this I get this error:
java.rmi.UnmarshalException: error unmarshalling return; nested
exception is: java.lang.ClassNotFoundException:
SEHT.somepackage.SuperNode (no security manager: RMI class loader
disabled) at sun.rmi.server.UnicastRef.invoke(Unknown Source) at
java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown
Source) at
java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
at com.sun.proxy.$Proxy0.getDataNodes(Unknown Source) Caused by:
java.lang.ClassNotFoundException: SEHT.somepackage.SuperNode (no
security manager: RMI class loader disabled) at
sun.rmi.server.LoaderHandler.loadClass(Unknown Source) at
sun.rmi.server.LoaderHandler.loadClass(Unknown Source) at
java.rmi.server.RMIClassLoader$2.loadClass(Unknown Source) at
java.rmi.server.RMIClassLoader.loadClass(Unknown Source) at
sun.rmi.server.MarshalInputStream.resolveClass(Unknown Source) at
java.io.ObjectInputStream.readNonProxyDesc(Unknown Source) at
java.io.ObjectInputStream.readClassDesc(Unknown Source) at
java.io.ObjectInputStream.readOrdinaryObject(Unknown Source) at
java.io.ObjectInputStream.readObject0(Unknown Source) at
java.io.ObjectInputStream.readObject(Unknown Source) at
java.util.ArrayList.readObject(Unknown Source) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at
java.lang.reflect.Method.invoke(Unknown Source) at
java.io.ObjectStreamClass.invokeReadObject(Unknown Source) at
java.io.ObjectInputStream.readSerialData(Unknown Source) at
java.io.ObjectInputStream.readOrdinaryObject(Unknown Source) at
java.io.ObjectInputStream.readObject0(Unknown Source) at
java.io.ObjectInputStream.readObject(Unknown Source) at
sun.rmi.server.UnicastRef.unmarshalValue(Unknown Source) ... 5 more
Is what I'm trying to do possible, if so what am I doing wrong, any help would be appreciated.
Finally figured it out...the jar file wasn't including the right files due to a stupid default that I didn't check. Thank you so much EJP for your help.
The client doesn't need any source files. It does however need the object files (.class) files for all types returned by remote methods, available on its CLASSPATH, unless:
... if you don't want to deploy SuperNode.class or whatever it is at the client, you can use the codebase feature. It's complicated.
You will need to install a security manager at the client.
You will need to define the system property java.rmi.server.codebase at the server JVM.
You will need to set it to one or more URLs that are intelligible to the client and that name JAR file(s) containing classes to be loaded dynamically. Typically a codebase item is an HTTP URL. Note that a codebase item referring to the file system local to the server cannot work, as it isn't intelligible to the client.
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
You have to allow the socket connect on your security properties under JRE. You can see this under jre/lib/security/java.policy
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.
I am unable to start the installed App on my WAS instance. I believe the root cause is an UnsatisfiedLinkError which is shown as follows:
Caused by: java.lang.UnsatisfiedLinkError: no ocijdbc10 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682)
at java.lang.Runtime.loadLibrary0(Runtime.java:822)
at java.lang.System.loadLibrary(System.java:993)
at oracle.jdbc.driver.T2CConnection$1.run(T2CConnection.java:3147)
at java.security.AccessController.doPrivileged(Native Method)
at oracle.jdbc.driver.T2CConnection.loadNativeLibrary(T2CConnection.java:3143)
at oracle.jdbc.driver.T2CConnection.logon(T2CConnection.java:221)
at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:441)
at oracle.jdbc.driver.T2CConnection.(T2CConnection.java:132)
at oracle.jdbc.driver.T2CDriverExtension.getConnection(T2CDriverExtension.java:78)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
at oracle.jdbc.pool.OracleDataSource.getPhysicalConnection(OracleDataSource.java:297)
at oracle.jdbc.xa.client.OracleXADataSource.getPooledConnection(OracleXADataSource.java:515)
at oracle.jdbc.xa.client.OracleXADataSource.getXAConnection(OracleXADataSource.java:159)
at oracle.jdbc.xa.client.OracleXADataSource.getXAConnection(OracleXADataSource.java:133)
at com.ibm.ws.rsadapter.spi.InternalGenericDataStoreHelper$1.run(InternalGenericDataStoreHelper.java:935)
at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118)
at com.ibm.ws.rsadapter.spi.InternalGenericDataStoreHelper.getPooledConnection(InternalGenericDataStoreHelper.java:972)
at com.ibm.ws.rsadapter.spi.WSRdbDataSource.getPooledConnection(WSRdbDataSource.java:1625)
at com.ibm.ws.rsadapter.spi.WSManagedConnectionFactoryImpl.createManagedConnection(WSManagedConnectionFactoryImpl.java:1220)
at com.ibm.ejs.j2c.FreePool.createManagedConnectionWithMCWrapper(FreePool.java:1988)
at com.ibm.ejs.j2c.FreePool.createOrWaitForConnection(FreePool.java:1660)
at com.ibm.ejs.j2c.PoolManager.reserve(PoolManager.java:2341)
at com.ibm.ejs.j2c.ConnectionManager.allocateMCWrapper(ConnectionManager.java:932)
at com.ibm.ejs.j2c.ConnectionManager.allocateConnection(ConnectionManager.java:608)
at com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource.getConnection(WSJdbcDataSource.java:449)
at com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource.getConnection(WSJdbcDataSource.java:418)
at org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl.newConnectionFromDataSource(Unknown Source)
at org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl.lookupConnection(Unknown Source)
at org.apache.ojb.broker.accesslayer.ConnectionFactoryManagedImpl.lookupConnection(Unknown Source)
at org.apache.ojb.broker.accesslayer.ConnectionManagerImpl.getConnection(Unknown Source)
at org.apache.ojb.broker.accesslayer.StatementManager.getPreparedStatement(Unknown Source)
at org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeQuery(Unknown Source)
at org.apache.ojb.broker.accesslayer.RsQueryObject.performQuery(Unknown Source)
at org.apache.ojb.broker.accesslayer.RsIterator.(Unknown Source)
at org.apache.ojb.broker.core.RsIteratorFactoryImpl.createRsIterator(Unknown Source)
at org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Unknown Source)
at org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorFromQuery(Unknown Source)
at org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unknown Source)
at org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unknown Source)
at org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unknown Source)
at org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Unknown Source)
at org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQuery(Unknown Source)
at org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQuery(Unknown Source)
at com.ascential.xmeta.persistence.orm.impl.ojb.OjbPersistentEObjectPersistenceRegistry.loadPackageCache(OjbPersistentEObjectPersistenceRegistry.java:371)
... 115 more
My LD_LIBRARY_PATH variable for the 'was' user is /opt/oracle/product/10.2.0/lib
What else should I be checking to fix this error?
Please help.
Thanks
Verify that "Java Library Path" in the trace header of SystemOut.log contains "/opt/oracle/product/10.2.0/lib". If it does not contain the path, then your LD_LIBRARY_PATH setting is not taking effect (perhaps the variable isn't exported, or perhaps you're executing startServer as a different user).
Regardless, I would recommend setting adding "/opt/oracle/product/10.2.0/lib" to the native library path of the JDBC provider rather than trying to set it at the OS level.
Finally, double-check that the server has the proper OS permissions to access the native library.
I'm trying to implement Sun Tutorials RMI application that calculates Pi. I'm having some serious problems and I cant find the solution eventhough I've been searching the entire web and several javaskilled people.
I'm hoping you can put an end to my frustrations.
The crazy thing is that I can run the application from the cmd on my desktop computer. Trying the exact same thing with the exact same code in the exact same directories on my laptop produces the following errors. The problem occures when I try to connect the client to the server.
I don't believe that the error is due to my policyfile as I can run it on the desktop. It must be elsewhere. Have anyone tried the same and can you give me a hint as to where my problem is, please?
POLICYFILE SERVER:
grant
{
permission java.security.AllPermissions;
permission java.net.SocketPermission"*", "connect, resolve";
};
POLICYFILE CLIENT:
grant
{
permission java.security.AllPermissions;
permission java.net.SocketPermission"*", "connect, resolve";
};
______________________________________________
SERVERSIDE ERRORS:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\STUDENT>cd\
C:\>start rmiregistry
C:\>java -cp c:\java;c:\java\compute.jar -Djava.rmi.server.codebase=file:/c:/jav
a/compute.jar -Djava.rmi.server.hostname=localhost -Djava.security.policy=c:/jav
a/servertest.policy engine.ComputeEngine
ComputeEngine bound
Exception in thread "RMI TCP Connection(idle)" java.security.AccessControlExcept
ion: access denied (java.net.SocketPermission 127.0.0.1:1440 accept,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.checkAccept(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.checkAcceptPermi
ssion(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.checkAcceptPermission(Unknown Sour
ce)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Sou
rce)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Sour
ce)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source
)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
_______________________________
CLIENTSIDE ERRORS:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\STUDENT>cd\
C:\>java -cp c:\java;c:\java\compute.jar -Djava.rmi.server.codebase=file:\C:\jav
a\files\ -Djava.security.policy=c:/java/clienttest.policy client.ComputePi local
host 45
ComputePi exception:
java.rmi.UnmarshalException: Error unmarshaling return header; nested exception
is:
java.io.EOFException
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unkn
own Source)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
at $Proxy0.executeTask(Unknown Source)
at client.ComputePi.main(ComputePi.java:18)
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(Unknown Source)
... 6 more
C:\>
Thanks in advance
Perry
Your server didn't have permission to accept a connection from that client.
Ergo your policy file wasn't where you said it was, or wasn't loaded for some other reason.
Run it with -Djava.security.debug=access,failure and you will see what protection domain you were in when the security exception occurred, and what permissions it had.
java -cp c:\java;c:\java\compute.jar -Djava.rmi.server.codebase=file:/c:/java/compute.jar -Djava.rmi.server.hostname=localhost -Djava.security.policy=c:/java/servertest.policy engine.ComputeEngine
NB a file: codebase cannot work if it refers to a local filesystem, unless the client is also in the same machine, which makes RMI fairly pointless. Codebase URLs need to refer to locations that are accessible by the client. You can use shared file systems but you must provide a URL that is usable by the client. The server doesn't use its own codebase URL at all.
I tried the same and I found that Java simply ignored the policy file, no matter where I put it or what I put into it or which option I used to make the VM pick it up.
In the end, I create my own SecurityManager in the code and did everything manually.
I am running a Java web applet on one of my servers. For some reason a particular user cannot access it (an error text appears in place of the applet that reads "Error. Click for details"; it is not text I placed between the tags, i.e., his JRE is installed and appears to at the very least be installed correctly but for some reason it is not working on my applet.
I think it has something to do with his particular "flavor" of JRE - this so-called "HotSpot" version. (see this: http://www.experts-exchange.com/Programming/Languages/Java/Q_24405442.html if you have an EE account, I can't remember mine offhand). I am not too familiar with Java itself or it's varieties - I am merely the implementer of the applet in the page (I did not write it).
The applet works fine for me, and every single other user to date. Also, it should not be referring to file as listed below in his error such as "http://mywebsite.com/java/JavaVersionDisplayApplet/class.class". The file is located at "http://mywebsite.com/java/JavaVersionDisplay.class". According to the applet programmer, his error points to a file that is not even specified anywhere in his code.
The users' error reads:
Java Plug-in 1.6.0_13
Using JRE version 1.6.0_13 Java HotSpot(TM) Client VM
User home directory = C:Documents and Settingsjohn
load: class JavaVersionDisplayApplet.class not found.
java.lang.ClassNotFoundException: JavaVersionDisplayApplet.class
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: open HTTP connection failed:http://mywebsite.com/java/JavaVersionDisplayApplet/class.class
at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 7 more
Exception: java.lang.ClassNotFoundException: JavaVersionDisplayApplet.class
load: class JavaVersionDisplayApplet.class not found.
java.lang.ClassNotFoundException: JavaVersionDisplayApplet.class
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: open HTTP connection failed:http://mywebsite.com/java/JavaVersionDisplayApplet/class.class
at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 7 more
Exception: java.lang.ClassNotFoundException: JavaVersionDisplayApplet.class
I'd start by packaging the application as a jarfile instead of as a set of classfiles. It seems like JavaVersionDisplayApplet.class is being interpreted as a fully-qualified class name...that is, the JVM thinks "JavaVersionDisplayApplet" is a package name and "class" is the class name.
Can you post the contents of the APPLET tag that you're using in the HTML?
A couple of things you might want to look at:
Is he using Chrome? It seems that Chrome and Java don't play well together quite yet.
Is he using a Proxy server? The "connection failed" error may indicate that he is using a Proxy that is allowing the browser through, but not the JRE.
This is the culprit:
Caused by: java.io.IOException: open HTTP connection failed:http://mywebsite.com/java/JavaVersionDisplayApplet/class.class
The JVM is started, but it cannot connect to the server hosting the applet. Does the user connect to mywebsite.com or another name?