]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9488 handle upload error as missing param in api/ce/submit
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 10 Jul 2017 14:15:39 +0000 (16:15 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Fri, 21 Jul 2017 10:20:52 +0000 (12:20 +0200)
server/sonar-server/src/main/java/org/sonar/server/ce/ws/SubmitAction.java
server/sonar-server/src/test/java/org/sonar/server/ce/ws/SubmitActionTest.java

index ab38090c4f64a21c2e0fe534d23be70455293152..eca4c5d48140aab95f2b5bcbe5b9e4288dc2a57f 100644 (file)
@@ -96,15 +96,13 @@ public class SubmitAction implements CeWsAction {
     String projectBranch = wsRequest.param(PARAM_PROJECT_BRANCH);
     String projectName = StringUtils.defaultIfBlank(wsRequest.param(PARAM_PROJECT_NAME), projectKey);
 
-    CeTask task;
-    try (InputStream report = new BufferedInputStream(wsRequest.paramAsInputStream(PARAM_REPORT_DATA))) {
-      task = reportSubmitter.submit(organizationKey, projectKey, projectBranch, projectName, report);
+    try (InputStream report = new BufferedInputStream(wsRequest.mandatoryParamAsPart(PARAM_REPORT_DATA).getInputStream())) {
+      CeTask task = reportSubmitter.submit(organizationKey, projectKey, projectBranch, projectName, report);
+      WsCe.SubmitResponse submitResponse = WsCe.SubmitResponse.newBuilder()
+        .setTaskId(task.getUuid())
+        .setProjectId(task.getComponentUuid())
+        .build();
+      WsUtils.writeProtobuf(submitResponse, wsRequest, wsResponse);
     }
-
-    WsCe.SubmitResponse submitResponse = WsCe.SubmitResponse.newBuilder()
-      .setTaskId(task.getUuid())
-      .setProjectId(task.getComponentUuid())
-      .build();
-    WsUtils.writeProtobuf(submitResponse, wsRequest, wsResponse);
   }
 }
index e719bf738ea4ce78469d4cfce4dd33864840ffdd..18635d71ac154410ccd3e743ad0a9a587d6143f9 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.ce.ws;
 
+import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import org.junit.Test;
 import org.mockito.Matchers;
@@ -63,7 +64,7 @@ public class SubmitActionTest {
     WsCe.SubmitResponse submitResponse = tester.newRequest()
       .setParam("projectKey", "my_project")
       .setParam("projectName", "My Project")
-      .setParam("report", "{binary}")
+      .setPart("report", new ByteArrayInputStream("{binary}".getBytes()), "foo.bar")
       .setMethod("POST")
       .executeProtobuf(WsCe.SubmitResponse.class);
 
@@ -81,7 +82,7 @@ public class SubmitActionTest {
     TestResponse wsResponse = tester.newRequest()
       .setParam("projectKey", "my_project")
       .setParam("projectName", "My Project")
-      .setParam("report", "{binary}")
+      .setPart("report", new ByteArrayInputStream("{binary}".getBytes()), "foo.bar")
       .setMediaType(MediaTypes.JSON)
       .setMethod("POST")
       .execute();
@@ -99,7 +100,7 @@ public class SubmitActionTest {
 
     tester.newRequest()
       .setParam("projectKey", "my_project")
-      .setParam("report", "{binary}")
+      .setPart("report", new ByteArrayInputStream("{binary}".getBytes()), "foo.bar")
       .setMediaType(MediaTypes.PROTOBUF)
       .setMethod("POST")
       .execute();