From 31570822628c2a081034f476bf697344822b80a7 Mon Sep 17 00:00:00 2001 From: Zellweger Christof Ralf Date: Fri, 3 Jul 2015 16:04:14 +0200 Subject: [PATCH] ATEST-81: - trying to fix bug re react stream and closed queue --- .../java/ch/psi/daq/rest/config/RestConfig.java | 17 ++++++++++++++++- .../daq/rest/response/ResponseStreamWriter.java | 5 +++++ src/main/resources/rest.properties | 4 ++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/psi/daq/rest/config/RestConfig.java b/src/main/java/ch/psi/daq/rest/config/RestConfig.java index 9aa21b3..7b30cdf 100644 --- a/src/main/java/ch/psi/daq/rest/config/RestConfig.java +++ b/src/main/java/ch/psi/daq/rest/config/RestConfig.java @@ -1,15 +1,21 @@ package ch.psi.daq.rest.config; +import java.util.Arrays; +import java.util.List; +import java.util.Set; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.context.annotation.PropertySource; import org.springframework.core.env.Environment; +import org.springframework.util.StringUtils; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.Sets; import ch.psi.daq.common.statistic.StorelessStatistics; import ch.psi.daq.domain.cassandra.ChannelEvent; @@ -56,5 +62,14 @@ public class RestConfig { mapper.addMixIn(StorelessStatistics.class, PropertyFilterMixin.class); return mapper; } - + + @Bean + private Set defaultResponseFields() { + List defaultFields = Arrays.asList( + StringUtils.commaDelimitedListToStringArray( + env.getProperty("rest.default.response.fields") + )); + Set defaultResponseFields = Sets.newHashSet(defaultFields.iterator()); + return defaultResponseFields; + } } diff --git a/src/main/java/ch/psi/daq/rest/response/ResponseStreamWriter.java b/src/main/java/ch/psi/daq/rest/response/ResponseStreamWriter.java index 3a4963a..11a2893 100644 --- a/src/main/java/ch/psi/daq/rest/response/ResponseStreamWriter.java +++ b/src/main/java/ch/psi/daq/rest/response/ResponseStreamWriter.java @@ -39,6 +39,8 @@ public class ResponseStreamWriter { @Autowired private ObjectMapper mapper; + @Autowired + private Set defaultResponseFields; /** * Responding with the the contents of the stream by writing into the output stream of the * {@link ServletResponse}. @@ -51,6 +53,9 @@ public class ResponseStreamWriter { public void respond(Stream stream, AbstractQuery query, ServletResponse response) throws IOException { Set includedFields = query.getFields(); + if (includedFields == null) { + includedFields = defaultResponseFields; + } if (query.getAggregations() != null) { includedFields.addAll(query.getAggregations() diff --git a/src/main/resources/rest.properties b/src/main/resources/rest.properties index 4e97ccf..2b5f02a 100644 --- a/src/main/resources/rest.properties +++ b/src/main/resources/rest.properties @@ -1,2 +1,6 @@ # port for the Spring boot application's embedded Tomcat server server.port=8080 + +# defines the fields that are included in the response +# if no fields have been specified by the user +rest.default.response.fields=channel,pulseId,globalMillis,globalNanos,value \ No newline at end of file