This commit is contained in:
@ -58,8 +58,7 @@ public class QueryRestConfig extends WebMvcConfigurerAdapter {
|
||||
|
||||
// a nested configuration
|
||||
// this guarantees that the ordering of the properties file is as expected
|
||||
// see:
|
||||
// https://jira.spring.io/browse/SPR-10409?focusedCommentId=101393&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-101393
|
||||
// see: https://jira.spring.io/browse/SPR-10409?focusedCommentId=101393&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-101393
|
||||
@Configuration
|
||||
@Import({QueryConfig.class})
|
||||
static class InnerConfiguration {
|
||||
|
@ -9,6 +9,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
import ch.psi.daq.domain.ResponseFormat;
|
||||
import ch.psi.daq.query.model.impl.DAQQuery;
|
||||
|
||||
|
||||
@ -42,11 +43,13 @@ public abstract class AbstractResponseStreamWriter implements ResponseStreamWrit
|
||||
|
||||
response.addHeader("Content-Type", contentType);
|
||||
if (query.isCompressed()) {
|
||||
response.addHeader("Content-Disposition", "attachment; filename=data.gz");
|
||||
String filename = "data." + query.getCompression().getFileSuffix();
|
||||
response.addHeader("Content-Disposition", "attachment; filename=" + filename);
|
||||
response.addHeader("Content-Encoding", query.getCompression().toString());
|
||||
out = query.getCompression().wrapStream(out);
|
||||
} else {
|
||||
response.addHeader("Content-Disposition", "attachment; filename=data.csv");
|
||||
String filename = "data." + (query.getResponseFormat() == ResponseFormat.CSV ? "csv" : "json");
|
||||
response.addHeader("Content-Disposition", "attachment; filename=" + filename);
|
||||
}
|
||||
|
||||
return out;
|
||||
|
@ -37,7 +37,6 @@ import ch.psi.daq.query.model.QueryField;
|
||||
import ch.psi.daq.query.model.impl.DAQQuery;
|
||||
import ch.psi.daq.queryrest.controller.QueryRestController;
|
||||
import ch.psi.daq.queryrest.filter.CorsFilter;
|
||||
import ch.psi.daq.queryrest.response.AbstractResponseStreamWriter;
|
||||
import ch.psi.daq.test.cassandra.admin.CassandraTestAdmin;
|
||||
import ch.psi.daq.test.queryrest.AbstractDaqRestTest;
|
||||
|
||||
@ -601,4 +600,50 @@ public class QueryRestControllerCsvTest extends AbstractDaqRestTest {
|
||||
mapReader.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGzipFileSuffixHeader() throws Exception {
|
||||
DAQQuery request = new DAQQuery(
|
||||
new RequestRangePulseId(
|
||||
10,
|
||||
11),
|
||||
TEST_CHANNEL_NAMES);
|
||||
request.setResponseFormat(ResponseFormat.CSV);
|
||||
request.setCompression(Compression.GZIP);
|
||||
|
||||
String content = mapper.writeValueAsString(request);
|
||||
|
||||
this.mockMvc
|
||||
.perform(MockMvcRequestBuilders
|
||||
.post(QueryRestController.QUERY)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(content))
|
||||
|
||||
.andDo(MockMvcResultHandlers.print())
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andExpect(MockMvcResultMatchers.header().string("Content-Disposition", "attachment; filename=data.gz"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsonFileSuffixHeader() throws Exception {
|
||||
DAQQuery request = new DAQQuery(
|
||||
new RequestRangePulseId(
|
||||
10,
|
||||
11),
|
||||
TEST_CHANNEL_NAMES);
|
||||
request.setResponseFormat(ResponseFormat.CSV);
|
||||
request.setCompression(Compression.NONE);
|
||||
|
||||
String content = mapper.writeValueAsString(request);
|
||||
|
||||
this.mockMvc
|
||||
.perform(MockMvcRequestBuilders
|
||||
.post(QueryRestController.QUERY)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(content))
|
||||
|
||||
.andDo(MockMvcResultHandlers.print())
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andExpect(MockMvcResultMatchers.header().string("Content-Disposition", "attachment; filename=data.csv"));
|
||||
}
|
||||
}
|
||||
|
@ -443,16 +443,15 @@ public class QueryRestControllerJsonTest extends AbstractDaqRestTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeflateCompression() throws Exception {
|
||||
public void testGzipFileSuffixHeader() throws Exception {
|
||||
DAQQuery request = new DAQQuery(
|
||||
new RequestRangePulseId(
|
||||
10,
|
||||
11),
|
||||
TEST_CHANNEL_NAMES);
|
||||
request.setCompression(Compression.DEFLATE);
|
||||
request.setCompression(Compression.GZIP);
|
||||
|
||||
String content = mapper.writeValueAsString(request);
|
||||
System.out.println(content);
|
||||
|
||||
this.mockMvc
|
||||
.perform(MockMvcRequestBuilders
|
||||
@ -461,7 +460,30 @@ public class QueryRestControllerJsonTest extends AbstractDaqRestTest {
|
||||
.content(content))
|
||||
|
||||
.andDo(MockMvcResultHandlers.print())
|
||||
.andExpect(MockMvcResultMatchers.status().isOk());
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andExpect(MockMvcResultMatchers.header().string("Content-Disposition", "attachment; filename=data.gz"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsonFileSuffixHeader() throws Exception {
|
||||
DAQQuery request = new DAQQuery(
|
||||
new RequestRangePulseId(
|
||||
10,
|
||||
11),
|
||||
TEST_CHANNEL_NAMES);
|
||||
request.setCompression(Compression.NONE);
|
||||
|
||||
String content = mapper.writeValueAsString(request);
|
||||
|
||||
this.mockMvc
|
||||
.perform(MockMvcRequestBuilders
|
||||
.post(QueryRestController.QUERY)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(content))
|
||||
|
||||
.andDo(MockMvcResultHandlers.print())
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andExpect(MockMvcResultMatchers.header().string("Content-Disposition", "attachment; filename=data.json"));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user