Open spring-projects-issues opened 9 years ago
Martin Macko commented
I've submitted a pull request for this: https://github.com/spring-projects/spring-data-rest/pull/201
Oliver Drotbohm commented
We dropped support for absolute base URIs as they have a couple of drawbacks.
Any reason you need to stick to absolute ones?
Dave Handy commented
Oliver- I was trying to set up apache/mod_proxy in front of tomcat, and the embedded HAL _links were being generated with the internal hostname. Since then I switched to mod_ajp (which sadly required an upgrade to apache that is not RHEL6 standard) and AJP forwards all the necessary information to tomcat to generate the links properly. AJP of course is a much better solution than using an absolute base URI; totally agree with your reasoning.
Since you've dropped support, does the test case above throw a more explanatory exception?
William Gorder commented
How about using it with websockets? RequestContext holder is not going to find anything since the request came over a websocket. So how am I supposed to build my response with links???
java.lang.IllegalStateException: Could not find current request via RequestContextHolder
at org.springframework.util.Assert.state(Assert.java:392) ~[spring-core-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.support.ServletUriComponentsBuilder.getCurrentRequest(ServletUriComponentsBuilder.java:183) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.support.ServletUriComponentsBuilder.fromCurrentRequest(ServletUriComponentsBuilder.java:175) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.data.web.PagedResourcesAssembler.getUriTemplate(PagedResourcesAssembler.java:227) ~[spring-data-commons-1.11.4.RELEASE.jar:na]
at org.springframework.data.web.PagedResourcesAssembler.addPaginationLinks(PagedResourcesAssembler.java:190) ~[spring-data-commons-1.11.4.RELEASE.jar:na]
at org.springframework.data.web.PagedResourcesAssembler.createResource(PagedResourcesAssembler.java:185) ~[spring-data-commons-1.11.4.RELEASE.jar:na]
at org.springframework.data.web.PagedResourcesAssembler.toResource(PagedResourcesAssembler.java:115) ~[spring-data-commons-1.11.4.RELEASE.jar:na]
at org.springframework.data.web.PagedResourcesAssembler.toResource(PagedResourcesAssembler.java:90) ~[spring-data-commons-1.11.4.RELEASE.jar:na]
at com.api.chat.ChatController.getConversations(ChatController.java:41) ~[ChatController.class:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_20]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_20]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_20]
at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_20]
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:197) ~[spring-messaging-4.2.5.RELEASE.jar:4.2
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Dave Handy opened DATAREST-564 and commented
This test case fails, because BaseUri is trying to reverse an unmodifiable collection. A slightly broader question is why the getRepositoryLookup path logic is so different for absolute base URIs versus relative base URI.
import org.junit.Test; import org.springframework.data.rest.webmvc.BaseUri;
public class BaseUriTest {
@Test
public void testbaseURi() { BaseUri base = new BaseUri("https://example.com/services/v1/"); base.getRepositoryLookupPath(""); } }Caused by: java.lang.UnsupportedOperationException: null at java.util.Collections$UnmodifiableList.set(Collections.java:1311) at java.util.Collections.swap(Collections.java:497) at java.util.Collections.reverse(Collections.java:378) at org.springframework.data.rest.webmvc.BaseUri.getRepositoryLookupPath(BaseUri.java:130)
Affects: 2.2.2 (Evans SR2)
1 votes, 4 watchers