Remote call a webcam in Java - java

So I'm fiddling about with webcam usage in Java. I have tried using this set of libraries found here: https://github.com/sarxos/webcam-capture
All the examples seem to work and I can call webcam opening from other classes as well. However, my current setup I'm using includes a webapp hosted on a Tomcat server in Eclipse EE. When a button is pressed it sends a message to the server and does the according command based on the message.
The problem is that when a message is send to open the camera I get this error:
java.lang.RuntimeException: com/github/sarxos/webcam/WebcamPanel
at org.apache.tomcat.websocket.pojo.PojoMessageHandlerBase.handlePojoMethodException(PojoMessageHandlerBase.java:119)
at org.apache.tomcat.websocket.pojo.PojoMessageHandlerWholeBase.onMessage(PojoMessageHandlerWholeBase.java:82)
at org.apache.tomcat.websocket.WsFrameBase.sendMessageText(WsFrameBase.java:393)
at org.apache.tomcat.websocket.WsFrameBase.processDataText(WsFrameBase.java:494)
at org.apache.tomcat.websocket.WsFrameBase.processData(WsFrameBase.java:289)
at org.apache.tomcat.websocket.WsFrameBase.processInputBuffer(WsFrameBase.java:130)
at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:60)
at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler$WsReadListener.onDataAvailable(WsHttpUpgradeHandler.java:203)
at org.apache.coyote.http11.upgrade.AbstractServletInputStream.onDataAvailable(AbstractServletInputStream.java:198)
at org.apache.coyote.http11.upgrade.AbstractProcessor.upgradeDispatch(AbstractProcessor.java:96)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:654)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1558)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoClassDefFoundError: com/github/sarxos/webcam/WebcamPanel
at WebcamPanelExample.handleMessage(WebcamPanelExample.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.apache.tomcat.websocket.pojo.PojoMessageHandlerWholeBase.onMessage(PojoMessageHandlerWholeBase.java:80)
... 16 more
Caused by: java.lang.ClassNotFoundException: com.github.sarxos.webcam.WebcamPanel
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1305)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1157)
... 22 more
If I create a main method to open the camera it seems to work fine, but when I want to call it from from the message handler it doesn't. Is there something obvious I am missing?
Thanks in advance!
Doesn't work:
#OnMessage
public void handleMessage(String message) throws IOException {
if(message.equals("Camera"))
{
CameraTest.OpenCam1(); // Method that opens camera
}
}
Works:
public static void main(String[] args) {
CameraTest.OpenCam();
}

Related

Problems with RMI Server; rmiregistry on windows

So we haft to use a RMI Server and Client for some exercice in class. Our professor don't want us to use `LocateRegirstry.createRegistry()`, instead we shall start the rmiregistry from within either intellij external tools, or the cmd. I tried several things, nothing seems to work. I opened cmd both as Admin and normal User, started rmiregistry from within the "out" dictionary of the project (professor said it has to be started in the same dictionary where the byte code lies). Made a link to the original rmiregistry and placed it into the "out" dictionary,startet it from intellij terminal, external tools etc. but i cant get it to work.
at the moment i get this Error:
DateServerImpl: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: RMI.DateServer
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: RMI.DateServer
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:391)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:691)
at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at java.base/java.lang.Thread.run(Thread.java:832)
at java.rmi/sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:303)
at java.rmi/sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:279)
at java.rmi/sun.rmi.server.UnicastRef.invoke(UnicastRef.java:380)
at java.rmi/sun.rmi.registry.RegistryImpl_Stub.rebind(RegistryImpl_Stub.java:158)
at java.rmi/java.rmi.Naming.rebind(Naming.java:177)
at RMI.DateServerImpl.main(DateServerImpl.java:20)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: RMI.DateServer
at java.rmi/sun.rmi.registry.RegistryImpl_Skel.dispatch(RegistryImpl_Skel.java:157)
at java.rmi/sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:468)
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:298)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:691)
at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.ClassNotFoundException: RMI.DateServer
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:435)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
at java.rmi/sun.rmi.server.LoaderHandler$Loader.loadClass(LoaderHandler.java:1207)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:468)
at java.rmi/sun.rmi.server.LoaderHandler.loadClassForName(LoaderHandler.java:1221)
at java.rmi/sun.rmi.server.LoaderHandler.loadProxyInterfaces(LoaderHandler.java:731)
at java.rmi/sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:674)
at java.rmi/sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:611)
at java.rmi/java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.java:646)
at java.rmi/java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:311)
at java.rmi/sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStream.java:254)
at java.base/java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1950)
at java.base/java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1892)
at java.base/java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2202)
at java.base/java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1712)
at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:519)
at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:477)
at java.rmi/sun.rmi.registry.RegistryImpl_Skel.dispatch(RegistryImpl_Skel.java:154)
... 14 more
I couldn't find the solution on google ( which leads me here anyway most of the time, to similar problems, but couldn't figure anything out with those posts)
here is the code i use:
Server Code
package RMI;
import java.rmi.*;
import java.rmi.server.*;
import java.util.Date;
public class DateServerImpl extends UnicastRemoteObject implements DateServer {
public DateServerImpl () throws RemoteException {
}
public Date getDate () throws RemoteException {
System.out.println("Invocation of getDate()");
return new Date ();
}
public static void main (String[] args) {
try {
DateServerImpl dateServer = new DateServerImpl ();
Naming.rebind ("DateServer", dateServer);
System.out.println("The server is up");
} catch (Exception e) {
System.out.println("DateServerImpl: " + e.getMessage());
e.printStackTrace();
}
}
}
Interface Code
package RMI;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.Date;
public interface DateServer extends Remote {
public Date getDate () throws RemoteException;
}
So I hope anybody can help me here. What am I doing wrong?
I hope this is enough information, first time posting here =D
Thank you!
It's funny that this problem has been around for 20+ years. After opening CMD, you need to set the environment variable CLASSPATH and include every JAR/directory needed to properly find your server classes, and then start rmiregistry.
So I just found a workaround. I used the javac command to compile it over cmd, started the rmiregistry and than the server... and it worked. So I assume it is a Problem of intellij, because .class and .java are in different dictionary and therefore the exception "class not found" makes sense. Now i just need to find a way to reorganize intellij... Thanks for the help so far =D
Edit: Intellij on Windows needs the "out" dictionary to be mirrored(On Linux it seems no problem at all, as long as you started rmiregistry in the same dictionary as your byte code aka .class files are). So Go to
File->Project Structure->Modules->Paths
choose Use module compile output path, and just use out as output
after that, got to intellij terminal, change to the out dictionary, start rmiregistry and than start the server.
That's it, works for me =D.

Attach an agent remotely using Bytebuddy

I am trying to attach an agent for a process using bytebuddy .I found that we can use ByteBuddyAgent.attach(file,"18467"); for this. But when i am trying to do this following errors occurring.
This is agent i used
File file = (new File("Agent.jar"));
Error
java.lang.IllegalStateException: Error during attachment using: net.bytebuddy.agent.ByteBuddyAgent$AttachmentProvider$Compound#e26db604
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:378)
at net.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:227)
at net.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:202)
at net.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:189)
at common.netty.echo.EchoHttpServer.main(EchoHttpServer.java:95)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.bytebuddy.agent.Attacher.install(Attacher.java:77)
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:373)
... 4 more
Caused by: com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded
at sun.tools.attach.LinuxVirtualMachine.<init>(LinuxVirtualMachine.java:106)
at sun.tools.attach.LinuxAttachProvider.attachVirtualMachine(LinuxAttachProvider.java:63)
at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:208)
... 10 more
Any idea for this ? and When i try to use this attachment from another agent as follows
public class Agent {
public static void premain(String args, Instrumentation instrumentation) {
System.out.println("Premain");
File file ;
try {
file = (new File("Agent.jar"));
ByteBuddyAgent.attach(file,"18467");
}
catch (Exception e)
{
e.printStackTrace();
}
}
I am getting this error
Error
java.lang.IllegalStateException: Error during attachment using: net.bytebuddy.agent.ByteBuddyAgent$AttachmentProvider$Compound#423f0955
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:378)
at net.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:227)
at net.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:202)
at net.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:189)
at common.netty.echo.Agent.premain(Agent.java:111)
at common.netty.echo.EchoHttpServer.<clinit>(EchoHttpServer.java:56)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.bytebuddy.agent.Attacher.install(Attacher.java:77)
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:373)
... 5 more
Caused by: java.lang.UnsatisfiedLinkError: Native Library /usr/lib/jvm/java-8-oracle/jre/lib/amd64/libattach.so already loaded in another classloader
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1907)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1845)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at sun.tools.attach.LinuxVirtualMachine.<clinit>(LinuxVirtualMachine.java:342)
at sun.tools.attach.LinuxAttachProvider.attachVirtualMachine(LinuxAttachProvider.java:63)
at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:208)
... 11 more
Any suggestion on this!!
As for the first error message: does the target VM run the attachment listener? You can try to force starting the thread by setting -XX:+StartAttachListener which should be set by default. What JVM version are you running?
The other error message indicates that the attachment library was already loaded by another class loader. See this answer for further details: java.lang.UnsatisfiedLinkError: Native Library XXX.so already loaded in another classloader

Not able to create custom Predicate while using fast aggregations in Hazelcast

I am creating a custom Predicate. It takes an integer and compares it with the value of map.
public class LocationPredicate implements Predicate<Key, Portable> {
private int rssi;
public LocationPredicate() {
}
public LocationPredicate(int rssi) {
this.rssi = rssi;
}
#Override
public boolean apply(Entry<Key, Aortable> arg0) {
return false;
//int val = arg0.getValue().getData().getLocation().getRssiVal();
//return (rssi == val ) ;
}
}
When I run the program, I am getting the following error:
Exception in thread "main" com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.ClassNotFoundException: com.snmpapp.main.LocationPredicate
at com.hazelcast.internal.serialization.impl.JavaDefaultSerializers$JavaSerializer.read(JavaDefaultSerializers.java:224)
at com.hazelcast.internal.serialization.impl.StreamSerializerAdapter.read(StreamSerializerAdapter.java:48)
at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toObject(AbstractSerializationService.java:184)
at com.hazelcast.client.impl.protocol.task.map.MapAggregateWithPredicateMessageTask.getPredicate(MapAggregateWithPredicateMessageTask.java:45)
at com.hazelcast.client.impl.protocol.task.map.AbstractMapQueryMessageTask.call(AbstractMapQueryMessageTask.java:87)
at com.hazelcast.client.impl.protocol.task.AbstractCallableMessageTask.processMessage(AbstractCallableMessageTask.java:35)
at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.initializeAndProcessMessage(AbstractMessageTask.java:123)
at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.run(AbstractMessageTask.java:103)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at com.hazelcast.util.executor.HazelcastManagedThread.executeRun(HazelcastManagedThread.java:64)
at com.hazelcast.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:80)
at ------ submitted from ------.(Unknown Source)
at com.hazelcast.client.spi.impl.ClientInvocationFuture.resolveAndThrowIfException(ClientInvocationFuture.java:95)
at com.hazelcast.client.spi.impl.ClientInvocationFuture.resolveAndThrowIfException(ClientInvocationFuture.java:32)
at com.hazelcast.spi.impl.AbstractInvocationFuture.get(AbstractInvocationFuture.java:155)
at com.hazelcast.client.spi.ClientProxy.invoke(ClientProxy.java:172)
at com.hazelcast.client.proxy.ClientMapProxy.aggregate(ClientMapProxy.java:1356)
at com.snmpapp.main.Main.main(Main.java:370)
Caused by: java.lang.ClassNotFoundException: com.aruba.acp.snmpapp.main.LocationPredicate
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.hazelcast.nio.ClassLoaderUtil.tryLoadClass(ClassLoaderUtil.java:149)
at com.hazelcast.nio.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:123)
at com.hazelcast.nio.IOUtil$ClassLoaderAwareObjectInputStream.resolveClass(IOUtil.java:522)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1613)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1518)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1774)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
at com.hazelcast.internal.serialization.impl.JavaDefaultSerializers$JavaSerializer.read(JavaDefaultSerializers.java:219)
at com.hazelcast.internal.serialization.impl.StreamSerializerAdapter.read(StreamSerializerAdapter.java:48)
at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toObject(AbstractSerializationService.java:184)
at com.hazelcast.client.impl.protocol.task.map.MapAggregateWithPredicateMessageTask.getPredicate(MapAggregateWithPredicateMessageTask.java:45)
at com.hazelcast.client.impl.protocol.task.map.AbstractMapQueryMessageTask.call(AbstractMapQueryMessageTask.java:87)
at com.hazelcast.client.impl.protocol.task.AbstractCallableMessageTask.processMessage(AbstractCallableMessageTask.java:35)
at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.initializeAndProcessMessage(AbstractMessageTask.java:123)
at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.run(AbstractMessageTask.java:103)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at com.hazelcast.util.executor.HazelcastManagedThread.executeRun(HazelcastManagedThread.java:64)
at com.hazelcast.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:80)
I am little bit confused. Do I need to create the Predicate on the server? I am running as Hcast client and the client is creating the predicate.
As far as I know, when you create the predicate, it is sent as a serialized object to the hazelcast server.
Also, I tried to implement Predicate as Serializable, but it didnt help.
Thanks
I am not experienced with Hazelcast but as far as I know during serialisation and deserialisation you can transfer state (in this case the member variable) but not the behaviour (your actual implementation of apply method). Somehow (I am not experienced with this technology) you should provide your class to the Hazelcast's class loader (maybe copying to the classpath). Good luck!
The class needs to be on the classpath of all nodes.

java RMI - unexpected error

I have been working on to create a sample RMI project for a while and having difficulty with the following error for a few hours now. If anyone of you can point me towards my mistake, I will be grateful. I will be posting the trimmed code with the error.
Thanks in advance for your time.
PrimeFinder.java
import //irrelevant
public interface PrimeFinder extends Remote
{
public List<Integer> findPrime (int startPoint, int endPoint )
throws RemoteException;
}
PrimeFinderService.java
import //irrelevant
public class PrimeFinderService extends UnicastRemoteObject
implements PrimeFinder
{
public PrimeFinderService () throws RemoteException
{
super();
}
public List<Integer> findPrime(int startPoint, int endPoint)
throws RemoteException {
// Irrelevant
}
public static void main ( String args[] ) throws Exception
{
if (System.getSecurityManager() == null)
System.setSecurityManager ( new RMISecurityManager() );
PrimeFinderService svr = new PrimeFinderService();
Naming.bind ("PowerService", svr);
System.out.println ("Service bound....");
}
}
.policy
grant {
permission java.security.AllPermission; }
The error that is killing me :
Exception in thread "main" java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: access to class loader denied
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:419)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
at sun.rmi.transport.Transport$1.run(Transport.java:177)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:273)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:251)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:377)
at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
at java.rmi.Naming.bind(Naming.java:128)
at q7.PrimeFinderService.main(PrimeFinderService.java:69)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: access to class loader denied
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:409)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
at sun.rmi.transport.Transport$1.run(Transport.java:177)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)
Caused by: java.lang.ClassNotFoundException: access to class loader denied
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:445)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:182)
at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:637)
at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:264)
at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:214)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1592)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1513)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1749)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1346)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:368)
... 12 more
Caused by: java.security.AccessControlException: access denied (java.io.FilePermission /home/cem/workspace/OBSS_q7/bin/q7/- read)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:393)
at java.security.AccessController.checkPermission(AccessController.java:553)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at sun.rmi.server.LoaderHandler$Loader.checkPermissions(LoaderHandler.java:1173)
at sun.rmi.server.LoaderHandler$Loader.access$000(LoaderHandler.java:1127)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:409)
... 21 more
Edit 1:
The error line that I'm trying to overcome is:
Caused by: java.security.AccessControlException: access denied (java.io.FilePermission /home/cem/workspace/OBSS_q7/bin/q7/- read)
I have tried at least 10 different approaches in my .policy file - all of which ended up with the same problem. I have tried anything in the tutorials I have found and it's I believe safe to say that the problem doesn't lie in .policy file.
I have also meddled with the codebase, giving the codebase wrong ends up with different errors so that can't be it either.
Still looking for ideas ^^
Cheers !
Get rid of the SecurityManager, or else write yourself a security policy file that grants that permission.
The problem was regarding linux file system permissions, altering permissions fixes the problem.
If someone stumbles upon the issue on Windows, then two words... Windows Defender. It probably just deleted your project files.
So just rebuild your project. No not "build", just entirely "rebuild".
Windows Defender might delete your project' executables if they went into high CPU usage. So I also always suggest putting your project' directory as an exception.

Problems setting up a simple RMI server

I am having a problem setting up a simple RMI server, and was wondering if someone can point me in the right direction.
I have a simple class, Server, that should export an simple interface. Currently when I try and run the server class, I get the following exception:
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: prototype.ISimpleService
I have already made sure that the rmi registry is running, by running the "start rmiregistry" command, and I am running the service with the following argument
-Djava.rmi.server.codebase=file:C:/Users/John/Documents/NetBeansProjects/Prototype/build/classes
The path in the argument above points to the top level folder of my class hierarchy, so:
/classes
/prototype
->ISimpleService.class
->SimpleServiceImpl.class
->IServer.class
Here is my server code:
public class Server
{
private static ISimpleService service;
public static void main(String[] args)
{
service = new SimpleServiceImpl();
try
{
ISimpleService stub = (ISimpleService) UnicastRemoteObject.exportObject(service, 0);
Registry registry = LocateRegistry.getRegistry();
registry.rebind("SimpleService", stub);
System.out.println("Simple Service bound");
}
catch (Exception ex)
{
System.out.println("Exception binding the simple service");
ex.printStackTrace();
}
}
}
I have looked at the Java RMI trail, and adapted my simple example to follow that, although I am not using security/permissions that I shouldn't need as I have gotten an RMI example working before without that stuff...
So I believe I have to missing something simple(no pun intended), to make this work, but I cant see anything at the moment.
Do anyone have an ideas?
Here is the full stack trace:
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: prototype.ISimpleService
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:396)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:250)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask (ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer (StreamRemoteCall.java:255)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:359)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at prototype.Server.main(Server.java:35)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: prototype.ISimpleService
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:386)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:250)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask (ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.ClassNotFoundException: prototype.ISimpleService
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at sun.rmi.server.LoaderHandler.loadProxyInterfaces(LoaderHandler.java:711)
at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:655)
at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:592)
at java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.java:628)
at java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:294)
at sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStream.java:238)
at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1530)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1492)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1731)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
... 12 more
I have solved this issue... Took me alittle longer than I expected though :(
Turns out when you use a codebase argument like I had done, you should place a trailing "/" at the end, if you are pointing to a directory. Once I added that in, my server successfully binds.
For a resource on this p see http://download.oracle.com/javase/1.4.2/docs/guide/rmi/codebase.html#section6
It seems prototype.ISimpleService is not in your classpath.
Try:
java -cp=C:/Users/John/Documents/NetBeansProjects/Prototype/build/classes;C:/Users/John/Documents/NetBeansProjects/Server/build/classes Server

Categories