c6e31085 by Ean Schuessler

Do not change status to "done" until the OFBiz service call returns

1 parent 707be16d
...@@ -19,6 +19,7 @@ import org.ofbiz.base.util.HttpClient; ...@@ -19,6 +19,7 @@ import org.ofbiz.base.util.HttpClient;
19 19
20 public class NGINXUploadProcessor extends HttpServlet { 20 public class NGINXUploadProcessor extends HttpServlet {
21 class ProgressRecord { 21 class ProgressRecord {
22 boolean complete = false;
22 long bytesRead; 23 long bytesRead;
23 long contentLength; 24 long contentLength;
24 int items; 25 int items;
...@@ -65,12 +66,8 @@ public class NGINXUploadProcessor extends HttpServlet { ...@@ -65,12 +66,8 @@ public class NGINXUploadProcessor extends HttpServlet {
65 System.err.println("QUERY PROGRESS: [" + xProgressId + "] - " + progress.get(xProgressId)); 66 System.err.println("QUERY PROGRESS: [" + xProgressId + "] - " + progress.get(xProgressId));
66 if (xProgressId != null && progress.get(xProgressId) != null) { 67 if (xProgressId != null && progress.get(xProgressId) != null) {
67 ProgressRecord record = progress.get(xProgressId); 68 ProgressRecord record = progress.get(xProgressId);
68 String status = "done"; 69 out.println("({ \"state\" : \""+ (record.complete ? "done" : "uploading") +"\", \"received\" : " +
69 if (record.bytesRead < record.contentLength) { 70 record.bytesRead + ", \"size\" : " + record.contentLength + " });");
70 status = "uploading";
71 }
72 out.println("({ \"state\" : \""+ status +"\", \"received\" : " +
73 record.bytesRead + ", \"size\" : " + record.contentLength + " });");
74 } else { 71 } else {
75 out.println("({ \"error\" : \"Invalid X-Progress-ID\" });"); 72 out.println("({ \"error\" : \"Invalid X-Progress-ID\" });");
76 } 73 }
...@@ -132,6 +129,8 @@ public class NGINXUploadProcessor extends HttpServlet { ...@@ -132,6 +129,8 @@ public class NGINXUploadProcessor extends HttpServlet {
132 String pResponse = http.post(); 129 String pResponse = http.post();
133 System.err.println("FINISHED:" + pResponse); 130 System.err.println("FINISHED:" + pResponse);
134 out.print(pResponse); 131 out.print(pResponse);
132
133 progress.get(xProgressId).complete = true;
135 } catch (Exception ex) { 134 } catch (Exception ex) {
136 ex.printStackTrace(); 135 ex.printStackTrace();
137 } 136 }
......