spring-restcontroller

Spring asynch method integration test fails

白昼怎懂夜的黑 提交于 2020-01-16 20:19:26
问题 I created an integration test for asynchronous rest controller method. Which looks like: @Test public void shouldHandleRequestsAsynchronously() throws Exception { MvcResult mvcResult = this.mockMvc.perform(get("/api/reports/daily?startDate=2004-04-13&endDate=2005-04-13")) .andExpect(request().asyncStarted()) .andReturn(); this.mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()) .andExpect(jsonPath("$[0].totalDistance", equalTo(100))) .andExpect(jsonPath("$[0].totalPrice",

Spring asynch method integration test fails

安稳与你 提交于 2020-01-16 20:19:09
问题 I created an integration test for asynchronous rest controller method. Which looks like: @Test public void shouldHandleRequestsAsynchronously() throws Exception { MvcResult mvcResult = this.mockMvc.perform(get("/api/reports/daily?startDate=2004-04-13&endDate=2005-04-13")) .andExpect(request().asyncStarted()) .andReturn(); this.mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()) .andExpect(jsonPath("$[0].totalDistance", equalTo(100))) .andExpect(jsonPath("$[0].totalPrice",

Cannot use Map as a JSON @RequestParam in Spring REST controller

别说谁变了你拦得住时间么 提交于 2020-01-15 09:57:53
问题 This controller @GetMapping("temp") public String temp(@RequestParam(value = "foo") int foo, @RequestParam(value = "bar") Map<String, String> bar) { return "Hello"; } Produces the following error: { "exception": "org.springframework.web.method.annotation.MethodArgumentConversionNotSupportedException", "message": "Failed to convert value of type 'java.lang.String' to required type 'java.util.Map'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang

@RestController in other package doesn't work

大憨熊 提交于 2020-01-09 19:39:47
问题 I start with learning Spring and I create basic project which creates database, insert values and next print it in web browser. My problem is that when I have RestController in the same package like main class - its OK, but I want distribute it to other package and when I create new package, move the RestController it doesn't work. Let met explain: My project looks like: |-Springtestv_01 |-src/main/java |--com.person <-- it's a main package |-Main.java |-Person.java |-PersonLineRunner.java |

can @FeignClient extend - and @RestController implement - a common, fully-annotated Interface?

浪尽此生 提交于 2020-01-06 20:17:43
问题 I want a Feign client to consume a Spring Boot controller, and I want the contract between them to be specified in a common Interface to the degree possible. The interface with method would look something like this: @RequestMapping public interface RuleManager { @RequestMapping(value = "/addRule", method = RequestMethod.POST, consumes = {"application/json"}, produces = {"application/json"}) @ResponseBody Rule addRule(@RequestBody Rule rule); } The Feign client would look like: @FeignClient

Spring RestTemplate gives 401 Unauthorized error when sending with Authorization Header

别来无恙 提交于 2020-01-04 06:28:10
问题 I am trying to hit one Microsoft Flow POST URL in my Spring Rest application using following code but it is giving me 401 error. My Code: @RequestMapping(value = "/hookslistner", method = RequestMethod.POST) public ResponseEntity<Void> recieveWebhook(@RequestBody InventorySystemModel inventory, @RequestHeader("event") String event, @RequestHeader("Authorization") String authorization) { // authorization = "Basic <Base64 encoded value of username:pwd>" RestTemplate restTemplate = new

Difference between @RestController and @RepositoryRestController

醉酒当歌 提交于 2019-12-29 05:47:45
问题 What is the typical use case code that shows the difference between those two annotations - meaning the @RestController and the @RepositoryRestController - ? 回答1: According to the annotation the RepositoryRestController is a way to provide custom controllers that still take advantage of spring data rest functionality http://docs.spring.io/spring-data/rest/docs/current/reference/html/#customizing-sdr.overriding-sdr-response-handlers Sometimes you may want to write a custom handler for a

Spring - is possible to give same url in request mapping of post method?

柔情痞子 提交于 2019-12-25 18:31:30
问题 Is that possible to use same url in request mapping for two different post method, only request body differs. 回答1: No, you can't give same url in request mapping of post method having different request body type but same media type. Below won't work: @PostMapping(path = "/hello", consumes = MediaType.APPLICATION_JSON_VALUE) public String hello(@RequestBody Pojo1 val) { return "Hello"; } @PostMapping(path = "/hello", consumes = MediaType.APPLICATION_JSON_VALUE) public String hello(@RequestBody

Custom JSON serialization in Spring

人走茶凉 提交于 2019-12-25 07:47:18
问题 I have three entities: @Entity class Group { @id Long id; String name; String faculty; @OneToMany(mappedBy = "group", fetch = FetchType.LAZY, cascade = CascadeType.ALL ) List<Schedule> scedule; ... } @Entity class Schedule { @id Long id; String name; Group group; @OneToMany(mappedBy = "scedule", fetch = FetchType.LAZY, cascade = CascadeType.ALL ) List<Lesson> scedule; ... } @Entity class Lesson { @id Long id; String name; Schedule scedule; ... } I use Spring boot, and one my restcontroller

spring-data-jpa @RestController @Repository Optional strange behavior

非 Y 不嫁゛ 提交于 2019-12-24 20:25:28
问题 My @RestController @GetMapping("/projects/{project_id}") public Project getProjectById(@PathVariable(value = "project_id") UUID projectId) { return projectRepository.findById(projectId).orElseThrow(Util.notFound(projectId)); } My projectRepository is @Repository public interface ProjectRepository extends PagingAndSortingRepository<Project, UUID> { } public class Util { static Supplier<ResourceNotFoundException> notFound(UUID msg) { log.error(msg + " not found"); return () -> new