< previous paste - next paste>
Description of the problem:
-------------------------------
When I call fs.readFile in ClientConnection like this:
fileContent = fs.readFile(uri, callback);
it fails with the following stack trace.
When I call fs.readFile with null in stead of callback as the second argument,
it does *not* fail.
In ClientConnection.java callback is an object of type Callback.
Stack trace and code snippets from the related java source files can be seen below.
Stack trace:
-----------------
Initialized webserver8081
2006-09-26 13:47:17 [DEBUG][Callback] Callback object created.
2006-09-26 13:47:17 [INFO][WebServer] Starting webserver on port 8081...
2006-09-26 13:47:17 [INFO][WebServer] Cache style is afs2
2006-09-26 13:47:17 [INFO][WebServer] Webserver accepting connections on port 8081
2006-09-26 13:47:23 [INFO][ClientConnection(15)] Certificate from SecureClient is valid and the owner has permission: rw
2006-09-26 13:47:23 [INFO][ClientConnection(15)] Client returned correct shared secret: 0
2006-09-26 13:47:23 [INFO][ClientConnection(15)] GET /testfile
2006-09-26 13:47:23 [INFO][ClientConnection(15)] No valid cache exists. Getting the file from the file server.
Exception in thread "Thread-3" java.lang.IllegalArgumentException: argument type mismatch
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 sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
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.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
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 $Proxy2.readFile(Unknown Source)
at dk.thomasdamgaard.diku.distsys.webserver.ClientConnection.handleGetRequest(ClientConnection.java:376)
at dk.thomasdamgaard.diku.distsys.webserver.ClientConnection.run(ClientConnection.java:260)
at java.lang.Thread.run(Unknown Source)
IFileServer.java:
----------------------------
package dk.thomasdamgaard.diku.distsys.interfaces;
import java.io.IOException;
import java.rmi.Remote;
import java.rmi.RemoteException;
import dk.thomasdamgaard.diku.distsys.webserver.Callback;
/**
* @author Thomas Damgaard Nielsen <spam@thomasdamgaard.dk>
*
*/
public interface IFileServer extends Remote {
public byte[] readFile(String fileName, Callback callback)
throws RemoteException, IOException;
public void writeFile(String fileName, char[] data) throws RemoteException,
IOException;
public void deleteFile(String fileName) throws RemoteException, IOException;
public boolean fileExists(String fileName) throws RemoteException,
IOException;
public String[] listFiles() throws RemoteException, IOException;
}
From ClientConnection.java lines 370-383:
------------------------------------------
if (cacheIsInvalid) {
// The cached version is either expired or does not exist
// Get a new version from the file server
if (fs.fileExists(uri)) {
logger.info("No valid cache exists. " +
"Getting the file from the file server.");
fileContent = fs.readFile(uri, callback); // This is the line (376) that fails
CacheItem ci = new CacheItem(uri, fileContent);
cache.add(uri, ci);
} else {
logger.info("The file does not exist on the server.");
fileContent = null;
}
}
FileServer.java (the readFile method):
-----------------------------------------
public synchronized byte[] readFile(String fileName, Callback callback)
throws RemoteException, IOException {
logger.info("Reading '" + fileName + "'");
// If the client uses callback then
// put the callback in the list of clients that needs
// to be notified when the cached files changes.
if (callback != null) {
ArrayList<Callback> cl = cbList.get(fileName);
if (null != cl) {
if (!cl.contains(callback)) {
cl.add(callback);
}
} else {
cl = new ArrayList<Callback>();
cl.add(callback);
cbList.put(fileName, cl);
}
}
RandomAccessFile raf = new RandomAccessFile(root.toString() + slash
+ fileName, "r");
byte[] content = new byte[(int) raf.length()];
raf.readFully(content);
return content;
}
Go to most recent paste.
(c) Copyright 2005-2011 Thomas Damgaard Nielsen.