74e33972 by Ean Schuessler

Fix parameter name. Switch to ConcurrentHashMap.

1 parent 4afee607
......@@ -6,6 +6,7 @@ import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.servlet.*;
import javax.servlet.http.*;
......@@ -16,10 +17,8 @@ import org.apache.commons.fileupload.disk.DiskFileItem;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.ofbiz.base.util.HttpClient;
public class NGINXUploadProcessor extends HttpServlet {
class ProgressRecord {
HashMap<String, ProgressRecord> progress;
long bytesRead;
long contentLength;
int items;
......@@ -33,7 +32,7 @@ public class NGINXUploadProcessor extends HttpServlet {
private static final long serialVersionUID = 1L;
private ServletConfig config;
private final HashMap<String, ProgressRecord> progress = new HashMap<String, ProgressRecord>();
private static final ConcurrentHashMap<String, ProgressRecord> progress = new ConcurrentHashMap<String, ProgressRecord>();
@Override
public void destroy() {
......@@ -63,7 +62,7 @@ public class NGINXUploadProcessor extends HttpServlet {
if (request.getRequestURI().contains("progress")) {
PrintWriter out = new PrintWriter(response.getWriter());
String xProgressId = request.getHeader("X-Progress-ID");
System.err.println("PROGRESS: " + xProgressId);
System.err.println("QUERY PROGRESS: [" + xProgressId + "] - " + progress.get(xProgressId));
if (xProgressId != null && progress.get(xProgressId) != null) {
ProgressRecord record = progress.get(xProgressId);
String status = "done";
......@@ -77,6 +76,10 @@ public class NGINXUploadProcessor extends HttpServlet {
}
out.close();
} else {
String xProgressId = request.getParameter("X-Progress-ID");
System.err.println("STORE: [" + xProgressId + "]");
progress.put(xProgressId, new ProgressRecord(-1, 0, 1));
if (ServletFileUpload.isMultipartContent(request)) {
// Create a factory for disk-based file items
DiskFileItemFactory factory = new DiskFileItemFactory();
......@@ -95,8 +98,6 @@ public class NGINXUploadProcessor extends HttpServlet {
PrintWriter out = new PrintWriter(response.getWriter());
try {
Map<String, FileItem> itemMap = new HashMap<String, FileItem>();
String xProgressId = request.getParameter("X-Progress-ID");
System.err.println("STORE: " + xProgressId);
class UploadProgressListener implements ProgressListener {
String xProgressId;
......@@ -114,23 +115,22 @@ public class NGINXUploadProcessor extends HttpServlet {
};
ProgressListener listener = (ProgressListener) new UploadProgressListener(xProgressId, this.progress);
progress.put(xProgressId, new ProgressRecord(-1, 0, 1));
upload.setProgressListener(listener);
List<FileItem> items = (List<FileItem>)upload.parseRequest(request);
for (FileItem item : items) {
itemMap.put(item.getFieldName(), item);
}
HashMap parameters = new HashMap();
parameters.put("path", ((DiskFileItem)itemMap.get("file")).getStoreLocation().getPath());
parameters.put("file.path", ((DiskFileItem)itemMap.get("file")).getStoreLocation().getPath());
parameters.put("X-Progress-ID", xProgressId);
String token = itemMap.get("token").getString();
parameters.put("token", token);
HttpClient http = new HttpClient("http://localhost:8080/bfp/control/upload", parameters);
String pResponse = http.post();
System.err.println("FINISHED:" + pResponse);
out.print(pResponse);
} catch (Exception ex) {
ex.printStackTrace();
......