Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResourceProcessor not invoked for empty collections [DATAREST-542] #918

Closed
spring-projects-issues opened this issue May 14, 2015 · 7 comments
Closed

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented May 14, 2015

Petar Tahchiev opened DATAREST-542 and commented

Hi there,

at the moment opening the rest representation of a given entity I see this:

{
  "_links" : {
    "self" : {
      "href" : "https://localhost:8112/storefront/rest/category{?page,size,sort}",
      "templated" : true
    },
    "next" : {
      "href" : "https://localhost:8112/storefront/rest/category?page=2&size=20{&sort}",
      "templated" : true
    },
    "search" : {
      "href" : "https://localhost:8112/storefront/rest/category/search"
    }
  },
  "_embedded" : {
....
}

What I would love to see is the ability to specify custom links in the _links section. So that the end result would be like this:

{
  "_links" : {
    "self" : {
      "href" : "https://localhost:8112/storefront/rest/category{?page,size,sort}",
      "templated" : true
    },
    "next" : {
      "href" : "https://localhost:8112/storefront/rest/category?page=2&size=20{&sort}",
      "templated" : true
    },
    "search" : {
      "href" : "https://localhost:8112/storefront/rest/category/search"
    },
    "mynewlink": {
     "href" : "https://localhost:8112/storefront/rest/category/mynewlink"
    }
  },
  "_embedded" : {
...
}

Issue Links:

  • DATACMNS-699 PagedResourcesAssembler should allow creating an empty PagedResources that renders an embedded empty collection
    ("depends on")
  • DATAREST-479 Render empty _embedded content for empty collections
@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 14, 2015

Oliver Drotbohm commented

You should be able to just implement a ResourceProcessor<Resources<YourDomainType>> and manually add the additional links in process(…)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 15, 2015

Petar Tahchiev commented

Hmm.. I tried it and I couldn't make it work. At first I though it is because my entities are interfaces, but even if they are concrete classes it still doesn't invoke my ResourceProcessor. Here's a sample repository:
https://github.com/paranoiabla/DATAREST-542

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 18, 2015

Oliver Drotbohm commented

The reason you currently don't see this working is that for an empty collection the component invoking the ResourceProcessor instances cannot reason about whether the processor should be invoked as there's no type information in the returned empty collection / page. I am currently working on an improvement on this (see the linked tickets) which should solve this one here transitively

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 18, 2015

Oliver Drotbohm commented

This should work now, feel free to give the snapshots a spin

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 22, 2015

Petar Tahchiev commented

I tried my sample project with the latest Gosling release and I got this error:

java.lang.NoSuchMethodError: org.springframework.hateoas.core.EmbeddedWrappers.emptyCollectionOf(Ljava/lang/Class;)Lorg/springframework/hateoas/core/EmbeddedWrapper;
	at org.springframework.data.web.PagedResourcesAssembler.toEmptyResource(PagedResourcesAssembler.java:152)
	at org.springframework.data.rest.webmvc.AbstractRepositoryRestController.entitiesToResources(AbstractRepositoryRestController.java:124)
	at org.springframework.data.rest.webmvc.AbstractRepositoryRestController.toResources(AbstractRepositoryRestController.java:88)
	at org.springframework.data.rest.webmvc.RepositoryEntityController.getCollectionResource(RepositoryEntityController.java:205)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1521)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1478)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 22, 2015

Oliver Drotbohm commented

There is no Gosling release. Make sure you use Spring HATEOAS 0.17.0.RELEASE

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 22, 2015

Petar Tahchiev commented

Yep, that was it - old SNAPSHOT version of spring-data-rest-core, which was bringing Spring HATEOAS 0.16.0.RELEASE Now the test project is OK, but only because I use concrete classes for data-model. It would be nice if this feature is also available for the alternative domain types :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants