ab099caf by Ean Schuessler

Replace tabs with 4 spaces.

1 parent 707be16d
...@@ -18,47 +18,47 @@ import org.apache.commons.fileupload.servlet.ServletFileUpload; ...@@ -18,47 +18,47 @@ import org.apache.commons.fileupload.servlet.ServletFileUpload;
18 import org.ofbiz.base.util.HttpClient; 18 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 long bytesRead; 22 long bytesRead;
23 long contentLength; 23 long contentLength;
24 int items; 24 int items;
25 25
26 public ProgressRecord(long bytesRead, long contentLength, int items) { 26 public ProgressRecord(long bytesRead, long contentLength, int items) {
27 this.bytesRead = bytesRead; 27 this.bytesRead = bytesRead;
28 this.contentLength = contentLength; 28 this.contentLength = contentLength;
29 this.items = items; 29 this.items = items;
30 } 30 }
31 } 31 }
32 32
33 private static final long serialVersionUID = 1L; 33 private static final long serialVersionUID = 1L;
34 private ServletConfig config; 34 private ServletConfig config;
35 private static final ConcurrentHashMap<String, ProgressRecord> progress = new ConcurrentHashMap<String, ProgressRecord>(); 35 private static final ConcurrentHashMap<String, ProgressRecord> progress = new ConcurrentHashMap<String, ProgressRecord>();
36 36
37 @Override 37 @Override
38 public void destroy() { 38 public void destroy() {
39 // TODO Auto-generated method stub 39 // TODO Auto-generated method stub
40 } 40 }
41 41
42 @Override 42 @Override
43 public ServletConfig getServletConfig() { 43 public ServletConfig getServletConfig() {
44 // TODO Auto-generated method stub 44 // TODO Auto-generated method stub
45 return this.config; 45 return this.config;
46 } 46 }
47 47
48 @Override 48 @Override
49 public String getServletInfo() { 49 public String getServletInfo() {
50 // TODO Auto-generated method stub 50 // TODO Auto-generated method stub
51 return null; 51 return null;
52 } 52 }
53 53
54 @Override 54 @Override
55 public void init(ServletConfig config) throws ServletException { 55 public void init(ServletConfig config) throws ServletException {
56 this.config = config; 56 this.config = config;
57 } 57 }
58 58
59 @Override 59 @Override
60 public void service(HttpServletRequest request, HttpServletResponse response) 60 public void service(HttpServletRequest request, HttpServletResponse response)
61 throws ServletException, IOException { 61 throws ServletException, IOException {
62 if (request.getRequestURI().contains("progress")) { 62 if (request.getRequestURI().contains("progress")) {
63 PrintWriter out = new PrintWriter(response.getWriter()); 63 PrintWriter out = new PrintWriter(response.getWriter());
64 String xProgressId = request.getHeader("X-Progress-ID"); 64 String xProgressId = request.getHeader("X-Progress-ID");
...@@ -70,7 +70,7 @@ public class NGINXUploadProcessor extends HttpServlet { ...@@ -70,7 +70,7 @@ public class NGINXUploadProcessor extends HttpServlet {
70 status = "uploading"; 70 status = "uploading";
71 } 71 }
72 out.println("({ \"state\" : \""+ status +"\", \"received\" : " + 72 out.println("({ \"state\" : \""+ status +"\", \"received\" : " +
73 record.bytesRead + ", \"size\" : " + record.contentLength + " });"); 73 record.bytesRead + ", \"size\" : " + record.contentLength + " });");
74 } else { 74 } else {
75 out.println("({ \"error\" : \"Invalid X-Progress-ID\" });"); 75 out.println("({ \"error\" : \"Invalid X-Progress-ID\" });");
76 } 76 }
...@@ -78,7 +78,7 @@ public class NGINXUploadProcessor extends HttpServlet { ...@@ -78,7 +78,7 @@ public class NGINXUploadProcessor extends HttpServlet {
78 } else { 78 } else {
79 String xProgressId = request.getParameter("X-Progress-ID"); 79 String xProgressId = request.getParameter("X-Progress-ID");
80 System.err.println("STORE: [" + xProgressId + "]"); 80 System.err.println("STORE: [" + xProgressId + "]");
81 progress.put(xProgressId, new ProgressRecord(-1, 0, 1)); 81 progress.put(xProgressId, new ProgressRecord(-1, 0, 1));
82 82
83 if (ServletFileUpload.isMultipartContent(request)) { 83 if (ServletFileUpload.isMultipartContent(request)) {
84 // Create a factory for disk-based file items 84 // Create a factory for disk-based file items
...@@ -97,29 +97,29 @@ public class NGINXUploadProcessor extends HttpServlet { ...@@ -97,29 +97,29 @@ public class NGINXUploadProcessor extends HttpServlet {
97 // Parse the request 97 // Parse the request
98 PrintWriter out = new PrintWriter(response.getWriter()); 98 PrintWriter out = new PrintWriter(response.getWriter());
99 try { 99 try {
100 Map<String, FileItem> itemMap = new HashMap<String, FileItem>(); 100 Map<String, FileItem> itemMap = new HashMap<String, FileItem>();
101 101
102 class UploadProgressListener implements ProgressListener { 102 class UploadProgressListener implements ProgressListener {
103 String xProgressId; 103 String xProgressId;
104 Map<String, ProgressRecord> progress; 104 Map<String, ProgressRecord> progress;
105 105
106 public UploadProgressListener(String xProgressId, Map<String, ProgressRecord> progress) { 106 public UploadProgressListener(String xProgressId, Map<String, ProgressRecord> progress) {
107 this.xProgressId = xProgressId; 107 this.xProgressId = xProgressId;
108 this.progress = progress; 108 this.progress = progress;
109 } 109 }
110 @Override 110 @Override
111 public void update(long sent, long length, int items) { 111 public void update(long sent, long length, int items) {
112 System.err.println("PROGRESS: " + sent + " " + length + " " + items); 112 System.err.println("PROGRESS: " + sent + " " + length + " " + items);
113 progress.put(xProgressId, new ProgressRecord(sent, length, items)); 113 progress.put(xProgressId, new ProgressRecord(sent, length, items));
114 } 114 }
115 }; 115 };
116 116
117 ProgressListener listener = (ProgressListener) new UploadProgressListener(xProgressId, this.progress); 117 ProgressListener listener = (ProgressListener) new UploadProgressListener(xProgressId, this.progress);
118 upload.setProgressListener(listener); 118 upload.setProgressListener(listener);
119 List<FileItem> items = (List<FileItem>)upload.parseRequest(request); 119 List<FileItem> items = (List<FileItem>)upload.parseRequest(request);
120 120
121 for (FileItem item : items) { 121 for (FileItem item : items) {
122 itemMap.put(item.getFieldName(), item); 122 itemMap.put(item.getFieldName(), item);
123 } 123 }
124 124
125 HashMap parameters = new HashMap(); 125 HashMap parameters = new HashMap();
...@@ -142,5 +142,5 @@ public class NGINXUploadProcessor extends HttpServlet { ...@@ -142,5 +142,5 @@ public class NGINXUploadProcessor extends HttpServlet {
142 out.close(); 142 out.close();
143 } 143 }
144 } 144 }
145 } 145 }
146 } 146 }
......