aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2019-07-12 08:56:10 -0500
committerSonarTech <sonartech@sonarsource.com>2019-07-12 20:21:16 +0200
commit5227460bf31c1d5359258d5bf21310246d54d76e (patch)
tree3902ccb7c091c7519ece4f082a18736fda33b355
parent7f1afd8ce4723dad04762837efec3b4b2525dff5 (diff)
downloadsonarqube-5227460bf31c1d5359258d5bf21310246d54d76e.tar.gz
sonarqube-5227460bf31c1d5359258d5bf21310246d54d76e.zip
SONAR-12283 Don't stream response of qualityprofile/export WS
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java10
1 files changed, 7 insertions, 3 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java
index 0e1466d0bca..114baed2168 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java
@@ -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) {