0 Replies Latest reply: Oct 5, 2011 4:22 AM by 892543 RSS

    Please, help in RMI UnmarshalException: nested exception is: EOFException

    892543
      Good day,
      I have a problem in sample program, similar like an Oracle oriinal in "Getting Started Usin Java RMI", identically on server and client sides. It correctly works in NetBeans IDE, but never alone, as JAR archive or java class, if I used java -jar or java -classpath command-line form. Fragment of the server code includes final check on correct read from remote object, it corrrectly works within NetBeans but cause UnmarshalException in same server side in independent launch form (WeatherBean - sample object, contains points to information about city name, weather description, temperathure an small "weather" icon, WeatherService - interface with one getWeatherInformation() function):
                     String serverObjectName = "WeatherService";
      
                     final int remotePort = 1099;
                     final String remoteHost = "localhost";
      
                     Registry registry = LocateRegistry.getRegistry(remoteHost);
      
                     WeatherService remoteObject = (WeatherService) 
                             UnicastRemoteObject.exportObject(service, 0); 
                     
                     registry.rebind(serverObjectName, remoteObject);
                     
                     //control export output 
                     java.util.List<WeatherBean> list = 
                             service.getWeatherInformation();
                     for (int i = 0; i < list.size(); i++) {
      
                         WeatherBean wb = list.get(i);
                         service.addTextWeatherString(wb.getCityName() + " " + 
                                 wb.getDescription() + " " + wb.getTemperature());
                     }
      
      
                     //back read exported object (cause error)
                     String[] regArr = registry.list();
      
                     java.util.List<String> regList = Arrays.asList(regArr);
      
                     if (regList.contains(serverObjectName)) {
      
                          Remote remote = registry.lookup(serverObjectName);
      
                          if (Proxy.isProxyClass(remote.getClass())) {
      
                              Proxy proxy = (Proxy) remote;
      
                              InvocationHandler invocationHandler = 
                                      Proxy.getInvocationHandler(proxy);
      
                              WeatherService weatherService = (WeatherService) 
                                      Proxy.newProxyInstance(
                                      WeatherService.class.getClassLoader(),
                                      new Class[] { WeatherService.class },
                                                    invocationHandler);
      
                              list = weatherService.getWeatherInformation();
      
                              for (int i = 0; i < list.size(); i++) {
      
                              WeatherBean wb = list.get(i);
                              service.addTextWeatherString(wb.getCityName() + " " + 
                                      wb.getDescription() + " " + wb.getTemperature());
                              }     
                          }    
                     }
      Starts with form java -jar WeatherServiceProj.jar (my project name) cause this error:
      java.rmi.UnmarshalException: error unmarshalling return; nested exception is: 
           java.io.EOFException
           at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:173)
           at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:178)
           at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:132)
           at $Proxy0.getWeatherInformation(Unknown Source)
           at deitel.rmi.weather.server.WeatherServiceImpl.main(WeatherServiceImpl.java:381)
      Caused by: java.io.EOFException
           at java.io.DataInputStream.readInt(DataInputStream.java:375)
           at java.io.ObjectInputStream$BlockDataInputStream.readInt(ObjectInputStream.java:2775)
           at java.io.ObjectInputStream.readInt(ObjectInputStream.java:949)
           at javax.swing.ImageIcon.readObject(ImageIcon.java:441)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:597)
           at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
           at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1848)
           at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
           at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
           at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946)
           at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1870)
           at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
           at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
           at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
           at java.util.ArrayList.readObject(ArrayList.java:593)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:597)
           at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
           at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1848)
           at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
           at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
           at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
           at sun.rmi.server.UnicastRef.unmarshalValue(UnicastRef.java:306)
           at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:155)
           ... 4 more
      I try to use many forms of java -Dxxxx keys, such as -Djava.rmi.server.codebase or -Djava.rmi.security.policy, but it does not help. Maybe i don't know something else? Key or sustem property, e. g.?

      Great thanks for some little help,
      Jaroslav

      Edited by: EJP on 5/10/2011 20:21: added {noformat}
      {noformat} tags: please use them.