Skip to content

Commit

Permalink
Added lots of logging.
Browse files Browse the repository at this point in the history
Fixed problem that prevented from uploading more than one image at a time under some conditions.
  • Loading branch information
Pierre-Luc Paour committed Sep 4, 2002
1 parent 1d84f32 commit 061fd07
Showing 1 changed file with 49 additions and 66 deletions.
115 changes: 49 additions & 66 deletions com/gallery/GalleryRemote/GalleryComm.java
Expand Up @@ -33,10 +33,10 @@ public class GalleryComm {
private static final String PROTOCAL_VERSION = "1";
private static final String SCRIPT_NAME = "gallery_remote.php";

private String mURLString = new String();
private String mUsername = new String();
private String mPassword = new String();
private String mAlbum = new String();
private String mURLString = null;
private String mUsername = null;
private String mPassword = null;
private String mAlbum = null;

private ArrayList mFileList;
private ArrayList mAlbumList;
Expand All @@ -50,7 +50,6 @@ public class GalleryComm {
private HTTPConnection mConnection;

public GalleryComm() {

//-- our policy handler accepts all cookies ---
CookieModule.setCookiePolicyHandler(new GalleryCookiePolicyHandler());
}
Expand All @@ -70,26 +69,33 @@ public void setURLString (String val) {

mLoggedIn = false;
}

public String getURLString () {
return mURLString;
}

public void setUsername (String val) {
mUsername = val;
mLoggedIn = false;
}

public String getUsername () {
return mUsername;
}

public void setPassword (String val) {
mPassword = val;
mLoggedIn = false;
}

public String getPassword () {
return mPassword;
}

public void setAlbum (String val) {
mAlbum = val;
}

public String getAlbum () {
return mAlbum;
}
Expand All @@ -99,9 +105,8 @@ public String getAlbum () {
//--
//-------------------------------------------------------------------------
public void uploadFiles(ArrayList fileList) {

mFileList = fileList;
final SwingWorker worker = new SwingWorker() {
mFileList = fileList;
final SwingWorker worker = new SwingWorker() {
public Object construct() {
return new ActualTask("upload");
}
Expand All @@ -113,8 +118,7 @@ public Object construct() {
//--
//-------------------------------------------------------------------------
public void fetchAlbums() {

final SwingWorker worker = new SwingWorker() {
final SwingWorker worker = new SwingWorker() {
public Object construct() {
return new ActualTask("fetch-albums");
}
Expand All @@ -127,7 +131,6 @@ public Object construct() {
//-------------------------------------------------------------------------
class ActualTask {
ActualTask (String task) {

mDone = false;

//-- login ---
Expand All @@ -139,7 +142,6 @@ class ActualTask {
}

if (task.equals("upload")) {

//-- upload each file, one at a time ---
boolean allGood = true;
mUploadedCount = 0;
Expand All @@ -149,19 +151,18 @@ class ActualTask {
allGood = uploadFile(file);
mUploadedCount++;
}
status("[Upload] Complete.");
}

else if (task.equals("fetch-albums")) {

if (allGood) {
status("[Upload] Complete.");
} else {
status("[Upload] Aborted.");
}
} else if (task.equals("fetch-albums")) {
requestAlbumList();
status("[Album Fetch] Complete.");

}

mDone = true;


}
}

Expand Down Expand Up @@ -189,29 +190,23 @@ private boolean login() {
mConnection = new HTTPConnection(url);
HTTPResponse rsp = mConnection.Post(loginPage, form_data);

if (rsp.getStatusCode() >= 300)
{
if (rsp.getStatusCode() >= 300) {
loginMessage = "HTTP Error: "+rsp.getReasonLine();

} else {
String response = new String(rsp.getData());
String response = new String(rsp.getData()).trim();

if (response.equals("SUCCESS")) {
mLoggedIn = true;
loginMessage = "Success";
} else {
loginMessage = "Login Error: " + response;
}

}
}
catch (IOException ioe)
{
} catch (IOException ioe) {
Log.logException(Log.ERROR, MODULE, ioe);
loginMessage = "Error: " + ioe.toString();
}

catch (ModuleException me)
{
} catch (ModuleException me) {
Log.logException(Log.ERROR, MODULE, me);
loginMessage = "Error handling request: " + me.getMessage();
}

Expand All @@ -223,13 +218,11 @@ private boolean login() {
//--
//-------------------------------------------------------------------------
private boolean requestAlbumList() {

mLoggedIn = false;
String albumMessage;
status("[Fetch Albums]");
status("[Fetch Albums] Fetching...");

try
{
try {
URL url = new URL(mURLString);
String loginPage = url.getFile() + SCRIPT_NAME;

Expand All @@ -246,14 +239,13 @@ private boolean requestAlbumList() {
if (rsp.getStatusCode() >= 300)
{
albumMessage = "HTTP Error: "+rsp.getReasonLine();

} else {
String response = new String(rsp.getData());
String response = new String(rsp.getData()).trim();

if (response.indexOf("SUCCESS") >= 0) {
albumMessage = "Success";

Log.log(Log.INFO, MODULE, response);
Log.log(Log.INFO, MODULE, "Fetch Albums: " + response);
mAlbumList = new ArrayList();

// build the list of hashtables here...
Expand All @@ -267,24 +259,18 @@ private boolean requestAlbumList() {
mAlbumList.add(h);
}
}

} else {
albumMessage = " Error: [" + response + "]";
albumMessage = "Error: [" + response + "]";
}

}
}
catch (IOException ioe)
{
} catch (IOException ioe) {
Log.logException(Log.ERROR, MODULE, ioe);
albumMessage = "Error: " + ioe.toString();
}

catch (ModuleException me)
{
} catch (ModuleException me) {
Log.logException(Log.ERROR, MODULE, me);
albumMessage = "Error handling request: " + me.getMessage();
}
catch (Exception ee)
{
} catch (Exception ee) {
Log.logException(Log.ERROR, MODULE, ee);
albumMessage = "Error: " + ee.getMessage();
}

Expand All @@ -301,8 +287,7 @@ public boolean uploadFile(File file) {

String uploadMessage;

try
{
try {
URL url = new URL(mURLString);
String savePage = url.getFile() + SCRIPT_NAME;

Expand All @@ -315,31 +300,29 @@ public boolean uploadFile(File file) {
NVPair[] hdrs = new NVPair[1];
byte[] data = Codecs.mpFormDataEncode(opts, afile, hdrs);
HTTPResponse rsp = mConnection.Post(savePage, data, hdrs);
if (rsp.getStatusCode() >= 300)
{

if (rsp.getStatusCode() >= 300) {
uploadMessage = "HTTP Error: "+rsp.getReasonLine();

} else {
String response = new String(rsp.getData());
String response = new String(rsp.getData()).trim();

if (response.equals("SUCCESS")) {
if (response.indexOf("SUCCESS") >= 0) {
uploadMessage = "Success";
} else {
uploadMessage = "Upload Error: " + response;
}
}
}
catch (IOException ioe)
{
catch (IOException ioe) {
Log.logException(Log.ERROR, MODULE, ioe);
uploadMessage = "Error: " + ioe.toString();
}

catch (ModuleException me)
{
} catch (ModuleException me) {
Log.logException(Log.ERROR, MODULE, me);
uploadMessage = "Error handling request: " + me.getMessage();
}

status("[Upload " + filename + "] " + uploadMessage);

return (uploadMessage.equals("Success"));
}

Expand All @@ -361,9 +344,9 @@ public int getUploadedCount() {

public ArrayList getAlbumList() {
return mAlbumList;
}
}

public boolean done() {
return mDone;
}

}

0 comments on commit 061fd07

Please sign in to comment.