From df948be2ea161dd1ae38fce937cefc07ae6154d8 Mon Sep 17 00:00:00 2001 From: Zellweger Christof Ralf Date: Wed, 20 Jan 2016 11:50:20 +0100 Subject: [PATCH] sf_daq/ch.psi.daq.web#15 create a method which allows a GET request with the JSON object stringified as request parameter --- .../controller/QueryRestController.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/java/ch/psi/daq/queryrest/controller/QueryRestController.java b/src/main/java/ch/psi/daq/queryrest/controller/QueryRestController.java index 18ebfe5..db58502 100644 --- a/src/main/java/ch/psi/daq/queryrest/controller/QueryRestController.java +++ b/src/main/java/ch/psi/daq/queryrest/controller/QueryRestController.java @@ -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 @@ -67,6 +69,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 @@ -157,6 +162,25 @@ public class QueryRestController { throw e; } } + + /** + * 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.