Refactored FTP Upload and Download behaviours.

Made FTP behaviours to use Passive mode instead of active.
[artf448994]
This commit is contained in:
Ziver Koc 2014-11-20 17:40:17 +01:00
parent 5ca06373bb
commit e4936d9f33
84 changed files with 341 additions and 105 deletions

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="UeControl" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="UeControl" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
@ -80,14 +80,13 @@
</content>
<orderEntry type="jdk" jdkName="Android API 15 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="dom4j-1.6.1" level="project" />
<orderEntry type="library" exported="" name="GraphView-3.1.3" level="project" />
<orderEntry type="library" exported="" name="android-logging-log4j-1.0.3" level="project" />
<orderEntry type="library" exported="" name="support-v4-19.1.0" level="project" />
<orderEntry type="library" exported="" name="jaxen-1.1.6" level="project" />
<orderEntry type="library" exported="" name="dom4j-1.6.1" level="project" />
<orderEntry type="library" exported="" name="log4j-1.2.17" level="project" />
<orderEntry type="library" exported="" name="commons-net-3.3" level="project" />
<orderEntry type="library" exported="" name="android-logging-log4j-1.0.3" level="project" />
<orderEntry type="library" exported="" name="gson-2.3" level="project" />
<orderEntry type="library" exported="" name="commons-net-3.3" level="project" />
<orderEntry type="library" exported="" name="jaxen-1.1.6" level="project" />
<orderEntry type="library" exported="" name="GraphView-3.1.3" level="project" />
</component>
</module>
</module>

0
app/draggable.svg Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

Before After
Before After

0
app/file.svg Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Before After
Before After

0
app/folder.svg Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Before After
Before After

0
app/function.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

Before After
Before After

0
app/function.svg Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Before After
Before After

0
app/libs/android-logging-log4j-1.0.3.jar Normal file → Executable file
View file

0
app/libs/dom4j-1.6.1.jar Normal file → Executable file
View file

0
app/libs/gson-2.3.jar Normal file → Executable file
View file

0
app/libs/jaxen-1.1.6.jar Normal file → Executable file
View file

0
app/libs/log4j-1.2.17.jar Normal file → Executable file
View file

0
app/libs/src/GraphView-3.1.3.zip Normal file → Executable file
View file

View file

@ -0,0 +1,68 @@
package com.ericsson.uecontrol.core.behaviour;
import com.ericsson.uecontrol.core.UeBehaviour;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.log4j.Logger;
import java.io.IOException;
/**
* This behaviour simulates downloading a file from FTP
*
* Created by ezivkoc on 2014-07-15.
*/
public abstract class UeBehaviourFtp extends UeBehaviour {
private static final Logger log = Logger.getLogger(UeBehaviourFtp.class);
final protected void execute() throws IOException {
FTPClient ftp = new FTPClient();
try {
// Connect
ftp.setConnectTimeout(5000);
ftp.setDataTimeout(3000);
if (getHost().contains(":")) {
String tmpHost = getHost().substring(0, getHost().indexOf(':'));
int tmpPort = Integer.parseInt(getHost().substring(getHost().indexOf(':')));
ftp.connect(tmpHost, tmpPort);
} else ftp.connect(getHost());
if(getUsername() != null && !getUsername().isEmpty())
ftp.login(getUsername(), getPassword());
ftp.setFileType(FTP.BINARY_FILE_TYPE);
ftp.enterLocalPassiveMode();
executeFtp(ftp);
// Disconnect
ftp.logout();
} finally {
if(ftp.isConnected()) {
ftp.disconnect();
}
}
}
protected String getFtpUrl(String filePath) {
String url = "ftp://";
if(getUsername() != null && !getUsername().isEmpty()) {
url += getUsername();
if(getPassword() !=null && !getPassword().isEmpty())
url += ":" + getPassword();
url += "@";
}
url += getHost();
if(filePath != null && !filePath.isEmpty()){
if(!filePath.startsWith("/"))
filePath = "/"+filePath;
url += filePath;
}
return url;
}
abstract protected void executeFtp(FTPClient client) throws IOException;
abstract String getHost();
abstract String getUsername();
abstract String getPassword();
}

View file

@ -2,15 +2,19 @@ package com.ericsson.uecontrol.core.behaviour;
import com.ericsson.uecontrol.gui.util.Configurator.Configurable;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.log4j.Logger;
import java.io.*;
/**
* This behaviour simulates downloading a file from FTP
*
* Created by ezivkoc on 2014-07-15.
*/
public class UeBehaviourFtpDownload extends UeBehaviourFileDownload {
public class UeBehaviourFtpDownload extends UeBehaviourFtp {
private static final Logger log = Logger.getLogger(UeBehaviourFtpDownload.class);
private static final int BUFFER_SIZE = 512;
@Configurable("Host")
private String host = "ftp.otenet.gr";
@ -21,23 +25,46 @@ public class UeBehaviourFtpDownload extends UeBehaviourFileDownload {
@Configurable("Password")
private String password = "speedtest";
private transient long estimatedDataLength = -1;
@Override
protected String getFileUrl() {
String url = "ftp://";
if(username != null && !username.isEmpty()) {
url += username;
if(password !=null && !password.isEmpty())
url += ":"+password;
url += "@";
protected void executeFtp(FTPClient ftp) throws IOException {
// Download data
InputStream inStream = ftp.retrieveFileStream(filePath);
if (inStream != null) {
InputStream in = new BufferedInputStream(inStream);
long progress = 0;
long read = 0;
byte[] data = new byte[BUFFER_SIZE];
while((read = in.read(data)) != -1 && !stopExecution()){
progress += read;
super.setProgress((float)progress/estimatedDataLength);
}
estimatedDataLength = progress;
in.close();
if(!ftp.completePendingCommand()) {
throw new IOException("FTP reply: "+ftp.getReplyString());
}
} else {
throw new IOException("FTP reply: "+ftp.getReplyString());
}
url += host;
if(filePath != null && !filePath.isEmpty()){
if(!filePath.startsWith("/"))
filePath = "/"+filePath;
url += filePath;
}
return url;
}
@Override
public String getHost() {
return host;
}
@Override
public String getUsername() {
return username;
}
@Override
public String getPassword() {
return password;
}
@ -46,4 +73,8 @@ public class UeBehaviourFtpDownload extends UeBehaviourFileDownload {
return "FTP Download";
}
@Override
public String toString() {
return "Will download " + getFtpUrl(filePath);
}
}

View file

@ -21,7 +21,7 @@ import java.net.URLConnection;
*
* Created by ezivkoc on 2014-07-15.
*/
public class UeBehaviourFtpUpload extends UeBehaviour {
public class UeBehaviourFtpUpload extends UeBehaviourFtp {
private static final int BUFFER_SIZE = 512;
private static final Logger log = Logger.getLogger(UeBehaviourFtpUpload.class);
@ -38,85 +38,42 @@ public class UeBehaviourFtpUpload extends UeBehaviour {
@Override
protected void execute() throws IOException {
FTPClient ftp = new FTPClient();
try {
// Connect
ftp.setConnectTimeout(3000);
ftp.setDataTimeout(200);
if (host.contains(":")) {
String tmpHost = host.substring(0, host.indexOf(':'));
int tmpPort = Integer.parseInt(host.substring(host.indexOf(':')));
ftp.connect(tmpHost, tmpPort);
} else ftp.connect(host);
ftp.login(username, password);
ftp.setFileType(FTP.BINARY_FILE_TYPE);
protected void executeFtp(FTPClient ftp) throws IOException {
// Upload data
OutputStream outStream = ftp.storeFileStream(filePath);
if (outStream != null) {
OutputStream out = new BufferedOutputStream(outStream);
int total = 0;
byte[] data = new byte[BUFFER_SIZE];
while (total < size && !stopExecution()) {
int writeLength = (total + data.length < size ? data.length : size - total);
out.write(data, 0, writeLength);
// Upload data
OutputStream outStream = ftp.storeFileStream(filePath);
if (outStream != null) {
OutputStream out = new BufferedOutputStream(outStream);
int total = 0;
byte[] data = new byte[BUFFER_SIZE];
while (total < size && !stopExecution()) {
int writeLength = (total + data.length < size ? data.length : size - total);
out.write(data, 0, writeLength);
total += writeLength;
super.setProgress((float) total / size);
}
out.close();
if(!ftp.completePendingCommand()) {
throw new IOException("FTP reply: "+ftp.getReplyString());
}
} else {
total += writeLength;
super.setProgress((float) total / size);
}
out.close();
if(!ftp.completePendingCommand()) {
throw new IOException("FTP reply: "+ftp.getReplyString());
}
// Disconnect
ftp.logout();
} finally {
if(ftp.isConnected()) {
ftp.disconnect();
}
} else {
throw new IOException("FTP reply: "+ftp.getReplyString());
}
}
/* @Override
protected void execute() throws IOException {
URL url = new URL(getFileUrl());
log.debug("Uploading file: " + url);
byte[] data = new byte[BUFFER_SIZE];
URLConnection connection = url.openConnection();
OutputStream out = new BufferedOutputStream(connection.getOutputStream());
int total = 0;
while(total < size && !stopExecution()){
int writeLength = (total+data.length < size ? data.length : total+data.length-size);
out.write(data, 0, writeLength);
total += writeLength;
super.setProgress((float)total/size);
}
out.close();
}
*/
protected String getFileUrl() {
String url = "ftp://";
if(username != null && !username.isEmpty()) {
url += username;
if(password !=null && !password.isEmpty())
url += ":"+password;
url += "@";
}
url += host;
if(filePath != null && !filePath.isEmpty()){
if(!filePath.startsWith("/"))
filePath = "/"+filePath;
url += filePath;
}
return url;
@Override
public String getHost() {
return host;
}
@Override
public String getUsername() {
return username;
}
@Override
public String getPassword() {
return password;
}

View file

@ -4,9 +4,12 @@ import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Handler;
import com.ericsson.uecontrol.gui.MainActivity;
import org.apache.log4j.Logger;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
@ -14,15 +17,24 @@ import java.net.URLConnection;
* Created by ezivkoc on 2014-09-18.
*/
public class UrlUtil {
private static final Logger log = Logger.getLogger(UrlUtil.class);
public static URLConnection getURLConnection(URL url) throws IOException {
if(!isNetworkAvailable())
throw new IOException("No Data Network Available");
URLConnection connection = url.openConnection();
final URLConnection connection = url.openConnection();
connection.setConnectTimeout(5000);
connection.setReadTimeout(3000);
connection.setUseCaches(false);
/*new Thread(new Runnable() {
public void run() {
try{Thread.sleep(5000);}catch(Exception e){};
log.error("Force disconnect URLConnection");
connection.
}
}).start();*/
connection.connect();
return connection;

View file

@ -0,0 +1,47 @@
package com.ericsson.uecontrol.gui.util;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import com.ericsson.uecontrol.gui.MainActivity;
import org.apache.log4j.Logger;
import java.util.List;
/**
* Created by ezivkoc on 2014-11-05.
*/
public class WifiScanner {
private static final Logger log = Logger.getLogger(WifiScanner.class);
private WifiManager mainWifi;
private WifiReceiver receiverWifi;
public WifiScanner() {
mainWifi = (WifiManager) MainActivity.getContext().getSystemService(MainActivity.getContext().WIFI_SERVICE);
receiverWifi = new WifiReceiver();
}
protected void start() {
MainActivity.getContext().registerReceiver(receiverWifi, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
mainWifi.startScan();
}
protected void stop() {
MainActivity.getContext().unregisterReceiver(receiverWifi);
}
class WifiReceiver extends BroadcastReceiver {
public void onReceive(Context c, Intent intent) {
List<ScanResult> scanList = mainWifi.getScanResults();
for(ScanResult item : scanList){
log.debug("WiFi scan found SSID: "+item);
}
}
}
}

0
app/src/main/res/drawable-hdpi/arrow_down_24.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 692 B

After

Width:  |  Height:  |  Size: 692 B

Before After
Before After

0
app/src/main/res/drawable-hdpi/arrow_up_24.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 714 B

After

Width:  |  Height:  |  Size: 714 B

Before After
Before After

0
app/src/main/res/drawable-hdpi/file.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Before After
Before After

0
app/src/main/res/drawable-hdpi/folder.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 2 KiB

After

Width:  |  Height:  |  Size: 2 KiB

Before After
Before After

0
app/src/main/res/drawable-hdpi/stat_download.xml Normal file → Executable file
View file

View file

View file

Before

Width:  |  Height:  |  Size: 695 B

After

Width:  |  Height:  |  Size: 695 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 675 B

After

Width:  |  Height:  |  Size: 675 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 697 B

After

Width:  |  Height:  |  Size: 697 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 688 B

After

Width:  |  Height:  |  Size: 688 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 660 B

After

Width:  |  Height:  |  Size: 660 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 673 B

After

Width:  |  Height:  |  Size: 673 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 690 B

After

Width:  |  Height:  |  Size: 690 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 681 B

After

Width:  |  Height:  |  Size: 681 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 634 B

After

Width:  |  Height:  |  Size: 634 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 704 B

After

Width:  |  Height:  |  Size: 704 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 697 B

After

Width:  |  Height:  |  Size: 697 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 669 B

After

Width:  |  Height:  |  Size: 669 B

Before After
Before After

0
app/src/main/res/drawable-hdpi/stat_upload.xml Normal file → Executable file
View file

0
app/src/main/res/drawable-mdpi/draggable.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 569 B

After

Width:  |  Height:  |  Size: 569 B

Before After
Before After

0
app/src/main/res/drawable-mdpi/file.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before After
Before After

0
app/src/main/res/drawable-mdpi/folder.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Before After
Before After

0
app/src/main/res/drawable-mdpi/icon.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 574 B

After

Width:  |  Height:  |  Size: 574 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 571 B

After

Width:  |  Height:  |  Size: 571 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 576 B

After

Width:  |  Height:  |  Size: 576 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 575 B

After

Width:  |  Height:  |  Size: 575 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 557 B

After

Width:  |  Height:  |  Size: 557 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 567 B

After

Width:  |  Height:  |  Size: 567 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 580 B

After

Width:  |  Height:  |  Size: 580 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 577 B

After

Width:  |  Height:  |  Size: 577 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 545 B

After

Width:  |  Height:  |  Size: 545 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 586 B

After

Width:  |  Height:  |  Size: 586 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 582 B

After

Width:  |  Height:  |  Size: 582 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 573 B

After

Width:  |  Height:  |  Size: 573 B

Before After
Before After

0
app/src/main/res/drawable-xhdpi/draggable.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 933 B

After

Width:  |  Height:  |  Size: 933 B

Before After
Before After

0
app/src/main/res/drawable-xhdpi/file.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Before After
Before After

0
app/src/main/res/drawable-xhdpi/folder.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Before After
Before After

0
app/src/main/res/drawable-xhdpi/icon.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 3 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 798 B

After

Width:  |  Height:  |  Size: 798 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 811 B

After

Width:  |  Height:  |  Size: 811 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 819 B

After

Width:  |  Height:  |  Size: 819 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 821 B

After

Width:  |  Height:  |  Size: 821 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 783 B

After

Width:  |  Height:  |  Size: 783 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 785 B

After

Width:  |  Height:  |  Size: 785 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 813 B

After

Width:  |  Height:  |  Size: 813 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 814 B

After

Width:  |  Height:  |  Size: 814 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 759 B

After

Width:  |  Height:  |  Size: 759 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 848 B

After

Width:  |  Height:  |  Size: 848 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 837 B

After

Width:  |  Height:  |  Size: 837 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 794 B

After

Width:  |  Height:  |  Size: 794 B

Before After
Before After

0
app/src/main/res/drawable-xxhdpi/draggable.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Before After
Before After

0
app/src/main/res/drawable-xxhdpi/file.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

Before After
Before After

0
app/src/main/res/drawable-xxhdpi/folder.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 4 KiB

After

Width:  |  Height:  |  Size: 4 KiB

Before After
Before After

0
app/src/main/res/drawable-xxhdpi/icon.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Before After
Before After

View file

View file

View file

0
app/src/main/resources/META-INF/licenses/gson/LICENSE Normal file → Executable file
View file

View file

0
app/src/main/resources/META-INF/licenses/log4j/LICENSE Normal file → Executable file
View file

0
app/src/main/resources/META-INF/licenses/log4j/NOTICE Normal file → Executable file
View file