中文乱码问题,待解决

This commit is contained in:
wangwei10061 2017-04-23 20:54:09 +08:00
parent 23659cfb6c
commit b6b21dbc68
4 changed files with 34 additions and 8 deletions

View File

@ -52,7 +52,7 @@ public class GameController extends BaseController {
public JSONObject publishGame (@ApiParam(name = "gameInfo", required = true, value = "游戏信息") @RequestParam String gameInfo) {
logger.debug("***/game/publishGame gameInfo: " + gameInfo);
// 生成脚本
// 生成整个游戏的pipeline脚本
JSONObject response = generatePipelineScriptForGame(gameInfo);
// 写case
@ -84,7 +84,6 @@ public class GameController extends BaseController {
@ApiOperation(value = "生成每一个关卡的脚本", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
@RequestMapping(path = "/generatePipelineScriptForChallenge")
public JSONObject generatePipelineScriptForChallenge (@ApiParam(name = "challengeInfo", required = true, value = "关卡信息") @RequestParam String challengeInfo) {
JSONObject response = new JSONObject();
try {

View File

@ -53,8 +53,35 @@ public class PipeLineController extends BaseController {
Case caseOne=new Case((i + 1) + "", inputs.get(i), outputs.get(i), expectedOuts.get(i), pass);
testInfo.getMsg().add(caseOne);
}
String jsonTestInfo = JSON.toJSONString(testInfo);
// 假如出错
// todo: 中文乱码
// StringBuffer errorInfo = new StringBuffer();
// if("-1".equals(testInfo.getStatus())) {
// errorInfo.append("测试结果不匹配:");
//
// for (int i = 0; i < testInfo.getMsg().size(); i++) {
// if("0".equals(testInfo.getMsg().get(i).getPassed())){
// errorInfo.append("测试集" + testInfo.getMsg().get(i).getCaseId() + "");
// errorInfo.append("期待输出:" + testInfo.getMsg().get(i).getExpectedOutput() + ", 实际输出:" + Base64Helper.decode(testInfo.getMsg().get(i).getOutput()) + " ");
// }
// }
// testInfo.setOutPut(Base64Helper.encode(errorInfo.toString()));
// }
StringBuffer errorInfo = new StringBuffer();
if("-1".equals(testInfo.getStatus()) && "Y29tcGlsZSBzdWNjZXNzZnVsbHk=".equals(compileResult)) {
errorInfo.append("error : ");
for (int i = 0; i < testInfo.getMsg().size(); i++) {
if("0".equals(testInfo.getMsg().get(i).getPassed())){
errorInfo.append("case" + testInfo.getMsg().get(i).getCaseId() + " : ");
errorInfo.append("expected : " + testInfo.getMsg().get(i).getExpectedOutput() + ", but was " + Base64Helper.decode(testInfo.getMsg().get(i).getOutput()) + "; ");
}
}
testInfo.setOutPut(Base64Helper.encode(errorInfo.toString()));
}
String jsonTestInfo = JSON.toJSONString(testInfo);
Map map = new HashMap();
map.put("jsonTestDetails", jsonTestInfo);
trustieApi.commitResultToTrustie(map);

View File

@ -66,7 +66,7 @@ public class HttpHelper {
// 设置通用的请求属性
conn.setRequestProperty("Accept", "*/*");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
// conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestMethod("POST");
@ -85,7 +85,7 @@ public class HttpHelper {
log.debug("POST: "+ url + " DATA: " + data);
OutputStream outputStream = conn.getOutputStream();
outputStream.write(data.getBytes(Charset.forName("UTF-8")));
outputStream.write(data.getBytes());
outputStream.flush();
outputStream.close();

View File

@ -17,9 +17,9 @@ public class PipelineContrillerTest extends SpringTestBase {
String buildId = "1";
String compileResult = "123131";
String in = "[\"12,3\", \"12,4\"]";
String out = "[\"5\", \"6\"]";
String expectedOut = "[\"5\", \"6\"]";
String out = "[\"NQ==\", \"Ng==\"]";
String expectedOut = "[\"1\", \"6\"]";
System.out.println(pipeLineController.postTrainingGameInstanceResultToBDWeb(buildId, compileResult, in, out, expectedOut));
System.out.println(pipeLineController.postTrainingGameInstanceResultToBDWeb(buildId, compileResult, out, in, expectedOut));
}
}