spring-projects / spring-projects/spring-data-rest

In spring-data-rest @BasePathAwareController breaks request mapping that returns an image [DATAREST-709]

Open
#1,078 0 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

type: bug
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

Tobias Kaupat opened DATAREST-709 and commented

I could understand, that a @RepositoryRestController is not meant to return images. But when I use the follwing endpoint. I get an 406 return from the endpoint:

@BasePathAwareController
@RestController
@RequestMapping("/images")
public class ImageEndpoint {
         @Autowired
         private TextureRepository textureRepository;
         @Autowired
         private ResourceLoader resourceLoader;
         @RequestMapping(value = "/texture/{id}", method = RequestMethod.GET, produces = "image/png")
         public ResponseEntity<Resource> texture(@PathVariable("id") Long id) {
                  Texture texture = textureRepository.findOne(id);
                  if (texture != null) {
                           return ResponseEntity.ok(resourceLoader.getResource(texture.getResourcePath()));
                  } else {
                           return new ResponseEntity<>(HttpStatus.NOT_FOUND);
                  }
         }
}

Removing just the @BasePathAwareController will fix the problem and everything works fine (ofc not at the basePath URL)


Affects: 2.4.1 (Gosling SR1)

1 votes, 1 watchers

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.