Questions tagged [spring-rest]

Use this tag for question about the REST architectural style used in Spring framework

REST architectural style used in Spring framework

1305 questions
15
votes
3 answers

What is the best practice for RestController?

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…
Cihangir
  • 1,892
  • 1
  • 11
  • 16
15
votes
3 answers

DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler

I am trying to design a rest api, and below is my controller code. when i invoke http://localhost:8080/ the response is fine, but if i hit http://localhost:8080/api/ca it thorws javax.servlet.ServletException: No adapter for handler…
Jigar Naik
  • 1,946
  • 5
  • 29
  • 60
15
votes
4 answers

What is the equivalent of @Context UriInfo in Spring Rest

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…
Vignesh
  • 521
  • 2
  • 6
  • 10
14
votes
4 answers

Spring rest template readTimeOut

I'm trying to understand the readTimeout available on restTemplate, what is it exactly ? Is it the the total amount of time the request can take before we get the timeout exception ?
Seb
  • 3,602
  • 8
  • 36
  • 52
14
votes
4 answers

Spring REST Template for Byte

I am fetching the byte array using spring framework rest template, But I also need to fetch the Mediatype of this byte . The mediaType of this bytearray can be of any type. The code used now for fetching byte is below. HttpHeaders headers = new…
Tiny
  • 683
  • 5
  • 18
  • 36
14
votes
3 answers

REST POST works correctly with POSTMAN but exception when using Spring RestTemplate

I am writing a Rest client to post JSON data using Spring RestTemplate. Using POSTMAN and following JSON data in body get the response correctly- { "InCode":"test", "Name":"This is test", "Email":"test@gmail.com", …
Rehan
  • 929
  • 1
  • 12
  • 29
14
votes
3 answers

Spring Data Rest Validation Confusion

Looking for some help with Spring data rest validation regarding proper handling of validation errors: I'm so confused with the docs regarding spring-data-rest validation here:…
1977
  • 2,580
  • 6
  • 26
  • 37
13
votes
3 answers

Spring boot rest service to download a zip file which contains multiple file

I am able to download a single file but how I can download a zip file which contain multiple files. Below is the code to download a single file but I have multiples files to download. Any help would greatly appreciated as I am stuck on this for last…
abhishek chauhan
  • 367
  • 2
  • 6
  • 15
13
votes
5 answers

How to validate Spring Boot Rest response?

I have controller implemented with Spring Boot Rest: @RestController @RequestMapping("/example") public class ExampleController { @Autowired private ExampleService exampleService; @GetMapping("/{id}") public ExampleResponse…
Justinas Jakavonis
  • 8,220
  • 10
  • 69
  • 114
13
votes
7 answers

How to use RestTemplate with multiple response types?

I'm using spring RestTemplate for communication with a xml webservice backend as follows: ResponseEntity dto = restTemplate.postForObject(url, postData, MainDTO.class); Problem: the backend might either respond with MainDTO for normal data…
membersound
  • 81,582
  • 193
  • 585
  • 1,120
13
votes
1 answer

How to log RestTemplate request and response with spring?

I'm using Spring with RestTemplate to execute HTTP GET requests. How can I log any request and response data to a log file automatically on each request?
membersound
  • 81,582
  • 193
  • 585
  • 1,120
12
votes
3 answers

JSON Patch Request validation in Java

In my spring boot service, I'm using https://github.com/java-json-tools/json-patch for handling PATCH requests. Everything seems to be ok except a way to avoid modifying immutable fields like object id's, creation_time etc. I have found a similar…
shoaib1992
  • 410
  • 1
  • 8
  • 26
11
votes
4 answers

Not able to return ResponseEntity with Exception Details in spring

I have created a Spring Restful Service and Spring MVC application. Restful Service :: Restful service returns an entity if its existing in DB. If it doesn't exist It returns a custom Exception information in ResponseEntity object. It is working as…
Abdul
  • 1,130
  • 4
  • 29
  • 65
11
votes
1 answer

Spring boot security REST basic authentication from database

I have a problem where when I use basic authentication with inMemoryAuthentication as in the following snippet, it works perfectly. @Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired DataSource…
Sherbi7y
  • 155
  • 1
  • 2
  • 6
11
votes
1 answer

Spring RestTemplate - BufferingClientHttpRequestFactory & SimpleClientHttpRequestFactory

I saw the below code in one of the Rest Clients built using Spring. This Rest Client is present within a REST service and is calling another REST service. What is the purpose of this statement? return new BufferingClientHttpRequestFactory(new…
Punter Vicky
  • 15,954
  • 56
  • 188
  • 315
1
2
3
86 87