update post multipart file
This commit is contained in:
parent
18113d3f35
commit
dcf2e9c559
|
@ -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<String, String> headers, String url,
|
||||
String filePartName, List<File> files, String stringPartName,
|
||||
List<String> strings){
|
||||
List<String> 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<String, String> headers, String url,
|
||||
String filePartName, CommonsMultipartFile[] paramFiles, String stringPartName,
|
||||
List<String> strings) {
|
||||
List<File> files=new LinkedList<File>();
|
||||
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<String> strings) throws IOException {
|
||||
List<File> files = new LinkedList<File>();
|
||||
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 {
|
||||
|
|
Loading…
Reference in New Issue