spring-hateoas

How to configure Spring HATEOAS behind proxy?

亡梦爱人 提交于 2019-11-27 23:06:48
I have Spring Data Rest with Hateoas as my backed. It is behind a proxy. Backend url: backend.com Proxy url: proxy.com When I query proxy url, e.g. http://proxy.com/items/1 , I get a response with href links with domain backend.com . I need the domain to be proxy.com . As of Spring-Boot 2.1 / Spring 5.1, Spring shifts the responsibility of handling X-Forwarded-* from Spring HATEOAS to Spring MVC. https://jira.spring.io/browse/SPR-16668 You now require the registration of a filter bean. Minimal implementation: @Bean FilterRegistrationBean<ForwardedHeaderFilter> forwardedHeaderFilter() {

How to correctly use PagedResourcesAssembler from Spring Data?

青春壹個敷衍的年華 提交于 2019-11-27 10:28:11
I'm using Spring 4.0.0.RELEASE, Spring Data Commons 1.7.0.M1, Spring Hateoas 0.8.0.RELEASE My resource is a simple POJO: public class UserResource extends ResourceSupport { ... } My resource assembler converts User objects to UserResource objects: @Component public class UserResourceAssembler extends ResourceAssemblerSupport<User, UserResource> { public UserResourceAssembler() { super(UserController.class, UserResource.class); } @Override public UserResource toResource(User entity) { // map User to UserResource } } Inside my UserController I want to retrieve Page<User> from my service and then

Custom response for root request int the Spring REST HATEOAS with both RepositoryRestResource-s and regular controllers

£可爱£侵袭症+ 提交于 2019-11-27 10:10:05
问题 Let's say I have two repositories: @RepositoryRestResource(collectionResourceRel = "person", path = "person") public interface PersonRepository extends PagingAndSortingRepository<Person, Long> { List<Person> findByLastName(@Param("name") String name); } and @RepositoryRestResource(collectionResourceRel = "person1", path = "person1") public interface PersonRepository1 extends PagingAndSortingRepository<Person1, Long> { List<Person1> findByLastName(@Param("name") String name); } with one

Customizing HATEOAS link generation for entities with composite ids

孤街醉人 提交于 2019-11-27 04:27:11
问题 I have configured a RepositoryRestResource on a PageAndSortingRepository that accesses an Entity that includes a composite Id: @Entity @IdClass(CustomerId.class) public class Customer { @Id BigInteger id; @Id int startVersion; ... } public class CustomerId { BigInteger id; int startVersion; ... } @RepositoryRestResource(collectionResourceRel = "customers", path = "customers", itemResourceRel = "customers/{id}_{startVersion}") public interface CustomerRepository extends

Can I make a custom controller mirror the formatting of Spring-Data-Rest / Spring-Hateoas generated classes?

╄→尐↘猪︶ㄣ 提交于 2019-11-27 03:19:06
I'm trying to do something I think should be really simple. I have a Question object, setup with spring-boot, spring-data-rest and spring-hateoas. All the basics work fine. I would like to add a custom controller that returns a List<Question> in exactly the same format that a GET to my Repository 's /questions url does, so that the responses between the two are compatible. Here is my controller: @Controller public class QuestionListController { @Autowired private QuestionRepository questionRepository; @Autowired private PagedResourcesAssembler<Question> pagedResourcesAssembler; @Autowired

How to expose the resourceId with Spring Data Rest

℡╲_俬逩灬. 提交于 2019-11-27 03:19:02
问题 I had was to expose the primary key which is annotated with @Id in entity.the ID field is only visible on the resource path, but not on the JSON body. 回答1: You can configure this using the RepositoryRestConfigurerAdapter on entity level. @Configuration public class ExposeEntityIdRestConfiguration extends RepositoryRestConfigurerAdapter { @Override public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { config.exposeIdsFor(MyEntity.class); } } Be aware that using

Different JSON output when using custom json serializer in Spring Data Rest

被刻印的时光 ゝ 提交于 2019-11-27 02:22:59
问题 After adding a custom Jackson serializer based on the official documenation I've observed a slightly different json output format. This example is based on a fork of spring-restbucks. Extend org.springsource.restbucks.WebConfiguration from RepositoryRestMvcConfiguration and override configureJacksonObjectMapper : @Override protected void configureJacksonObjectMapper(ObjectMapper objectMapper) { final SimpleSerializers serializers = new SimpleSerializers(); serializers.addSerializer(Order

Enable HAL serialization in Spring Boot for custom controller method

浪尽此生 提交于 2019-11-27 01:30:21
I'm trying to build a RESTful API with Spring Boot using spring-boot-starter-data-rest. There are some entities: accounts, transactions, categories and users - just the usual stuff. When I retrieve the objects at http://localhost:8080/transactions via the API that has been generated by default, all is going well an I get a list with all transactions as JSON objects like that one: { "amount": -4.81, "date": "2014-06-17T21:18:00.000+0000", "description": "Pizza", "_links": { "self": { "href": "http://localhost:8080/transactions/5" }, "category": { "href": "http://localhost:8080/transactions/5

Spring MVC 3: return a Spring-Data Page as JSON

无人久伴 提交于 2019-11-27 00:11:43
问题 I have a data access layer made with Spring-Data. I'm now creating a web application on top of it. This one controller method should return a Spring-Data Page formatted as JSON. Such a Page is a List with additional Paging info like total amount of records and so forth. Is that possible and if yes how? And directly related to that can I define the mapping of property names? Eg. meaning I would need define how the paging info properties are named in JSON (differently than in page). Is this

Spring HATEOAS embedded resource support

旧城冷巷雨未停 提交于 2019-11-27 00:03:43
问题 I want to use the HAL format for my REST API to include embedded resources. I'm using Spring HATEOAS for my APIs and Spring HATEOAS seems to support embedded resources; however, there's no documentation or example on how to use this. Can someone provide an example how to use Spring HATEOAS to include embedded resources? 回答1: Make sure to read Spring's documentation about HATEOAS, it helps to get the basics. In this answer a core developer points out the concept of Resource , Resources and