diff --git a/Bench4Q-Share/src/main/java/org/bench4q/share/communication/HttpRequester.java b/Bench4Q-Share/src/main/java/org/bench4q/share/communication/HttpRequester.java index 0be1ec73..355d1bb0 100644 --- a/Bench4Q-Share/src/main/java/org/bench4q/share/communication/HttpRequester.java +++ b/Bench4Q-Share/src/main/java/org/bench4q/share/communication/HttpRequester.java @@ -22,11 +22,11 @@ import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.multipart.FilePart; import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity; import org.apache.commons.httpclient.methods.multipart.Part; -import org.apache.commons.httpclient.methods.multipart.PartSource; import org.apache.commons.httpclient.methods.multipart.StringPart; +import org.apache.log4j.Logger; +import org.bench4q.share.helper.ExceptionLog; import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.multipart.commons.CommonsMultipartFile; @Component public class HttpRequester { @@ -118,7 +118,7 @@ public class HttpRequester { public HttpResponse postFiles(Map headers, String url, String filePartName, List files, String stringPartName, - List strings){ + List strings) { if (!url.startsWith("http")) url = "http://" + url; PostMethod postMethod = new PostMethod(url); @@ -150,24 +150,21 @@ public class HttpRequester { postMethod.releaseConnection(); } } + public HttpResponse postFilesMulti(Map headers, String url, - String filePartName, CommonsMultipartFile[] paramFiles, String stringPartName, - List strings) { - List files=new LinkedList(); - for(CommonsMultipartFile commonsMultipartFile:paramFiles){ - File file=new File("paramFile.txt"); - try { - commonsMultipartFile.transferTo(file); - - files.add(file); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - return null; + String filePartName, MultipartFile[] multipartFiles, + String stringPartName, List strings) throws IOException { + List files = new LinkedList(); + if (multipartFiles != null) { + for (MultipartFile multipartFile : multipartFiles) { + File file = new File("paramFile.txt"); + multipartFile.transferTo(file); + files.add(file); + } - } - return postFiles(headers, url, filePartName, files, stringPartName, strings); + return postFiles(headers, url, filePartName, files, stringPartName, + strings); } private HttpResponse send(String urlString, String method, @@ -234,12 +231,15 @@ public class HttpRequester { return buildHttpResponse(urlConnection, readConnectionInputStream(in)); } catch (IOException e) { - e.printStackTrace(); + Logger.getLogger(HttpRequester.class).info( + ExceptionLog.getStackTrace(e)); in = urlConnection.getErrorStream(); try { return buildHttpResponse(urlConnection, readConnectionInputStream(in)); } catch (Exception e1) { + Logger.getLogger(HttpRequester.class).info( + ExceptionLog.getStackTrace(e1)); return getDefaultErrorResponse(); } } finally {