From 24ffcd69257525ff894c50d00296d6eb5c430369 Mon Sep 17 00:00:00 2001 From: fanfuxiaoran <495538672@qq.com> Date: Sun, 4 May 2014 17:25:22 +0800 Subject: [PATCH] refactor the post multipartfile --- .../share/communication/HttpRequester.java | 8 +- .../share/models/master/UserModel.java | 101 +++++++++--------- 2 files changed, 58 insertions(+), 51 deletions(-) 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 355d1bb0..9d8d6e3e 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 @@ -134,7 +134,9 @@ public class HttpRequester { } Part[] parts = new Part[files.size() + strings.size()]; for (int i = 0; i < files.size(); i++) { - parts[i] = new FilePart(filePartName, files.get(i)); + FilePart filePart = new FilePart(filePartName, files.get(i) + .getName(), files.get(i)); + parts[i] = filePart; } for (int i = 0; i < strings.size(); i++) { parts[i + files.size()] = new StringPart(stringPartName, @@ -157,14 +159,16 @@ public class HttpRequester { List files = new LinkedList(); if (multipartFiles != null) { for (MultipartFile multipartFile : multipartFiles) { - File file = new File("paramFile.txt"); + File file = new File(multipartFile.getOriginalFilename()); multipartFile.transferTo(file); files.add(file); } } + return postFiles(headers, url, filePartName, files, stringPartName, strings); + } private HttpResponse send(String urlString, String method, diff --git a/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/UserModel.java b/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/UserModel.java index 9c65c2bd..3e810229 100644 --- a/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/UserModel.java +++ b/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/UserModel.java @@ -1,49 +1,52 @@ -package org.bench4q.share.models.master; - -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - -@XmlRootElement(name = "user") -public class UserModel { - private int id; - private String userName; - private String password; - private byte scope; - - @XmlElement - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - @XmlElement - public String getUserName() { - return userName; - } - - public void setUserName(String userName) { - this.userName = userName; - } - - @XmlElement - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - @XmlElement - public byte getScope() { - return scope; - } - - public void setScope(byte scope) { - this.scope = scope; - } - -} +package org.bench4q.share.models.master; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "user") +public class UserModel { + private int id; + private String userName; + private String password; + private byte scope; + + public UserModel(){ + + } + @XmlElement + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @XmlElement + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + @XmlElement + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + @XmlElement + public byte getScope() { + return scope; + } + + public void setScope(byte scope) { + this.scope = scope; + } + +}