4,6 → 4,7 |
import org.apache.log4j.Logger; |
|
import java.io.IOException; |
import java.io.InputStream; |
import java.net.MalformedURLException; |
import java.net.URL; |
import java.util.HashMap; |
45,7 → 46,7 |
private static final int FTP_TIMEOUT_SECONDS = pt.estgp.estgweb.Globals.FTP_TIMEOUT_SECONDS; |
public FTPClient getClient() throws IOException |
{ |
final FTPClient ftp = new FTPClient(); |
final FTPClient ftp = new MyFTPClient(); |
logger.info("CONNECTING... waiting " + FTP_TIMEOUT_SECONDS + " seconds"); |
Thread t = new Thread(new Runnable() { |
@Override |
191,5 → 192,50 |
return null; |
} |
|
public static final int FTP_DATA_STORE_TIMEOUT_SECONDS = pt.estgp.estgweb.Globals.FTP_DATA_STORE_TIMEOUT_SECONDS; |
public class MyFTPClient extends FTPClient implements Runnable |
{ |
String remote = ""; |
InputStream local = null; |
boolean storeResult = false; |
|
public void run() { |
try { |
storeResult = super.storeFile(remote, local); |
} catch (IOException e) { |
logger.error(e,e); |
} |
} |
@Override |
public boolean storeFile(String remote, InputStream local) throws IOException |
{ |
this.remote = remote; |
this.local = local; |
Thread t = new Thread(this); |
t.start(); |
try { |
for(int i=0;i<FTP_DATA_STORE_TIMEOUT_SECONDS;i++) |
{ |
Thread.sleep(1000); |
if(!t.isAlive()) |
{ |
if(this.isConnected()) |
break; |
} |
} |
if(!this.isConnected()) |
{ |
logger.info("Not Connected will interrupt"); |
t.interrupt(); |
return false; |
} |
} catch (InterruptedException e) { |
logger.error(e,e); |
} |
return storeResult; |
} |
} |
|
|
|
} |