add ways to submit paramFiles to agent

This commit is contained in:
coderfengyun 2014-03-18 15:44:03 +08:00
parent 1576076d75
commit 38b805153c
5 changed files with 32 additions and 2099 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +0,0 @@
-- Adminer 3.7.1 MySQL dump
SET NAMES utf8;
SET foreign_key_checks = 0;
SET time_zone = '+08:00';
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
CREATE DATABASE `bench4q-master-yvAxaJI0` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `bench4q-master-yvAxaJI0`;
-- 2014-01-20 15:37:24

View File

@ -45,6 +45,8 @@ import org.springframework.web.multipart.MultipartFile;
@Controller @Controller
@RequestMapping("/test") @RequestMapping("/test")
public class TestController { public class TestController {
private static final String FILE_SEPARATOR = System
.getProperty("file.separator");
private ScenarioEngine scenarioEngine; private ScenarioEngine scenarioEngine;
private Logger logger = Logger.getLogger(TestController.class); private Logger logger = Logger.getLogger(TestController.class);
@ -61,16 +63,18 @@ public class TestController {
this.scenarioEngine = scenarioEngine; this.scenarioEngine = scenarioEngine;
} }
@RequestMapping(value = "/prepare/{fileName}", method = RequestMethod.POST) @RequestMapping(value = "/submit", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public String prepare(@RequestParam("file") MultipartFile file, public String submitParams(
@PathVariable String fileName) { @RequestParam("files[]") List<MultipartFile> files) {
RunScenarioResultModel result = new RunScenarioResultModel(); RunScenarioResultModel result = new RunScenarioResultModel();
try { try {
File receiveFile = new File("Upload" UUID runId = UUID.randomUUID();
+ System.getProperty("file.separator") + fileName); for (MultipartFile file : files) {
file.transferTo(receiveFile); file.transferTo(new File(guardDirExists(runId)
result.setRunId(UUID.randomUUID()); + file.getOriginalFilename()));
}
result.setRunId(runId);
return MarshalHelper.tryMarshal(result); return MarshalHelper.tryMarshal(result);
} catch (IOException e) { } catch (IOException e) {
logger.error("/prepare/fileName", e); logger.error("/prepare/fileName", e);
@ -78,6 +82,16 @@ public class TestController {
} }
} }
private String guardDirExists(UUID runId) {
String dirPath = "ScenarioParameters" + FILE_SEPARATOR
+ runId.toString() + FILE_SEPARATOR;
File dirFile = new File(dirPath);
if (!dirFile.exists()) {
dirFile.mkdirs();
}
return dirPath;
}
@RequestMapping(value = "/run", method = RequestMethod.POST) @RequestMapping(value = "/run", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public RunScenarioResultModel run( public RunScenarioResultModel run(

View File

@ -12,6 +12,7 @@
<bean id="multipartResolver" <bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="5000000" /> <property name="maxUploadSize" value="5000000" />
<property name="maxInMemorySize" value="5000000" />
</bean> </bean>
</beans> </beans>

View File

@ -4,6 +4,8 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@ -176,11 +178,14 @@ public class TestWithScriptFile {
} }
@Test @Test
public void testPrepare() throws IOException { public void testSubmitParams() throws IOException {
HttpResponse httpResponse = this.getHttpRequester().postMultiFile( List<File> files = new ArrayList<File>();
url + "/prepare/" + "ready.txt", files.add(new File("Scripts" + System.getProperty("file.separator")
"Scripts" + System.getProperty("file.separator") + "forGoodRecord.xml"));
+ "forGoodRecord.xml"); files.add(new File("Scripts" + System.getProperty("file.separator")
+ "testJD.xml"));
HttpResponse httpResponse = this.getHttpRequester().postFiles(
url + "/submit", "files[]", files);
assertNotNull(httpResponse); assertNotNull(httpResponse);
assertNotNull(httpResponse.getContent()); assertNotNull(httpResponse.getContent());
assertEquals(200, httpResponse.getCode()); assertEquals(200, httpResponse.getCode());