On 29/11/2010 16:42, Niklas Gustavsson wrote:
On Mon, Nov 29, 2010 at 12:50 PM, Aidan Diffey<[email protected]> wrote:
I have taken John's advise and implemented my own
FTPFileSystemFactory, View and file.
I have implemented my FtpFile createInputStream to read the data from
the database and return a new ByteArrayOutputStream containing the
byte[] data read from the database.
This has not solved the problem, BUT it has allowed me to view a stack
trace which might be helpful in diagnosing the problem. See stack
trace and some wire shark trace as well. From looking at this and the
code, it would appear that something has set the inputstream inside
the BufferedInputStream to null.
Could you provide a test case (including some minimal code for your
file system implementation independent on a DB) for this?
/niklas
Hello.
Not too sure if this sent first time. If it did, sorry.
Used case:
I have multiple Virtual IP addresses configured each with their own
Listener configured. My server is a FTP client (using Apache Commons
FTPClient) running on a Linux machine and my server is a Windows machine
running Apache FTPServer.
I have a single FTPLet coded that uses the beforeCommand and
afterCommand. The afterCommand on PASS sets the client IP address and
the MessageEndpointFactory.
When the NIOListener receives an RETR (from the server on any of the
Virtual IP addresses), it goes through the normal RETR class in Apache
FTP server and calls the MySystemFactory and classes in order to get the
ByteArrayOutputStream.
On the suggestion from John, I moved the code out of the FTPLet and into
these classes.
I am wondering if this is a problem with Windows rather than any
implementation.
---------------------------------
FileSystemFacotry:
public class MySystemFactory implements FileSystemFactory
/**
*
* @param user
* @return
* @throws FtpException
*/
public FileSystemView createFileSystemView(User user) throws
FtpException
{
synchronized (user)
{
return new MyFileSystemView(user);
}
}
---------------------------------
MyFileSystemView
public class MyFileSystemView implements FileSystemView
{
private String serverIPAddress;
private String clientIPAddress;
private MessageEndpointFactory factory = null;
private String cwd = "";
//Getters and setters for server and client IP Addresses and
MessageEndpoint
/**
*
* @param user
*/
public MyFileSystemView (User user)
{
}
public void dispose()
{
// TODO Auto-generated method stub
}
/**
*
* @param fileName
* @return
* @throws FtpException
*/
public FtpFile getFile(String fileName) throws FtpException
{
MyFTPFile result = null;
try
{
fileName = fileName.toLowerCase();
if (fileName.contains("xml"))
{
result = new MyFTPFile(fileName, clientIPAddress,
ercuIPAddress);
result.setFactory(factory);
}
else
{
Record record = Log.getInstance().getRecord(fileName);
if (record != null)
{
result = new MyFTPFile(fileName, clientIPAddress,
ercuIPAddress);
}
}
}
catch (Exception e)
{
throw new FtpException(e.getMessage());
}
return result;
}
-----------------------
MyFTPFile
public class MyFTPFile implements FtpFile
private String fileName = "";
private String serverIPAddress = "";
private String clientIPAddress = "";
private MessageEndpointFactory factory = null;
/**
*
* @param directory
*/
public MyFTPFile(String fileName, String clientIPAddress, String
serverIPAddress )
{
this.fileName = fileName;
this.serverIPAddress = serverIPAddress ;
this.clientIPAddress = clientIPAddress;
}
/**
*
* @param offset
* @return
* @throws IOException
*/
public InputStream createInputStream(long offset) throws IOException
{
//Code in here to open the database and get stream,
try
{
//Check name
Record record = Log.getInstance().getRecord(fileName);
//DAO calling SQL
String deviceID =
Device.getInstance().getDeviceIdForIpAddress(clientIPAddress);
//DAO calling SQL
DeviceRecord device =
DeviceeEquipment.getInstance().getDeviceRecord(deviceID ); //DAO
calling SQL
byte[] zip = null;
zip = Encryption.getInstance().generateMessage(DeviceRecord)
zip = Encryption.compress(zip);
return new ByteArrayInputStream(zip);
}
catch (Exception e)
{
}
return null;
}
-------------------------------------