]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12283 Don't stream response of qualityprofile/export WS
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Fri, 12 Jul 2019 13:56:10 +0000 (08:56 -0500)
committerSonarTech <sonartech@sonarsource.com>
Fri, 12 Jul 2019 18:21:16 +0000 (20:21 +0200)
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java

index 0e1466d0bca62edce6a88687de32c742355b2c9a..114baed2168ca358aeeb87f8d1e6eb7907264651 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.qualityprofile.ws;
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
@@ -27,6 +28,7 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Set;
 import javax.annotation.Nullable;
+import org.apache.commons.io.IOUtils;
 import org.sonar.api.profiles.ProfileExporter;
 import org.sonar.api.resources.Languages;
 import org.sonar.api.server.ws.Request;
@@ -131,9 +133,8 @@ public class ExportAction implements QProfileWsAction {
 
   private void writeResponse(DbSession dbSession, QProfileDto profile, @Nullable String exporterKey, Response response) throws IOException {
     Stream stream = response.stream();
-    try (
-      OutputStream output = response.stream().output();
-      Writer writer = new OutputStreamWriter(output, UTF_8)) {
+    ByteArrayOutputStream bufferStream = new ByteArrayOutputStream();
+    try (Writer writer = new OutputStreamWriter(bufferStream, UTF_8)) {
       if (exporterKey == null) {
         stream.setMediaType(MediaTypes.XML);
         backuper.backup(dbSession, profile, writer);
@@ -142,6 +143,9 @@ public class ExportAction implements QProfileWsAction {
         exporters.export(dbSession, profile, exporterKey, writer);
       }
     }
+
+    OutputStream output = response.stream().output();
+    IOUtils.write(bufferStream.toByteArray(), output);
   }
 
   private QProfileDto loadProfile(DbSession dbSession, OrganizationDto organization, @Nullable String key, @Nullable String language, @Nullable String name) {