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
369
votes
31 answers

Spring Boot - How to log all requests and responses with exceptions in single place?

I'm working on REST API with spring boot. I need to log all requests with input params (with methods, eg. GET, POST, etc.), request path, query string, corresponding class method of this request, also response of this action, both success and…
Teimuraz
  • 8,795
  • 5
  • 35
  • 62
57
votes
3 answers

Reading HTTP headers in a Spring REST controller

I am trying to read HTTP headers in Spring based REST API. I followed this. But I am getting this error: No message body reader has been found for class java.lang.String, ContentType: application/octet-stream I am new to Java and Spring so can't…
Ashwani K
  • 7,880
  • 19
  • 63
  • 102
55
votes
7 answers

Spring RestTemplate and generic types ParameterizedTypeReference collections like List

An Abstract controller class requires List of objects from REST. While using Spring RestTemplate its not mapping it to required class instead it returns Linked HashMAp public List restFindAll() { RestTemplate restTemplate =…
vels4j
  • 11,208
  • 5
  • 38
  • 63
39
votes
2 answers

Spring restTemplate get raw json string

How can I get the raw json string from spring rest template? I have tried following code but it returns me json without quotes which causes other issues, how can i get the json as is. ResponseEntity response = restTemplate.getForEntity(url,…
suraj bahl
  • 2,864
  • 6
  • 31
  • 42
33
votes
2 answers

Does Spring create new thread per request in rest controllers?

I wanted to learn non blocking REST, but first I wrote blocking controller for comparison. To my surprise Spring doesn't block incoming requests. Simple blocking service: @Service public class BlockingService { public String blocking() { …
user
  • 4,410
  • 16
  • 57
  • 83
26
votes
6 answers

How to create a Spring Interceptor for Spring RESTful web services

I have some Spring RESTful (RestControllers) web services with no web.xml and I am using Spring boot to start the services. I want to add authorization layer for the web services and wanted to route all the http requests to one front controller…
Praneeth Reddy
  • 393
  • 1
  • 4
  • 7
25
votes
3 answers

MockRestServiceServer: how to mock a POST call with a body?

I am trying to mock a POST method with MockRestServiceServer in the following way: MockRestServiceServer server = bindTo(restTemplate).build(); server.expect(requestTo("/my-api")) .andExpect(method(POST)) …
Sasha Shpota
  • 9,436
  • 14
  • 75
  • 148
25
votes
7 answers

How to get request's URI from WebRequest in Spring?

I am handling REST exceptions using @ControllerAdvice and ResponseEntityExceptionHandler in a spring Rest webservice. So far everything was working fine until I decided to add the URI path(for which exception has occurred) into the BAD_REQUEST…
The Coder
  • 3,447
  • 7
  • 46
  • 81
23
votes
3 answers

@RestController methods seem to be Transactional by default, Why?

Using Spring boot 1.3.1 I don't understand why @RestController are Transactionnal by default. I haven't found anything saying so in the docs. Example which pushes this fact that the method findOne() in the controller below is…
Gauthier Peel
  • 1,438
  • 2
  • 17
  • 35
21
votes
1 answer

How can I use Pageable in @RestController?

I know the Pageable comes from spring-data- domain. Is there any elegant way to directly use org.springframework.data.domain.Pageable in @RestController? I tried following. @RequestMapping(method = RequestMethod.GET, path =…
Jin Kwon
  • 20,295
  • 14
  • 115
  • 184
21
votes
1 answer

How to Use Spring Boot's 'spring.jackson.date-format' Property?

According to the Current SpringBoot Reference Guide if I set the spring.jackson.date-format property, it will: Date format string or a fully-qualified date format class name. For instance 'yyyy-MM-dd HH:mm:ss'. However, it doesn't work this way…
peterl
  • 1,881
  • 4
  • 21
  • 34
21
votes
5 answers

Swagger + Spring security - Hide methods based on roles

I have an API that has different consumers. I'd like them to get relevant documentation based on their roles in Spring Security. E.g API operation A is constricted to Role A and Role B API operation B is constricted to Role B API operation C is open…
Espen Schulstad
  • 2,355
  • 3
  • 21
  • 32
20
votes
2 answers

How to force `.andExpect(jsonPath()` to return Long/long instead int for int number for jackson parser

I have a simple test to my RestController. I expect that $[1].parent_idreturns Long as an object and not integer primitive. It will return Long if parent_id is in a long number range and > integer number range (such as :…
slawalata
  • 389
  • 1
  • 2
  • 14
17
votes
2 answers

Best practices on rest client using spring RestTemplate

I have read some tutorials about implementing REST client in java web application that use SPRING to manage beans. Every example I found, every time doing a REST request it creates new RestTemplate. Normally web applications use singleton spring…
Chamly Idunil
  • 1,848
  • 1
  • 18
  • 33
16
votes
3 answers

Spring REST and PATCH method

I'm using SpringBoot and Spring REST. I would like to understand the HTTP PATCH method to update properties of my Model Is there any good tutorial explaining how to make it works ? HTTP PATCH method and body to be Send Controller method and how to…
fvisticot
  • 7,936
  • 14
  • 49
  • 79
1
2 3
86 87