|
| 1 | +== Fully Qualified Links |
| 2 | +By default, and where possible, Spring Content REST exports Spring Resources to shortened link URIs. These will often |
| 3 | +match the Spring Data Rest Entity URI. |
| 4 | + |
| 5 | +Given the following example: |
| 6 | + |
| 7 | +==== |
| 8 | +[source, java] |
| 9 | +---- |
| 10 | + @Entity |
| 11 | + public class Dvd { |
| 12 | + @Id |
| 13 | + @GeneratedValue(strategy = GenerationType.AUTO) |
| 14 | + private Long id; |
| 15 | +
|
| 16 | + @ContentId |
| 17 | + private UUID contentId; |
| 18 | +
|
| 19 | + @ContentLength |
| 20 | + private Long contentLength; |
| 21 | +
|
| 22 | + @MimeType |
| 23 | + private String mimeType; |
| 24 | +
|
| 25 | + // getters and setters |
| 26 | + } |
| 27 | +
|
| 28 | + public interface DvdRepository extends CrudRepository<Dvd, Long> {} |
| 29 | +
|
| 30 | + public interface DvdStore extends ContentStore<Dvd, UUID> {} |
| 31 | +---- |
| 32 | +==== |
| 33 | + |
| 34 | +As there is only a single associated Spring Resource, Spring Content REST will generate the following URI: |
| 35 | + |
| 36 | +==== |
| 37 | +[source, java] |
| 38 | +---- |
| 39 | + "_links" : { |
| 40 | + "self" : { |
| 41 | + ... |
| 42 | + }, |
| 43 | + "dvd" : { |
| 44 | + ... |
| 45 | + }, |
| 46 | + "dvds" : { |
| 47 | + "href" : "http://localhost:8080/dvds/1" |
| 48 | + } |
| 49 | + } |
| 50 | +---- |
| 51 | +==== |
| 52 | + |
| 53 | +To generate fully qualified link URIs set the following property: |
| 54 | + |
| 55 | +==== |
| 56 | +[source, java] |
| 57 | +---- |
| 58 | +spring.content.rest.fullyQualifiedLinks=true |
| 59 | +---- |
| 60 | +==== |
| 61 | + |
| 62 | +Or if you are not using Spring Boot, you can do the following: |
| 63 | + |
| 64 | +==== |
| 65 | +[source, java] |
| 66 | +---- |
| 67 | +@Configuration |
| 68 | +class CustomContentRestMvcConfiguration { |
| 69 | +
|
| 70 | + @Bean |
| 71 | + public ContentRestConfigurer contentRestConfigurer() { |
| 72 | +
|
| 73 | + return new ContentRestConfigurer() { |
| 74 | +
|
| 75 | + @Override |
| 76 | + public void configure(RestConfiguration config) { |
| 77 | + config.setFullyQualifiedLinks(true); |
| 78 | + } |
| 79 | + }; |
| 80 | + } |
| 81 | +} |
| 82 | +---- |
| 83 | +==== |
| 84 | + |
| 85 | +Spring Content REST will now generate links as follows: |
| 86 | + |
| 87 | +==== |
| 88 | +[source, java] |
| 89 | +---- |
| 90 | + "_links" : { |
| 91 | + "self" : { |
| 92 | + ... |
| 93 | + }, |
| 94 | + "dvd" : { |
| 95 | + ... |
| 96 | + }, |
| 97 | + "content" : { |
| 98 | + "href" : "http://localhost:8080/dvds/1/content" |
| 99 | + } |
| 100 | + } |
| 101 | +---- |
| 102 | +==== |
| 103 | + |
| 104 | +where `content` is the extracted property name taken from the field `contentId`. |
0 commit comments