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