spring-projects / spring-data-rest

Simplifies building hypermedia-driven REST web services on top of Spring Data repositories
https://spring.io/projects/spring-data-rest
Apache License 2.0
920 stars 563 forks source link

Missing Etag header using custom @RepositoryRestController [DATAREST-1201] #1562

Open spring-projects-issues opened 6 years ago

spring-projects-issues commented 6 years ago

Daniele Renda opened DATAREST-1201 and commented

I'm using Spring Boot 1.5.10, Spring Data REST, Spring HEATEOAS, Spring HPA. I created a custom GET method in my @RepositoryRestController like this:

@GetMapping(path = "/users/{id}")
    public ResponseEntity<?> findById(@PathVariable(value = "id") long userId, Locale locale,
            PersistentEntityResourceAssembler resourceAssembler) {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        //My implementation

        return new ResponseEntity<>(resourceAssembler.toResource(user), HttpStatus.OK);
    }

Unfortunately, differently from the default Spring Data REST repository the Etag header is missing.

Am I missing something? Is this behaviour desired?


Affects: 3.0.3 (Kay SR3)

spring-projects-issues commented 6 years ago

Daniele Renda commented

Is this confirmed as a bug? Thanks

spring-projects-issues commented 6 years ago

Oliver Drotbohm commented

No, it's not. You're implementing the controller and don't set any headers. I am wondering what exactly makes you expect the ETag to be set magically?

spring-projects-issues commented 6 years ago

Daniele Renda commented

Thanks @Oliver Gierke. I thought the magic happened because I was using @RepositoryRestController. In the documentation (https://docs.spring.io/spring-data/rest/docs/current/reference/html/#customizing-sdr.overriding-sdr-response-handlers) is written "Sometimes you may want to write a custom handler for a specific resource. To take advantage of Spring Data REST’s settings, message converters, exception handling, and more..."

I thought that "and more" meant also this. Could you give me an hint to which Spring class to look at to take inspiration to set Etags like in Data REST Repositories? And if I may ask, why in Data REST repositories etag are set and here not?

Thanks

spring-projects-issues commented 6 years ago

Daniele Renda commented

@olivergierke Are you awaiting some feedback from me? I saw the change status but I didn't see any question. Thanks

spring-projects-issues commented 3 years ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.