Merge branch 'BF-6039' of /home/git/repositories/brainfood/ofbiz-directcontrolservlet
Showing
1 changed file
with
30 additions
and
2 deletions
... | @@ -6,6 +6,7 @@ import java.io.BufferedReader; | ... | @@ -6,6 +6,7 @@ import java.io.BufferedReader; |
6 | import java.io.StringReader; | 6 | import java.io.StringReader; |
7 | import java.io.InputStreamReader; | 7 | import java.io.InputStreamReader; |
8 | import java.io.InputStream; | 8 | import java.io.InputStream; |
9 | import java.io.File; | ||
9 | import java.util.Collections; | 10 | import java.util.Collections; |
10 | import java.util.Collection; | 11 | import java.util.Collection; |
11 | import java.util.Map; | 12 | import java.util.Map; |
... | @@ -34,6 +35,7 @@ import javax.servlet.http.HttpServletRequest; | ... | @@ -34,6 +35,7 @@ import javax.servlet.http.HttpServletRequest; |
34 | import javax.servlet.http.HttpServletResponse; | 35 | import javax.servlet.http.HttpServletResponse; |
35 | import javax.servlet.http.HttpSession; | 36 | import javax.servlet.http.HttpSession; |
36 | import javax.servlet.http.Cookie; | 37 | import javax.servlet.http.Cookie; |
38 | import javax.servlet.http.Part; | ||
37 | 39 | ||
38 | import org.ofbiz.base.util.Debug; | 40 | import org.ofbiz.base.util.Debug; |
39 | import org.ofbiz.base.util.GroovyUtil; | 41 | import org.ofbiz.base.util.GroovyUtil; |
... | @@ -59,6 +61,11 @@ import org.ofbiz.service.ServiceContainer; | ... | @@ -59,6 +61,11 @@ import org.ofbiz.service.ServiceContainer; |
59 | import org.apache.commons.csv.CSVFormat; | 61 | import org.apache.commons.csv.CSVFormat; |
60 | import org.apache.commons.csv.CSVRecord; | 62 | import org.apache.commons.csv.CSVRecord; |
61 | 63 | ||
64 | import org.apache.commons.fileupload.*; | ||
65 | import org.apache.commons.fileupload.disk.DiskFileItemFactory; | ||
66 | import org.apache.commons.fileupload.disk.DiskFileItem; | ||
67 | import org.apache.commons.fileupload.servlet.ServletFileUpload; | ||
68 | |||
62 | import groovy.lang.GroovyClassLoader; | 69 | import groovy.lang.GroovyClassLoader; |
63 | import groovy.lang.Script; | 70 | import groovy.lang.Script; |
64 | 71 | ||
... | @@ -74,9 +81,11 @@ public class DirectControlServlet extends HttpServlet { | ... | @@ -74,9 +81,11 @@ public class DirectControlServlet extends HttpServlet { |
74 | public static final Map<String, String> serviceURLMappings = new HashMap<String, String>(); | 81 | public static final Map<String, String> serviceURLMappings = new HashMap<String, String>(); |
75 | private String sessionTokenName = "_AUTHTOKEN"; | 82 | private String sessionTokenName = "_AUTHTOKEN"; |
76 | private String checkSessionService; | 83 | private String checkSessionService; |
84 | private ServletConfig config; | ||
77 | 85 | ||
78 | public void init(ServletConfig config) throws ServletException { | 86 | public void init(ServletConfig config) throws ServletException { |
79 | // get the mapping file for this webapp | 87 | // get the mapping file for this webapp |
88 | this.config = config; | ||
80 | ServletContext context = config.getServletContext(); | 89 | ServletContext context = config.getServletContext(); |
81 | String mappingFile = context.getInitParameter("serviceURLMappings"); | 90 | String mappingFile = context.getInitParameter("serviceURLMappings"); |
82 | Debug.logInfo("Mapping file: " + mappingFile, module); | 91 | Debug.logInfo("Mapping file: " + mappingFile, module); |
... | @@ -168,6 +177,25 @@ public class DirectControlServlet extends HttpServlet { | ... | @@ -168,6 +177,25 @@ public class DirectControlServlet extends HttpServlet { |
168 | data.add(row); | 177 | data.add(row); |
169 | } | 178 | } |
170 | context.put("data", data); | 179 | context.put("data", data); |
180 | } else if (contentType != null && contentType.indexOf("multipart/form-data") != -1) { | ||
181 | // Create a factory for disk-based file items | ||
182 | DiskFileItemFactory factory = new DiskFileItemFactory(); | ||
183 | |||
184 | // Configure a repository (to ensure a secure temp location is used) | ||
185 | ServletContext servletContext = config.getServletContext(); | ||
186 | File repository = (File) servletContext | ||
187 | .getAttribute("javax.servlet.context.tempdir"); | ||
188 | factory.setRepository(repository); | ||
189 | |||
190 | ServletFileUpload upload = new ServletFileUpload(factory); | ||
191 | |||
192 | //Map<String, FileItem> itemMap = new HashMap<String, FileItem>(); | ||
193 | |||
194 | List<FileItem> items = (List<FileItem>)upload.parseRequest(request); | ||
195 | for (FileItem item : items) { | ||
196 | Debug.logInfo("PART: " + item.getFieldName(), module); | ||
197 | context.put(item.getFieldName(), item.getString()); | ||
198 | } | ||
171 | } else { | 199 | } else { |
172 | // Check if the request is a backbone style "emulateJSON" request | 200 | // Check if the request is a backbone style "emulateJSON" request |
173 | if (contentType != null && contentType.indexOf("x-www-form-urlencoded") != -1 && request.getParameter("model") != null) { | 201 | if (contentType != null && contentType.indexOf("x-www-form-urlencoded") != -1 && request.getParameter("model") != null) { |
... | @@ -301,10 +329,10 @@ public class DirectControlServlet extends HttpServlet { | ... | @@ -301,10 +329,10 @@ public class DirectControlServlet extends HttpServlet { |
301 | response.setContentType("text/csv"); | 329 | response.setContentType("text/csv"); |
302 | 330 | ||
303 | // Find the first list | 331 | // Find the first list |
304 | List resList = null; | 332 | List<Map> resList = null; |
305 | for (Object o : result.values()) { | 333 | for (Object o : result.values()) { |
306 | if (o instanceof List) { | 334 | if (o instanceof List) { |
307 | resList = (List) o; | 335 | resList = (List<Map>) o; |
308 | break; | 336 | break; |
309 | } | 337 | } |
310 | } | 338 | } | ... | ... |
-
Please register or sign in to post a comment