create a method which allows a GET request with the JSON object
stringified as request parameter
This commit is contained in:
Zellweger Christof Ralf
2016-01-20 11:50:20 +01:00
parent b55015ab59
commit df948be2ea

View File

@ -23,6 +23,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@ -45,6 +46,7 @@ import ch.psi.daq.query.request.ChannelsRequest;
import ch.psi.daq.queryrest.response.csv.CSVResponseStreamWriter;
import ch.psi.daq.queryrest.response.json.JSONResponseStreamWriter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
@RestController
@ -68,6 +70,9 @@ public class QueryRestController {
@Resource
private ApplicationContext appContext;
@Resource
private ObjectMapper objectMapper;
// using Deferred ensures that data-api startup succeeds even if DataBuffer/ArchiverAppliance is
// not reachable at startup
private Deferred<QueryProcessor> cassandraQueryProcessor = new Deferred<QueryProcessor>(
@ -158,6 +163,25 @@ public class QueryRestController {
}
}
/**
* Accepts the properties for the {@link DAQQuery} instance as stringified JSON query string.
*
* @param jsonBody The {@link DAQQuery} properties sent as a JSON string, i.e. this is the
* stringified body of the POST request method
* @param res the current {@link HttpServletResponse} instance
* @throws Exception if reading the JSON string fails or if the subsequent call to
* {@link #executeQuery(DAQQuery, HttpServletResponse)} fails
*/
@RequestMapping(
value = QUERY,
method = RequestMethod.GET)
public void executeQueryBodyAsString(@RequestParam String jsonBody, HttpServletResponse res) throws Exception {
DAQQuery query = objectMapper.readValue(jsonBody, DAQQuery.class);
executeQuery(query, res);
}
/**
* Returns data in CSV format to the client.
*/