spring-projects / spring-projects/spring-data-rest
In spring-data-rest @BasePathAwareController breaks request mapping that returns an image [DATAREST-709]
Open
@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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.