|
@@ -1,6 +1,7 @@
|
|
|
package cn.com.qmth.examcloud.web.support;
|
|
|
|
|
|
import java.util.Collection;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
@@ -14,8 +15,13 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.api.commons.CloudService;
|
|
|
import cn.com.qmth.examcloud.api.commons.exchange.BaseResponse;
|
|
|
+import cn.com.qmth.examcloud.api.commons.exchange.FormFilePart;
|
|
|
+import cn.com.qmth.examcloud.api.commons.exchange.FormRequest;
|
|
|
import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
|
|
|
import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
|
|
|
import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
|
|
@@ -129,6 +135,10 @@ public class ControllerAspect {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if (isRpcRequest(request)) {
|
|
|
+ processFormFileParts(request, args);
|
|
|
+ }
|
|
|
+
|
|
|
Object ret = null;
|
|
|
try {
|
|
|
if (null != httpMethodProcessor) {
|
|
@@ -232,4 +242,46 @@ public class ControllerAspect {
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 处理表单请求中的文件
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param request
|
|
|
+ * @param args
|
|
|
+ */
|
|
|
+ private void processFormFileParts(HttpServletRequest request, Object[] args) {
|
|
|
+ for (int i = 0; i < args.length; i++) {
|
|
|
+ Object curArg = args[i];
|
|
|
+ if (curArg instanceof FormRequest) {
|
|
|
+ FormRequest formReq = (FormRequest) curArg;
|
|
|
+ List<FormFilePart> formFilePartList = formReq.getFormFilePartList();
|
|
|
+ if (null == formFilePartList) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
+ for (FormFilePart formFilePart : formFilePartList) {
|
|
|
+ MultipartFile file = multipartRequest.getFile(formFilePart.getParamName());
|
|
|
+ System.out.println(file);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否是RPC
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean isRpcRequest(HttpServletRequest request) {
|
|
|
+ ApiInfo apiInfo = (ApiInfo) request
|
|
|
+ .getAttribute(HttpServletRequestAttribute.$_API_INFO.name());
|
|
|
+ if (null == apiInfo) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Class<?> ctrClass = apiInfo.getBeanType();
|
|
|
+ return CloudService.class.isAssignableFrom(ctrClass);
|
|
|
+ }
|
|
|
+
|
|
|
}
|