spring-web

Can I use @Requestparam annotation for a Post request?

点点圈 提交于 2019-11-28 23:39:59
I have this controller method: @PostMapping( value = "/createleave", params = {"start","end","hours","username"}) public void createLeave(@RequestParam(value = "start") String start, @RequestParam(value = "end") String end, @RequestParam(value = "hours") String hours, @RequestParam(value = "username") String username){ System.out.println("Entering createLeave " + start + " " + end + " " + hours + " " + username); LeaveQuery newLeaveQuery = new LeaveQuery(); Account account = accountRepository.findByUsername(username); newLeaveQuery.setAccount(account); newLeaveQuery.setStartDate(new Date(Long

Overriding beans in Integration tests

你。 提交于 2019-11-28 17:31:12
For my Spring-Boot app I provide a RestTemplate though a @Configuration file so I can add sensible defaults(ex Timeouts). For my integration tests I would like to mock the RestTemplate as I dont want to connect to external services - I know what responses to expect. I tried providing a different implementation in the integration-test package in the hope that the latter will override the real implementation , but checking the logs it`s the other way around : the real implementation overrides the test one. How can I make sure the one from the TestConfig is the one used? This is my config file :

How to test DeferredResult timeoutResult

不想你离开。 提交于 2019-11-27 23:44:18
问题 I'm implementing long polling as per the Spring blog from some time ago. Here my converted method with same response signature as before, but instead of responding immediately, it now uses long polling: private Map<String, DeferredResult<ResponseEntity<?>>> requests = new ConcurrentHashMap<>(); @RequestMapping(value = "/{uuid}", method = RequestMethod.GET) public DeferredResult<ResponseEntity<?>> poll(@PathVariable("uuid") final String uuid) { // Create & store a new instance ResponseEntity<?

How to parse gzip encoded response with RestTemplate from Spring-Web

拜拜、爱过 提交于 2019-11-27 20:16:43
After I modified Consuming a RESTful Web Service example to call get users by id from api.stackexchange.com I get JsonParseException: com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is allowed between tokens Response from api.stackexchange.com is gzip compressed. How to add support for gzip compressed response into Spring-Web RestTemplate? I am using Spring boot parent ver. 1.3.1.RELEASE hence Spring-Web 4.2.4-RELEASE Here’s my adjusted example: User.java package stackexchange.dto; import com.fasterxml.jackson

Spring's @RequestParam with Enum

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 17:58:05
I have this enum : public enum SortEnum { asc, desc; } That I want to use as a parameter of a rest request : @RequestMapping(value = "/events", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public List<Event> getEvents(@RequestParam(name = "sort", required = false) SortEnum sort) { It works fine when I send these requests /events /events?sort=asc /events?sort=desc But when I send : /events?sort=somethingElse I get a 500 response and this message in the console : 2016-09-29 17:20:51.600 DEBUG 5104 --- [ XNIO-2 task-6] com.myApp.aop.logging.LoggingAspect : Enter: com

Overriding beans in Integration tests

笑着哭i 提交于 2019-11-27 10:30:15
问题 For my Spring-Boot app I provide a RestTemplate though a @Configuration file so I can add sensible defaults(ex Timeouts). For my integration tests I would like to mock the RestTemplate as I dont want to connect to external services - I know what responses to expect. I tried providing a different implementation in the integration-test package in the hope that the latter will override the real implementation , but checking the logs it`s the other way around : the real implementation overrides

Spring's @RequestParam with Enum

泪湿孤枕 提交于 2019-11-27 04:15:38
问题 I have this enum : public enum SortEnum { asc, desc; } That I want to use as a parameter of a rest request : @RequestMapping(value = "/events", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public List<Event> getEvents(@RequestParam(name = "sort", required = false) SortEnum sort) { It works fine when I send these requests /events /events?sort=asc /events?sort=desc But when I send : /events?sort=somethingElse I get a 500 response and this message in the console :

How to parse gzip encoded response with RestTemplate from Spring-Web

二次信任 提交于 2019-11-26 16:18:32
问题 After I modified Consuming a RESTful Web Service example to call get users by id from api.stackexchange.com I get JsonParseException: com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is allowed between tokens Response from api.stackexchange.com is gzip compressed. How to add support for gzip compressed response into Spring-Web RestTemplate? I am using Spring boot parent ver. 1.3.1.RELEASE hence Spring-Web 4.2.4