3962: Workspace Uploader improvements: use a sequential get status instead of parallel during (multiple-)uploads
Task-Url: https://support.d4science.org/issues/3962 Updated pom version at 1.2.0 Starting sequential system to upload instead of parallel git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-uploader@128558 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
852cb584be
commit
aa74220a50
|
@ -29,5 +29,6 @@
|
|||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="/home/francesco-mangiacrapa/libraries/asm-5.0.3/lib/asm-5.0.3.jar"/>
|
||||
<classpathentry kind="con" path="com.google.gwt.eclipse.core.GWT_CONTAINER"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
eclipse.preferences.version=1
|
||||
jarsExcludedFromWebInfLib=
|
||||
lastWarOutDir=/home/francesco-mangiacrapa/wseclipseluna/workspace-uploader-TRUNK/target/workspace-uploader-1.0.0-SNAPSHOT
|
||||
warSrcDir=
|
||||
warSrcDir=src/main/webapp
|
||||
warSrcDirIsOutput=false
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
<ReleaseNotes>
|
||||
<Changeset component="org.gcube.portlets-widgets.workspace-uploader.1-2-0"
|
||||
date="2016-05-09">
|
||||
<Change>[Feature #3962] Sequential upload status</Change>
|
||||
</Changeset>
|
||||
<Changeset component="org.gcube.portlets-widgets.workspace-uploader.1-1-0"
|
||||
date="2016-01-08">
|
||||
<Change>Bug Fixed #1333</Change>
|
||||
|
|
5
pom.xml
5
pom.xml
|
@ -12,7 +12,7 @@
|
|||
<groupId>org.gcube.portlets.widgets</groupId>
|
||||
<artifactId>workspace-uploader</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.1.1-SNAPSHOT</version>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<name>Workspace Uploader Widget</name>
|
||||
<description>Workspace Uploader Widget allows your application to upload file/s in the gCube Workspace</description>
|
||||
<scm>
|
||||
|
@ -37,7 +37,7 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>maven-portal-bom</artifactId>
|
||||
<version>LATEST</version>
|
||||
<version>2.6.0-SNAPSHOT</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
@ -179,7 +179,6 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.portal</groupId>
|
||||
<artifactId>social-networking-library</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -6,11 +6,12 @@ import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem
|
|||
import com.google.gwt.event.shared.GwtEvent;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The Class CancelUploadEvent.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Sep 7, 2015
|
||||
* May 10, 2016
|
||||
*/
|
||||
public class CancelUploadEvent extends GwtEvent<CancelUploadEventHandler> {
|
||||
public static Type<CancelUploadEventHandler> TYPE = new Type<CancelUploadEventHandler>();
|
||||
|
@ -18,16 +19,12 @@ public class CancelUploadEvent extends GwtEvent<CancelUploadEventHandler> {
|
|||
private String fileName;
|
||||
private WorkspaceUploaderItem uploader;
|
||||
|
||||
|
||||
/**
|
||||
* @return the hp
|
||||
*/
|
||||
public UploaderProgressView getProgessView() {
|
||||
return uploaderProgressView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new cancel upload event.
|
||||
*
|
||||
* @param uploader the uploader
|
||||
* @param uploaderProgressView the uploader progress view
|
||||
* @param fileName the file name
|
||||
*/
|
||||
public CancelUploadEvent(WorkspaceUploaderItem uploader, UploaderProgressView uploaderProgressView, String fileName) {
|
||||
this.uploader = uploader;
|
||||
|
@ -36,6 +33,8 @@ public class CancelUploadEvent extends GwtEvent<CancelUploadEventHandler> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets the uploader.
|
||||
*
|
||||
* @return the uploader
|
||||
*/
|
||||
public WorkspaceUploaderItem getUploader() {
|
||||
|
@ -59,7 +58,19 @@ public class CancelUploadEvent extends GwtEvent<CancelUploadEventHandler> {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* Gets the progess view.
|
||||
*
|
||||
* @return the progess view
|
||||
*/
|
||||
public UploaderProgressView getProgessView() {
|
||||
return uploaderProgressView;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the file name.
|
||||
*
|
||||
* @return the file name
|
||||
*/
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
|
|
|
@ -233,6 +233,7 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
|
|||
}
|
||||
});
|
||||
|
||||
//TODO NEVER USED, WE ARE USING MULTIPLE DIALOG UPLOAD
|
||||
formPanel.addSubmitHandler(new SubmitHandler() {
|
||||
|
||||
@Override
|
||||
|
@ -242,10 +243,10 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
|
|||
enableButtons(false);
|
||||
WorkspaceUploaderItem fakeUploader = new WorkspaceUploaderItem();
|
||||
fakeUploader.setClientUploadKey(clientUploadKey);
|
||||
UploaderMonitor.getInstance().addNewSubmit(fakeUploader, fileUpload.getFilename());
|
||||
UploaderMonitor.getInstance().addNewUploaderToMonitorPanel(fakeUploader, fileUpload.getFilename());
|
||||
setVisible(false);
|
||||
removeLoading();
|
||||
UploaderMonitor.getInstance().pollWorkspaceUploader(fakeUploader);
|
||||
// UploaderMonitor.getInstance().pollWorkspaceUploader(fakeUploader);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -142,13 +142,18 @@ public class MonitorPanel extends ScrollPanel{
|
|||
*/
|
||||
public void updateWorkspaceUploder(WorkspaceUploaderItem uploader){
|
||||
|
||||
if(uploader==null){
|
||||
GWT.log("Skipping update progress view, uploader is null");
|
||||
return;
|
||||
}
|
||||
|
||||
mapUploading.put(uploader.getClientUploadKey(), uploader);
|
||||
|
||||
if(mapPanels.get(uploader.getClientUploadKey())!=null){
|
||||
UploaderProgressView upv = mapPanels.get(uploader.getClientUploadKey());
|
||||
upv.update(uploader);
|
||||
}else{
|
||||
GWT.log("Skip update, uploader: "+uploader.getClientUploadKey() +" "+uploader.getFile().toString()+", not found!");
|
||||
GWT.log("Skipping update progress view, uploader: "+uploader.getClientUploadKey() +" "+uploader.getFile().toString()+", not found!");
|
||||
}
|
||||
|
||||
updateNumberUpload();
|
||||
|
@ -185,7 +190,7 @@ public class MonitorPanel extends ScrollPanel{
|
|||
String msg = "";
|
||||
for (String uploadKey : mapUploading.keySet()) {
|
||||
WorkspaceUploaderItem uploader = mapUploading.get(uploadKey);
|
||||
GWT.log("Closing uploder status: "+uploader.getFile().getFileName() +" status: "+uploader.getUploadStatus());
|
||||
GWT.log("Closing uploader status: "+uploader.getFile().getFileName() +" status: "+uploader.getUploadStatus());
|
||||
if(uploader.getUploadStatus().equals(UPLOAD_STATUS.WAIT) || uploader.getUploadStatus().equals(UPLOAD_STATUS.IN_PROGRESS))
|
||||
msg+=uploader.getFile().getFileName()+";";
|
||||
}
|
||||
|
|
|
@ -64,9 +64,6 @@ public class MultipleDilaogUpload extends DialogUpload {
|
|||
fileUploadID = GenerateUUID.get(10, 16); // is tagID
|
||||
fileUpload.getElement().setId(fileUploadID);
|
||||
this.addHandlers();
|
||||
// exportGenerateFakeUploaders();
|
||||
// exportCreateJsonKeyForFiles();
|
||||
// exportAddNewSubmitToMonitor();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,10 +84,7 @@ public class MultipleDilaogUpload extends DialogUpload {
|
|||
for (int i = 0; i < files.length; i++) {
|
||||
String normalizedFileName = files[i];
|
||||
if (normalizedFileName.contains("\\")) {
|
||||
files[i] = normalizedFileName.substring(normalizedFileName.lastIndexOf("\\") + 1); // remove
|
||||
// C:\fakepath\
|
||||
// if
|
||||
// exists
|
||||
files[i] = normalizedFileName.substring(normalizedFileName.lastIndexOf("\\") + 1); // remove C:\fakepath if exists
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,19 +150,6 @@ public class MultipleDilaogUpload extends DialogUpload {
|
|||
break;
|
||||
}
|
||||
case OK: {
|
||||
// removeLoading();
|
||||
// UploaderMonitor.getInstance().pollWorkspaceUploaderId(resultMessage.getMessage());
|
||||
|
||||
/*
|
||||
* Timer t = new Timer() { public void run() {
|
||||
* GWT.log("Upload started with id: "
|
||||
* +resultMessage.getMessage());
|
||||
* UploaderMonitor.getInstance(
|
||||
* ).pollWorkspaceUploaderId(resultMessage.getMessage()); }
|
||||
* };
|
||||
*
|
||||
* t.schedule(250);
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -206,16 +187,6 @@ public class MultipleDilaogUpload extends DialogUpload {
|
|||
if(isLimitExceeded(files.length))
|
||||
return;
|
||||
|
||||
// if (files.length > ConstantsWorkspaceUploader.LIMIT_UPLOADS) {
|
||||
// Window.alert("Multiple upload limit is "
|
||||
// + ConstantsWorkspaceUploader.LIMIT_UPLOADS
|
||||
// + " files");
|
||||
// MultipleDilaogUpload.this.hide();
|
||||
// return;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// GENERATE NEW UPLOADERS
|
||||
generateFakeUploaders(filesSelected, parentIdentifier);
|
||||
GWT.log(fakeUploaders.toString());
|
||||
|
@ -302,12 +273,16 @@ public class MultipleDilaogUpload extends DialogUpload {
|
|||
*/
|
||||
public void addNewSubmitToMonitor(){
|
||||
GWT.log("addNewSubmitToMonitor...");
|
||||
int queueIndex = UploaderMonitor.getInstance().newQueue();
|
||||
for (final WorkspaceUploaderItem workspaceUploaderItem : fakeUploaders) {
|
||||
UploaderMonitor.getInstance().addNewSubmit(workspaceUploaderItem, workspaceUploaderItem.getFile().getFileName());
|
||||
UploaderMonitor.getInstance().addNewUploaderToMonitorPanel(workspaceUploaderItem, workspaceUploaderItem.getFile().getFileName());
|
||||
setVisible(false);
|
||||
removeLoading();
|
||||
UploaderMonitor.getInstance().pollWorkspaceUploader(workspaceUploaderItem);
|
||||
UploaderMonitor.getInstance().addNewTimerToQueue(queueIndex, workspaceUploaderItem);
|
||||
// UploaderMonitor.getInstance().pollWorkspaceUploader(workspaceUploaderItem);
|
||||
}
|
||||
|
||||
UploaderMonitor.getInstance().doStartPollingQueue(queueIndex);
|
||||
}
|
||||
|
||||
|
||||
|
@ -339,64 +314,12 @@ public class MultipleDilaogUpload extends DialogUpload {
|
|||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Export generate fake uploaders.
|
||||
// */
|
||||
// public native void exportGenerateFakeUploaders() /*-{
|
||||
// var that = this;
|
||||
// $wnd.add = $entry(function(files,parentId) {
|
||||
// that.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::generateFakeUploaders([Ljava/lang/String;Ljava/lang/String;)(files,parentId);
|
||||
// });
|
||||
// }-*/;
|
||||
//
|
||||
// /**
|
||||
// * Export create json key for files.
|
||||
// */
|
||||
// public native void exportCreateJsonKeyForFiles() /*-{
|
||||
// var that = this;
|
||||
// $wnd.add = $entry(function() {
|
||||
// that.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::createJsonKeyForFiles()();
|
||||
// });
|
||||
// }-*/;
|
||||
//
|
||||
// /**
|
||||
// * Export create json key for files.
|
||||
// */
|
||||
// public native void exportAddNewSubmitToMonitor() /*-{
|
||||
// var that = this;
|
||||
// $wnd.add = $entry(function() {
|
||||
// that.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::addNewSubmitToMonitor()();
|
||||
// });
|
||||
// }-*/;
|
||||
|
||||
|
||||
/**
|
||||
* Submit form.
|
||||
*/
|
||||
@Override
|
||||
public void submitForm() {
|
||||
formPanel.submit();
|
||||
// for (final WorkspaceUploaderItem workspaceUploaderItem :
|
||||
// fakeUploaders) {
|
||||
//
|
||||
// UploaderMonitor.getInstance().addNewSubmit(workspaceUploaderItem,
|
||||
// workspaceUploaderItem.getFile().getFileName());
|
||||
// setVisible(false);
|
||||
// removeLoading();
|
||||
// //
|
||||
// UploaderMonitor.getInstance().pollWorkspaceUploaderId(workspaceUploaderItem.getClientUploadKey());
|
||||
//
|
||||
// //WAITING 0.1 SEC TO FIRST UPDATES
|
||||
// /*new Timer() {
|
||||
//
|
||||
// @Override
|
||||
// public void run() {
|
||||
// removeLoading();
|
||||
// UploaderMonitor.getInstance().pollWorkspaceUploaderId(workspaceUploaderItem.getClientUploadKey());
|
||||
//
|
||||
// }
|
||||
// }.schedule(100);*/
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -445,21 +368,6 @@ public class MultipleDilaogUpload extends DialogUpload {
|
|||
return uploadType;
|
||||
}
|
||||
|
||||
// public native void exportParentId() /*-{
|
||||
// var that = this;
|
||||
// $wnd.add = $entry(function() {
|
||||
// that.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::getParentId();
|
||||
// });
|
||||
// }-*/;
|
||||
//
|
||||
// public native void exportUploadType() /*-{
|
||||
// var that = this;
|
||||
// $wnd.add = $entry(function() {
|
||||
// that.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::getUploadType();
|
||||
// });
|
||||
// }-*/;
|
||||
|
||||
|
||||
/**
|
||||
* Gets the files selected.
|
||||
*
|
||||
|
@ -615,7 +523,9 @@ public class MultipleDilaogUpload extends DialogUpload {
|
|||
formdata.append('uploadFormElement', file);
|
||||
|
||||
xhr.send(formdata);
|
||||
|
||||
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::addNewSubmitToMonitor()();
|
||||
|
||||
// reader.readAsText(file);
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -3,8 +3,12 @@
|
|||
*/
|
||||
package org.gcube.portlets.widgets.workspaceuploader.client.uploader;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.ClosableDialog;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
|
||||
|
@ -45,8 +49,10 @@ public class UploaderMonitor {
|
|||
private static UploaderMonitor instance;
|
||||
private final static HandlerManager monitorEventBus = new HandlerManager(null);
|
||||
private MonitorPanel monitorPanel = new MonitorPanel(monitorEventBus);
|
||||
private static Map<String, Timer> mapTimer = new HashMap<String, Timer>();
|
||||
private static ArrayList<LinkedHashMap<String, WorkspaceUploaderItem>> queueUploads = new ArrayList<LinkedHashMap<String,WorkspaceUploaderItem>>();
|
||||
|
||||
private ClosableDialog dialogUploadMonitor = new ClosableDialog(monitorPanel, false, ConstantsWorkspaceUploader.MY_UPLOADS);
|
||||
private Map<String, Timer> currentTimersRun = new HashMap<String, Timer>();
|
||||
|
||||
/**
|
||||
* Gets the single instance of UploaderMonitor.
|
||||
|
@ -60,6 +66,9 @@ public class UploaderMonitor {
|
|||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new uploader monitor.
|
||||
*/
|
||||
private UploaderMonitor(){
|
||||
dialogUploadMonitor.setWidth("400px");
|
||||
bindEvents();
|
||||
|
@ -78,34 +87,54 @@ public class UploaderMonitor {
|
|||
if(deleteTimerEvent.getUploader()==null)
|
||||
return;
|
||||
|
||||
String clientKey = deleteTimerEvent.getUploader().getClientUploadKey();
|
||||
Timer timer = mapTimer.get(clientKey);
|
||||
GWT.log("Delete timer "+timer);
|
||||
if(timer!=null && timer.isRunning()){
|
||||
timer.cancel();
|
||||
mapTimer.put(clientKey, null);
|
||||
final String clientKey = deleteTimerEvent.getUploader().getClientUploadKey();
|
||||
final LinkedHashMap<String, WorkspaceUploaderItem> queue = getQueueFromClientUploadKey(clientKey);
|
||||
if(queue==null){
|
||||
GWT.log("onCancelUpload mapUpload is null for key: "+clientKey +", return");
|
||||
return;
|
||||
}
|
||||
|
||||
RequestBuilder request = new RequestBuilder(RequestBuilder.GET,
|
||||
ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_SERVLET_STREAM+"?"+ConstantsWorkspaceUploader.CLIENT_UPLOAD_KEYS+"="+clientKey+"&"+ConstantsWorkspaceUploader.CANCEL_UPLOAD+"=true");
|
||||
final Timer timer = getTimer(clientKey);
|
||||
GWT.log("Client abort for timer with clientKey "+clientKey);
|
||||
|
||||
if(timer==null || !timer.isRunning()){
|
||||
GWT.log("Timer abort skipping, timer for clientKey "+clientKey+" is null or not running");
|
||||
return;
|
||||
}
|
||||
|
||||
//CANCELLING TIMER
|
||||
timer.cancel();
|
||||
// queue.put(clientKey, null);
|
||||
|
||||
/*if(timer!=null && timer.isRunning()){
|
||||
timer.cancel();
|
||||
// mapUpload.put(clientKey, null);
|
||||
GWT.log("Aborted WorkspaceUploaderItem for key: "+clientKey);
|
||||
// removeTimer(clientKey);
|
||||
}*/
|
||||
|
||||
RequestBuilder request = new RequestBuilder(RequestBuilder.GET, ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_SERVLET_STREAM+"?"+ConstantsWorkspaceUploader.CLIENT_UPLOAD_KEYS+"="+clientKey+"&"+ConstantsWorkspaceUploader.CANCEL_UPLOAD+"=true");
|
||||
try {
|
||||
request.sendRequest(null, new RequestCallback() {
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
@Override
|
||||
public void onResponseReceived(Request request, Response response) {
|
||||
String strippedResult = new HTML(response.getText()).getText();
|
||||
final HandlerResultMessage resultMessage = HandlerResultMessage.parseResult(strippedResult);
|
||||
String result = response.getText();
|
||||
GWT.log("onResponseReceived "+result);
|
||||
final HandlerResultMessage resultMessage = HandlerResultMessage.parseResult(result);
|
||||
GWT.log("Cancel Upload Stream result: "+resultMessage);
|
||||
if(resultMessage==null)
|
||||
return;
|
||||
|
||||
switch(resultMessage.getStatus()){
|
||||
case ERROR:{
|
||||
GWT.log("ERROR: Error during stop upload "+resultMessage.getMessage());
|
||||
Window.alert("Sorry, An error occurred during upload abort!");
|
||||
return;
|
||||
Window.alert("Sorry, An error occurred during upload abort! "+resultMessage.getMessage());
|
||||
break;
|
||||
}
|
||||
case OK:{
|
||||
UploaderProgressView upv = deleteTimerEvent.getProgessView();
|
||||
VerticalPanel vp = upv.getPanel();
|
||||
VerticalPanel vp = upv!=null?upv.getPanel():null;
|
||||
if(vp!=null){
|
||||
vp.clear();
|
||||
HTML html = new HTML();
|
||||
|
@ -113,14 +142,71 @@ public class UploaderMonitor {
|
|||
String text = "<div><img src='"+WorkspaceUploaderResources.getImageCancelRed().getUrl()+"'>";
|
||||
text+="<span style='margin-left:5px; vertical-align: top;'>Upload "+deleteTimerEvent.getFileName()+ " aborted</span></div>";
|
||||
html.setHTML(text);
|
||||
|
||||
//UPDATING STATUS AS ABORTED IN ORDER TO STOP THE TIMER
|
||||
// WorkspaceUploaderItem workspaceUploader = mapUpload.get(clientKey);
|
||||
// workspaceUploader.setUploadStatus(UPLOAD_STATUS.ABORTED);
|
||||
// mapUpload.put(clientKey, workspaceUploader);
|
||||
|
||||
//UPDATING STATUS AS ABORTED IN ORDER TO STOP THE TIMER
|
||||
GWT.log("Upload Aborted is OK");
|
||||
timer.cancel();
|
||||
// queue.remove(clientKey);
|
||||
removeTimer(clientKey);
|
||||
// int indexQueue = getQueueIndexFromClientUploadKey(clientKey);
|
||||
// nextUploader(queue, indexQueue);
|
||||
// queue.remove(clientKey);
|
||||
// timer.cancel();
|
||||
// removeTimer(clientKey);
|
||||
// int indexQueue = getQueueIndexFromClientUploadKey(clientKey);
|
||||
// nextUploader(queue, indexQueue);
|
||||
|
||||
deleteTimerEvent.getUploader().setUploadStatus(UPLOAD_STATUS.ABORTED);
|
||||
notifyUploadAborted(deleteTimerEvent.getUploader().getFile().getParentId(), null);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case UNKNOWN:
|
||||
case WARN:{
|
||||
GWT.log("UNKNOWN/WARN CASE: Error during stop upload "+resultMessage.getMessage());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// switch (resultMessage.getStatus()) {
|
||||
// case ERROR: {
|
||||
// GWT.log("ERROR: Error during stop upload "+resultMessage.getMessage());
|
||||
// Window.alert("Sorry, An error occurred during upload abort! "+resultMessage.getMessage());
|
||||
// break;
|
||||
// }
|
||||
// case OK: {
|
||||
// UploaderProgressView upv = deleteTimerEvent.getProgessView();
|
||||
// VerticalPanel vp = upv!=null?upv.getPanel():null;
|
||||
// if(vp!=null){
|
||||
// vp.clear();
|
||||
// HTML html = new HTML();
|
||||
// vp.add(html);
|
||||
// String text = "<div><img src='"+WorkspaceUploaderResources.getImageCancelRed().getUrl()+"'>";
|
||||
// text+="<span style='margin-left:5px; vertical-align: top;'>Upload "+deleteTimerEvent.getFileName()+ " aborted</span></div>";
|
||||
// html.setHTML(text);
|
||||
|
||||
//UPDATING STATUS AS ABORTED IN ORDER TO STOP THE TIMER
|
||||
// WorkspaceUploaderItem workspaceUploader = mapUpload.get(clientKey);
|
||||
// workspaceUploader.setUploadStatus(UPLOAD_STATUS.ABORTED);
|
||||
// mapUpload.put(clientKey, workspaceUploader);
|
||||
|
||||
// deleteTimerEvent.getUploader().setUploadStatus(UPLOAD_STATUS.ABORTED);
|
||||
// notifyUploadAborted(deleteTimerEvent.getUploader().getFile().getParentId(), null);
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// default:{
|
||||
// GWT.log("UNKNOWN CASE: Error during stop upload "+resultMessage.getMessage());
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Request request, Throwable exception) {
|
||||
GWT.log("ERROR: Error during stop upload "+exception.getMessage());
|
||||
|
@ -143,6 +229,45 @@ public class UploaderMonitor {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the queue from client upload key.
|
||||
*
|
||||
* @param clientKey the client key
|
||||
* @return the queue from client upload key, otherwise null;
|
||||
*/
|
||||
public LinkedHashMap<String, WorkspaceUploaderItem> getQueueFromClientUploadKey(String clientKey){
|
||||
for (LinkedHashMap<String, WorkspaceUploaderItem> queue : queueUploads) {
|
||||
if(queue!=null){
|
||||
WorkspaceUploaderItem tm = queue.get(clientKey);
|
||||
if(tm != null)
|
||||
return queue;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the queue index from client upload key.
|
||||
*
|
||||
* @param clientKey the client key
|
||||
* @return the queue index from client upload key, otherwise -1;
|
||||
*/
|
||||
public int getQueueIndexFromClientUploadKey(String clientKey){
|
||||
int index = -1;
|
||||
for (LinkedHashMap<String, WorkspaceUploaderItem> queue : queueUploads) {
|
||||
if(queue!=null){
|
||||
index++;
|
||||
WorkspaceUploaderItem tm = queue.get(clientKey);
|
||||
if(tm != null)
|
||||
return index;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show monitor.
|
||||
*/
|
||||
|
@ -152,14 +277,13 @@ public class UploaderMonitor {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Adds the new submit.
|
||||
* Adds the new uploader to monitor panel.
|
||||
*
|
||||
* @param uploader the uploader
|
||||
* @param fileName the file name
|
||||
*/
|
||||
public void addNewSubmit(WorkspaceUploaderItem uploader, String fileName){
|
||||
public void addNewUploaderToMonitorPanel(WorkspaceUploaderItem uploader, String fileName){
|
||||
if(!dialogUploadMonitor.isShowing())
|
||||
dialogUploadMonitor.center();
|
||||
|
||||
|
@ -167,29 +291,32 @@ public class UploaderMonitor {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Poll workspace uploader.
|
||||
* Do polling.
|
||||
*
|
||||
* @param workspaceUploader the workspace uploader item
|
||||
* @param workspaceUploader the workspace uploader
|
||||
* @param queue the queue
|
||||
* @param indexQueue the index queue
|
||||
* @return the timer
|
||||
*/
|
||||
public void pollWorkspaceUploader(final WorkspaceUploaderItem workspaceUploader){
|
||||
/*private void doPolling(final WorkspaceUploaderItem workspaceUploader){
|
||||
|
||||
Timer timer = new Timer() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
WorkspaceUploaderServiceAsync.Util.getInstance().getUploadStatus(workspaceUploader.getClientUploadKey(), new AsyncCallback<WorkspaceUploaderItem>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(WorkspaceUploaderItem result) {
|
||||
// GWT.log("onSuccess: "+result.toString());
|
||||
synchronized(this){
|
||||
Timer tmn = mapTimer.get(workspaceUploader.getClientUploadKey());
|
||||
Timer tmn = queueTimers.get(workspaceUploader.getClientUploadKey());
|
||||
if(tmn!=null && tmn.isRunning()){
|
||||
if(result.getUploadStatus().equals(UPLOAD_STATUS.COMPLETED)){
|
||||
GWT.log("Upload Completed "+result.getFile().getItemId() +" name: "+result.getFile().getFileName());
|
||||
mapTimer.remove(tmn);
|
||||
queueTimers.remove(tmn);
|
||||
|
||||
if(!result.getIsOverwrite())
|
||||
notifyUploadCompleted(result.getFile().getParentId(), result.getFile().getItemId());
|
||||
|
@ -199,7 +326,7 @@ public class UploaderMonitor {
|
|||
cancel();
|
||||
}else if(result.getUploadStatus().equals(UPLOAD_STATUS.FAILED)){
|
||||
GWT.log("Upload Failed "+result.getFile().getItemId() +" name: "+result.getFile().getFileName());
|
||||
mapTimer.remove(tmn);
|
||||
queueTimers.remove(tmn);
|
||||
notifyUploadError(result.getFile().getParentId(), null, null);
|
||||
// new DialogResult(null, "Upload Failed!!", result.getStatusDescription()).center();
|
||||
cancel();
|
||||
|
@ -223,8 +350,121 @@ public class UploaderMonitor {
|
|||
|
||||
}
|
||||
};
|
||||
mapTimer.put(workspaceUploader.getClientUploadKey(), timer);
|
||||
queueTimers.put(workspaceUploader.getClientUploadKey(), timer);
|
||||
timer.scheduleRepeating(2000);
|
||||
|
||||
}*/
|
||||
|
||||
|
||||
public void startTimer(final WorkspaceUploaderItem workspaceUploader, final LinkedHashMap<String, WorkspaceUploaderItem> queue, final int indexQueue){
|
||||
|
||||
final Timer timer = new Timer() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
WorkspaceUploaderServiceAsync.Util.getInstance().getUploadStatus(workspaceUploader.getClientUploadKey(), new AsyncCallback<WorkspaceUploaderItem>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(WorkspaceUploaderItem result) {
|
||||
// GWT.log("onSuccess: "+result.toString());
|
||||
synchronized(this){
|
||||
// Timer tmn = queue.get(workspaceUploader.getClientUploadKey());
|
||||
if(isRunning()){
|
||||
if(result.getUploadStatus()==null){
|
||||
GWT.log("Upload status is null for: "+workspaceUploader.getClientUploadKey());
|
||||
return;
|
||||
}
|
||||
if(result.getUploadStatus().equals(UPLOAD_STATUS.COMPLETED)){
|
||||
GWT.log("Upload Completed "+result.getFile().getItemId() +" name: "+result.getFile().getFileName());
|
||||
queue.remove(workspaceUploader.getClientUploadKey());
|
||||
|
||||
if(!result.getIsOverwrite())
|
||||
notifyUploadCompleted(result.getFile().getParentId(), result.getFile().getItemId());
|
||||
else
|
||||
notifyOverwriteCompleted(result.getFile().getParentId(), result.getFile().getItemId());
|
||||
|
||||
cancel();
|
||||
removeTimer(workspaceUploader.getClientUploadKey());
|
||||
nextUploader(queue, indexQueue);
|
||||
}else if(result.getUploadStatus().equals(UPLOAD_STATUS.FAILED)){
|
||||
GWT.log("Upload Failed "+result.getFile().getItemId() +" name: "+result.getFile().getFileName());
|
||||
queue.remove(workspaceUploader.getClientUploadKey());
|
||||
notifyUploadError(result.getFile().getParentId(), null, null);
|
||||
// new DialogResult(null, "Upload Failed!!", result.getStatusDescription()).center();
|
||||
|
||||
cancel();
|
||||
removeTimer(workspaceUploader.getClientUploadKey());
|
||||
nextUploader(queue, indexQueue);
|
||||
}
|
||||
// }else if(result.getUploadStatus().equals(UPLOAD_STATUS.ABORTED)){
|
||||
// GWT.log("Upload Aborted "+result.getFile().getItemId() +" name: "+result.getFile().getFileName());
|
||||
// cancel();
|
||||
// removeTimer(workspaceUploader.getClientUploadKey());
|
||||
// nextUploader(queue, indexQueue);
|
||||
// }
|
||||
|
||||
monitorPanel.updateWorkspaceUploder(result);
|
||||
// GWT.log(result.toString());
|
||||
}else{
|
||||
GWT.log("Timer is null or already closed or completed");
|
||||
cancel();
|
||||
removeTimer(workspaceUploader.getClientUploadKey());
|
||||
nextUploader(queue, indexQueue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
GWT.log("onFailure: "+caught.getMessage());
|
||||
cancel();
|
||||
notifyUploadError(workspaceUploader.getFile().getParentId(), null, caught);
|
||||
removeTimer(workspaceUploader.getClientUploadKey());
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
GWT.log("Starting new timer for key: "+workspaceUploader.getClientUploadKey());
|
||||
saveTimer(timer, workspaceUploader.getClientUploadKey());
|
||||
timer.scheduleRepeating(2000);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes the timer.
|
||||
*
|
||||
* @param clientKey the client key
|
||||
*/
|
||||
private synchronized void removeTimer(String clientKey){
|
||||
Timer timer = currentTimersRun.get(clientKey);
|
||||
if(timer!=null){
|
||||
currentTimersRun.remove(clientKey);
|
||||
GWT.log("Remove timer for key: "+clientKey+", performed correctly");
|
||||
}else
|
||||
GWT.log("Remove timer for key: "+clientKey+", skypped, already removed?");
|
||||
}
|
||||
|
||||
/**
|
||||
* Save timer.
|
||||
*
|
||||
* @param timer the timer
|
||||
* @param clientKey the client key
|
||||
*/
|
||||
private synchronized void saveTimer(Timer timer, String clientKey){
|
||||
currentTimersRun.put(clientKey, timer);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the timer.
|
||||
*
|
||||
* @param clientKey the client key
|
||||
* @return the timer
|
||||
*/
|
||||
private Timer getTimer(String clientKey){
|
||||
return currentTimersRun.get(clientKey);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -269,4 +509,135 @@ public class UploaderMonitor {
|
|||
private void notifyUploadError(String parentId, String itemId, Throwable t){
|
||||
WorkspaceUploaderListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.FAILED, parentId, itemId, t));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* New queue.
|
||||
*
|
||||
* @return the int
|
||||
*/
|
||||
public synchronized int newQueue() {
|
||||
|
||||
int freeIndex = -1;
|
||||
GWT.log("Current queue upload size is: "+queueUploads.size());
|
||||
for(int i = 0; i < queueUploads.size(); i++){
|
||||
if(queueUploads.get(i) == null){
|
||||
freeIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GWT.log("Index for new queue uploads is: "+freeIndex);
|
||||
|
||||
if(freeIndex>=0 && freeIndex<queueUploads.size()){
|
||||
GWT.log("Using set index: "+freeIndex);
|
||||
queueUploads.set(freeIndex, new LinkedHashMap<String,WorkspaceUploaderItem>());
|
||||
}else{
|
||||
freeIndex= queueUploads.size();
|
||||
GWT.log("Using add index: "+freeIndex);
|
||||
queueUploads.add(freeIndex, new LinkedHashMap<String,WorkspaceUploaderItem>());
|
||||
}
|
||||
GWT.log("Returning new queue index: "+freeIndex);
|
||||
return freeIndex;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete queue.
|
||||
*
|
||||
* @param index the index
|
||||
*/
|
||||
public synchronized void deleteQueue(int index) {
|
||||
|
||||
if(index<0){
|
||||
GWT.log("Delete queue at invalid index: "+index +", skipping delete");
|
||||
return;
|
||||
}
|
||||
|
||||
if(queueUploads.get(index)!=null){
|
||||
queueUploads.set(index, null);
|
||||
GWT.log("Deleted queue at index: "+index);
|
||||
}else
|
||||
GWT.log("Queue at index: "+index +", not found, already deleted?, skipping");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds the new timer to queue.
|
||||
*
|
||||
* @param indexQueue the index queue
|
||||
* @param workspaceUploaderItem the workspace uploader item
|
||||
*/
|
||||
public void addNewTimerToQueue(int indexQueue, WorkspaceUploaderItem workspaceUploaderItem) {
|
||||
LinkedHashMap<String, WorkspaceUploaderItem> queue = queueUploads.get(indexQueue);
|
||||
queue.put(workspaceUploaderItem.getClientUploadKey(), workspaceUploaderItem);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Do start polling queue.
|
||||
*
|
||||
* @param index the index
|
||||
*/
|
||||
public synchronized void doStartPollingQueue(int index) {
|
||||
LinkedHashMap<String, WorkspaceUploaderItem> queue = queueUploads.get(index);
|
||||
|
||||
if(queue.size()<0){
|
||||
GWT.log("doStartPollingQueue return, queue size is < 0");
|
||||
return;
|
||||
}
|
||||
|
||||
Set<String> keys = queue.keySet();
|
||||
|
||||
if(keys.size()==0){
|
||||
GWT.log("no keys for queue index: "+index+", return");
|
||||
return;
|
||||
}
|
||||
|
||||
WorkspaceUploaderItem workspaceUploader = getNextUploader(queue);
|
||||
startTimer(workspaceUploader, queue, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next uploader.
|
||||
*
|
||||
* @param queue the queue
|
||||
* @return the next uploader
|
||||
*/
|
||||
public WorkspaceUploaderItem getNextUploader(LinkedHashMap<String, WorkspaceUploaderItem> queue){
|
||||
Iterator<String> it = queue.keySet().iterator();
|
||||
String firstKey = it.next();
|
||||
|
||||
if(firstKey==null || firstKey.isEmpty()){
|
||||
GWT.log("getNextUploader return empty or null key, returning null");
|
||||
return null;
|
||||
}
|
||||
|
||||
return queue.get(firstKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Next uploader.
|
||||
*
|
||||
* @param queue the queue
|
||||
* @param indexQueue the index queue
|
||||
*/
|
||||
public synchronized void nextUploader(LinkedHashMap<String, WorkspaceUploaderItem> queue, int indexQueue){
|
||||
|
||||
if(queue.keySet().size()==0){
|
||||
GWT.log("nextUploader return, queue size is = 0, deleting queue");
|
||||
deleteQueue(indexQueue);
|
||||
return;
|
||||
}
|
||||
|
||||
WorkspaceUploaderItem workspaceUploader = getNextUploader(queue);
|
||||
|
||||
if(workspaceUploader==null){
|
||||
GWT.log("nextUploader return a null uploader, deleting queue");
|
||||
deleteQueue(indexQueue);
|
||||
return;
|
||||
}
|
||||
|
||||
startTimer(workspaceUploader, queue, indexQueue);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,6 +92,7 @@ public class UploaderProgressView {
|
|||
*/
|
||||
public void update(WorkspaceUploaderItem uploader){
|
||||
String text;
|
||||
try{
|
||||
switch(uploader.getUploadStatus()){
|
||||
case COMPLETED:
|
||||
setVisibleBar(true);
|
||||
|
@ -164,6 +165,9 @@ public class UploaderProgressView {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
}catch(Exception e) {
|
||||
GWT.log("error during update");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -57,10 +57,13 @@ public class WorkspaceFieldsUploadManager {
|
|||
*/
|
||||
public void addNewSubmitToMonitor(){
|
||||
GWT.log("addNewSubmitToMonitor...");
|
||||
int queueIndex = UploaderMonitor.getInstance().newQueue();
|
||||
for (final WorkspaceUploaderItem workspaceUploaderItem : fakeUploaders) {
|
||||
UploaderMonitor.getInstance().addNewSubmit(workspaceUploaderItem, workspaceUploaderItem.getFile().getFileName());
|
||||
UploaderMonitor.getInstance().pollWorkspaceUploader(workspaceUploaderItem);
|
||||
UploaderMonitor.getInstance().addNewUploaderToMonitorPanel(workspaceUploaderItem, workspaceUploaderItem.getFile().getFileName());
|
||||
UploaderMonitor.getInstance().addNewTimerToQueue(queueIndex, workspaceUploaderItem);
|
||||
// UploaderMonitor.getInstance().pollWorkspaceUploader(workspaceUploaderItem);
|
||||
}
|
||||
UploaderMonitor.getInstance().doStartPollingQueue(queueIndex);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -308,18 +308,25 @@ public class MultipleDNDUpload extends LayoutPanel implements
|
|||
|
||||
console.log("initW3CFileReader");
|
||||
|
||||
function makeSyncAjaxCall(url, params, msgText, conType){
|
||||
function isFileOverwrite(url, params, msgText){
|
||||
var xhReq = new XMLHttpRequest();
|
||||
xhReq.open(conType, url+"?"+params, false);
|
||||
if (conType == "POST")
|
||||
xhReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||
|
||||
xhReq.open("GET", url+"?"+params, false); //SYNCRONUS CALL
|
||||
xhReq.send(msgText);
|
||||
if(xhReq.status==200){
|
||||
console.log(xhReq.responseText);
|
||||
return xhReq.responseText;
|
||||
}else
|
||||
if(xhReq.readyState==4 && xhReq.status==200) {
|
||||
var content = xhReq.responseText;
|
||||
console.log("responseText:" +content);
|
||||
if(content!=undefined && content=='null'){
|
||||
console.log("isFileOverwrite response ok, responseText is null, returning null");
|
||||
return null;
|
||||
}else{
|
||||
console.log("isFileOverwrite response ok, responseText "+content);
|
||||
return content;
|
||||
}
|
||||
|
||||
}else if(xhReq.readyState==4 && xhReq.status!=200){
|
||||
console.log("isFileOverwrite error on status, returning null");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function generateUUID() {
|
||||
|
@ -335,16 +342,6 @@ public class MultipleDNDUpload extends LayoutPanel implements
|
|||
|
||||
//DROP CHECK IF CONTAINS FILES
|
||||
function containsFiles(items) {
|
||||
// if (dataTransfer.types) {
|
||||
// for (var i = 0; i < dataTransfer.types.length; i++) {
|
||||
// console.log("dataTransfer.types[i] "+dataTransfer.types[i]);
|
||||
// if (dataTransfer.types[i] != "Files") {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
|
||||
if (items) {
|
||||
|
||||
for (i = 0; i < items.length; i++) {
|
||||
|
@ -578,8 +575,8 @@ public class MultipleDNDUpload extends LayoutPanel implements
|
|||
console.log("item_name: " + item_name);
|
||||
var params = folder_parent_id+"="+idfolder+"&"+item_name+"="+files[i].name
|
||||
console.log("params: " + params);
|
||||
var response = makeSyncAjaxCall(wsUtil, params, "", "GET");
|
||||
console.log("response: " + response);
|
||||
var response = isFileOverwrite(wsUtil, params, "");
|
||||
console.log("response overwrite: " + response);
|
||||
if(response!=null && response!=undefined){
|
||||
console.log("overwrite confirm?");
|
||||
if($wnd.confirm(files[i].name+" exists in folder. Overwrite?")){
|
||||
|
|
|
@ -65,11 +65,12 @@ import org.json.JSONTokener;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* The Class WorkspaceUploadServletStream.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* @Jan 21, 2014
|
||||
* May 10, 2016
|
||||
*/
|
||||
public class WorkspaceUploadServletStream extends HttpServlet implements Servlet{
|
||||
|
||||
|
@ -138,7 +139,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
|||
logger.debug("GET method CANCEL_UPLOAD "+cancelUpload);
|
||||
if (cancelUpload) {
|
||||
cancelUpload(request.getSession(), clientUploadKey);
|
||||
sendMessage(response, "Upload abort: "+request.getParameter(CANCEL_UPLOAD));
|
||||
sendMessage(response, "Upload aborted "+clientUploadKey);
|
||||
}else
|
||||
logger.debug(CANCEL_UPLOAD + " param not found");
|
||||
// }else
|
||||
|
@ -544,6 +545,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
|||
* @param clientUploadKey the client upload key
|
||||
* @param folderParentId the folder parent id
|
||||
* @param fileName the file name
|
||||
* @param isOverwrite the is overwrite
|
||||
* @return the workspace uploader item
|
||||
*/
|
||||
private WorkspaceUploaderItem createNewWorkspaceUploader(String clientUploadKey, String folderParentId, String fileName, boolean isOverwrite){
|
||||
|
@ -837,6 +839,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
|||
protected void sendMessage(HttpServletResponse response, String message) throws IOException{
|
||||
try {
|
||||
response.setStatus(HttpServletResponse.SC_ACCEPTED);
|
||||
message = message.replaceAll(":", "");
|
||||
HandlerResultMessage resultMessage = HandlerResultMessage.okResult(message);
|
||||
response.getWriter().write(resultMessage.toString());
|
||||
//5.6 Closure of Response Object:
|
||||
|
@ -964,21 +967,4 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
|||
}else
|
||||
logger.warn("Listener "+clientUploadKey+ "is null");
|
||||
}
|
||||
|
||||
/**
|
||||
* The main method.
|
||||
*
|
||||
* @param args the arguments
|
||||
*/
|
||||
/*
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
parseJSONClientUploadKeys("{\"ClientKeys\":[{\"3D6CAAEFF9241F6\":\"bookmarks.xml\"}, {\"69E9907A78AD20B\":\"WFS\"}]}");
|
||||
} catch (FileUploadException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -121,6 +121,9 @@ public class WorkspaceUploaderWsUtil extends HttpServlet {
|
|||
protected void sendOKMessage(HttpServletResponse response, String message) throws IOException{
|
||||
try {
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
response.setContentType("text/xml");
|
||||
if(message==null)
|
||||
message="null";
|
||||
response.getWriter().write(message);
|
||||
//5.6 Closure of Response Object:
|
||||
//When a response is closed, the container must immediately flush all remaining content in the response buffer to the client
|
||||
|
|
|
@ -10,15 +10,18 @@ import java.io.Serializable;
|
|||
* The Class HandlerResultMessage.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Aug 3, 2015
|
||||
* May 10, 2016
|
||||
*/
|
||||
public class HandlerResultMessage implements Serializable{
|
||||
|
||||
|
||||
protected Status status;
|
||||
protected String message;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4607236625671465107L;
|
||||
|
||||
private static final long serialVersionUID = -7652344136772252755L;
|
||||
|
||||
/**
|
||||
* The Enum Status.
|
||||
|
@ -46,6 +49,23 @@ public class HandlerResultMessage implements Serializable{
|
|||
UNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TO SERIALIZATION
|
||||
*/
|
||||
public HandlerResultMessage() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new result message.
|
||||
* @param status the status.
|
||||
* @param message the message.
|
||||
*/
|
||||
public HandlerResultMessage(Status status, String message) {
|
||||
this.status = status;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Error result.
|
||||
*
|
||||
|
@ -78,15 +98,18 @@ public class HandlerResultMessage implements Serializable{
|
|||
|
||||
/**
|
||||
* Parses the result.
|
||||
*
|
||||
* expected status:message (e.g. OK:Upload aborted)
|
||||
* @param result the result
|
||||
* @return the handler result message
|
||||
*/
|
||||
public static HandlerResultMessage parseResult(String result){
|
||||
//expected 200:Upload complete
|
||||
//expected status:message
|
||||
String statusToken = null;
|
||||
String messageToken = null;
|
||||
|
||||
if(result==null || result.isEmpty())
|
||||
return errorResult("result is null or empty");
|
||||
|
||||
int index = result.indexOf(':');
|
||||
if (index>0){
|
||||
statusToken = result.substring(0,index);
|
||||
|
@ -97,29 +120,19 @@ public class HandlerResultMessage implements Serializable{
|
|||
|
||||
Status status = Status.UNKNOWN;
|
||||
if (statusToken!=null){
|
||||
try{
|
||||
status = Status.valueOf(statusToken);
|
||||
}catch (Exception e) {
|
||||
status = Status.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
String message = (messageToken!=null)?messageToken:"";
|
||||
String message = messageToken!=null?messageToken:"";
|
||||
|
||||
return new HandlerResultMessage(status, message);
|
||||
}
|
||||
|
||||
|
||||
protected Status status;
|
||||
protected String message;
|
||||
|
||||
/**
|
||||
* Create a new result message.
|
||||
* @param status the status.
|
||||
* @param message the message.
|
||||
*/
|
||||
public HandlerResultMessage(Status status, String message) {
|
||||
this.status = status;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the status.
|
||||
*
|
||||
|
@ -149,6 +162,4 @@ public class HandlerResultMessage implements Serializable{
|
|||
builder.append(message);
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue