spring-rest

What is the equivalent of @Context UriInfo in Spring Rest

五迷三道 提交于 2021-02-18 10:40:07
问题 I have worked in Jersey and RESTEasy framework earlier and now we will be using Spring Rest for a new project , I don't want to pass all the query params and matrix params as parameters in the method , and usually I would annotate the method with @Context UriInfo and would get all the parameters inside my method in Jersey or RESTEasy Framework for complex parameters. I would like to know if there is any @Context UriInfo in Spring REST, which is similar to RESTEasy or Jersey Framework. I would

Java/Spring Processing Spring batch job requests asynchronously

为君一笑 提交于 2021-02-17 06:33:24
问题 Currently, I expose a rest endpoint in my application that kick of spring batch jobs. However, the requests are not scheduled asynchronously. Response is provided after job completes with batch status in the MyResponse object. @RestController @RequestMapping("/test") public class TestController { private MyProcessor processor; private RequestDataRepo repo; public TestController(final MyProcessor processor, final RequestDataRepo repo) { this.feedProcessor = feedProcessor; this.repo = repo; }

Test endpoints compliance against openapi contract in Spring Boot Rest

谁都会走 提交于 2021-02-11 15:24:58
问题 I am looking for a nice way to write tests to make sure that enpoints in Spring Boot Rest (ver. 2.1.9) application follows the contract in openapi contract. In the project I moved recently there is following workflow: architects write contract openapi.yml and developers have to implement endpoint to compliance the contract. Unfortunately a lot of differences happen and this test have to catch such situation and it is not possible to change this :( I was thinking about the solution to generate

Spring REST endpoint returning StreamingResponseBody: AsyncRequestTimeoutException after 30 seconds

烈酒焚心 提交于 2021-02-11 15:14:32
问题 I have the same problem as described here and here. I tried the answers given and combinations thereof but none solved my issue. When I tried this answer, after 30 seconds, instead of the timeout, the download restarted from the beginning and then, after 30 more seconds, then it timed out. I'm testing by visiting the REST endpoint in Google Chrome and trying to download a file from there. Here I have the project that displays this error. Thanks in advance. Edit: here's the source: src\main

Forward request to spring controller

空扰寡人 提交于 2021-02-10 16:00:50
问题 From a servlet , I am forwarding the request to a spring controller like below RequestDispatcher rd = request.getRequestDispatcher("/myController/test?reqParam=value"); rd.forward(request, response); In order to pass a parameter to the spring controller , I am passing it as request parameter in the forward URL. Is there a better way of doing this ? Instead of passing in request parameter , can I pass as a method parameter to the spring controller during forward ? 回答1: This will be called when

What is the best practice for RestController?

南笙酒味 提交于 2021-02-07 12:39:23
问题 Code convention says no logic in the controllers. All should be handled in the service layer. My question is especially about returning ResponseEntity. Should it be handled in RestController or in Service layer? I tried both ways. I think RestController is the suitable place to return ResponseEntity. Because we are using mappings in the RestController. On the other hand, we know the controllers should not include any logic. @GetMapping("/{id}") public ResponseEntity<Employee> getEmployee(

how to route to an external url using zuul proxy filter

久未见 提交于 2021-01-22 08:24:20
问题 i have an external url and i want to pass some request header through zuul filter to launch the application. Can anyone please help me on this. In my custom prefilter i have written this: @Component public class CustomFilters extends ZuulFilter { public static final Logger logger = LoggerFactory.getLogger(CustomFilters.class); @Override public String filterType() { return "route"; } @Override public int filterOrder() { return 1; } @Override public boolean shouldFilter() { return true; }

how to route to an external url using zuul proxy filter

北城以北 提交于 2021-01-22 08:21:09
问题 i have an external url and i want to pass some request header through zuul filter to launch the application. Can anyone please help me on this. In my custom prefilter i have written this: @Component public class CustomFilters extends ZuulFilter { public static final Logger logger = LoggerFactory.getLogger(CustomFilters.class); @Override public String filterType() { return "route"; } @Override public int filterOrder() { return 1; } @Override public boolean shouldFilter() { return true; }

how do I throw a error on unknown fields in json request to spring restapi

让人想犯罪 __ 提交于 2021-01-03 16:58:55
问题 I have a spring rest api which gets json data and binds to a pojo GetData. Whenever i recieve unknown fields it doesnt fail or throw any exception. My requirement here is it should throw a error when it receives unknown fields in json data. public ResponseEntity<Error> saveLocation(@Valid @RequestBody GetData getdata,BindingResult bindingResults) { Below is my Pojo GetData public class GetData{ @JsonProperty("deviceID") @Pattern(regexp="^[\\p{Alnum}][-\\p{Alnum}\\p{L}]+[\\p{Alnum}]$",message

Spring boot send async tasks

♀尐吖头ヾ 提交于 2021-01-02 03:28:28
问题 I need to send the email/sms/events as a background async task inside spring boot rest. My REST controller @RestController public class UserController { @PostMapping(value = "/register") public ResponseEntity<Object> registerUser(@RequestBody UserRequest userRequest){ // I will create the user // I need to make the asyn call to background job to send email/sms/events sendEvents(userId, type) // this shouldn't block the response. // need to send immediate response Response x = new Response();