Skip to content

Commit c0951de

Browse files
author
eugenp
committed
fixes for discoverability
1 parent c974940 commit c0951de

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

‎common/src/main/java/org/rest/common/web/event/ResourceCreatedDiscoverabilityListener.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ public final void onApplicationEvent(final ResourceCreatedEvent ev) {
3030
addLinkHeaderOnEntityCreation(ev.getUriBuilder(), ev.getResponse(), idOfNewResource, ev.getClazz());
3131
}
3232

33+
/**
34+
* - note: at this point, the URI is transformed into plural (added `s`) in a hardcoded way - this will change in the future
35+
*/
3336
final void addLinkHeaderOnEntityCreation(final UriComponentsBuilder uriBuilder, final HttpServletResponse response, final long idOfNewEntity, final Class clazz) {
3437
final String resourceName = clazz.getSimpleName().toString().toLowerCase();
35-
final String locationValue = uriBuilder.path(PATH_SEP + resourceName + "/{id}").build().expand(idOfNewEntity).encode().toUriString();
38+
final String locationValue = uriBuilder.path(PATH_SEP + resourceName + "s/{id}").build().expand(idOfNewEntity).encode().toUriString();
3639

3740
response.setHeader(HttpHeaders.LOCATION, locationValue);
3841
}

‎common/src/main/java/org/rest/common/web/event/SingleResourceRetrievedDiscoverabilityListener.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ public final void onApplicationEvent(final SingleResourceRetrievedEvent ev) {
3030
discoverGetAllURI(ev.getUriBuilder(), ev.getResponse(), ev.getClazz());
3131
}
3232

33+
/**
34+
* - note: at this point, the URI is transformed into plural (added `s`) in a hardcoded way - this will change in the future
35+
*/
3336
final void discoverGetAllURI(final UriComponentsBuilder uriBuilder, final HttpServletResponse response, final Class clazz) {
3437
final String resourceName = clazz.getSimpleName().toString().toLowerCase();
35-
final String uriForResourceCreation = uriBuilder.path(PATH_SEP + resourceName).build().encode().toUriString();
38+
final String uriForResourceCreation = uriBuilder.path(PATH_SEP + resourceName + "s").build().encode().toUriString();
3639

3740
final String linkHeaderValue = LinkUtil.createLinkHeader(uriForResourceCreation, LinkUtil.REL_COLLECTION);
3841
response.addHeader(HttpHeaders.LINK, linkHeaderValue);
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
22
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
33
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
4-
<listEntry value="/rest-sec/src/test/java/org/rest/sec/security/SecurityRESTIntegrationTest.java"/>
4+
<listEntry value="/rest-sec/src/test/java/org/rest/sec/web/user/UserDiscoverabilityRESTIntegrationTest.java"/>
55
</listAttribute>
66
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
77
<listEntry value="1"/>
@@ -12,10 +12,10 @@
1212
</mapAttribute>
1313
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
1414
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
15-
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
15+
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value="whenResourceIsRetrieved_thenURIToGetAllResourcesIsDiscoverable"/>
1616
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
1717
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
18-
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.rest.sec.security.SecurityRESTIntegrationTest"/>
18+
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.rest.sec.web.user.UserDiscoverabilityRESTIntegrationTest"/>
1919
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="rest-sec"/>
2020
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
2121
</launchConfiguration>

0 commit comments

Comments
 (0)