spring-projects / spring-projects/spring-data-rest

Complex path in @RestResource for repository wrongly exported [DATAREST-79]

Open
#464 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: bug
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

Marco Fago opened DATAREST-79 and commented

I have a repository interface declared as

package it.mafa.smm.heatmap.persistence.repository;

import it.mafa.smm.heatmap.persistence.model.HeatmapPostEntity;

import java.util.Date;
import java.util.List;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.repository.annotation.RestResource;
import org.springframework.stereotype.Repository;

@RestResource(path="complex/path")
@Repository
public interface HeatmapPostRepository extends CrudRepository<HeatmapPostEntity, Long>{
	@RestResource(path="content")
	@Query("select p from HeatmapPostEntity p,HeatmapAbonnementEntity a where p.abonnement = a and a.name = :name and p.createdAt between :fromDate and :toDate")
	List<HeatmapPostEntity> findByNameAndCreatedAtBetween(@Param("name") String name,@Param("fromDate") Date fromDate,@Param("toDate") Date toDate, Pageable pageable);

	@Query("select p.languageCode,count(p) from HeatmapPostEntity p,HeatmapAbonnementEntity a where p.abonnement = a and a.name = :name and p.createdAt between :fromDate and :toDate group by p.languageCode")
	Object countByNameAndCreatedAtBetween(@Param("name") String name,@Param("fromDate") Date fromDate,@Param("toDate") Date toDate);
	
	@Query("select p.languageCode,count(p) from HeatmapPostEntity p,HeatmapAbonnementEntity a where p.abonnement = a and a.name = :name group by p.languageCode")
	List<Object> countByName(@Param("name") String name);
}

The list of exported REST resources looks like

C:\Documents and Settings\Administrator>curl -v "http://localhost:8080/heatmap/"
* About to connect() to localhost port 8080 (#0)
*   Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /heatmap/ HTTP/1.1
> User-Agent: curl/7.21.1 (i686-pc-mingw32) libcurl/7.21.1 OpenSSL/0.9.8r zlib/1.2.3
> Host: localhost:8080
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: application/json
< Transfer-Encoding: chunked
< Server: Jetty(8.1.8.v20121106)
<
{
  "links" : [ {
    "rel" : "client",
    "href" : "http://localhost:8080/heatmap/client"
  }, {
    "rel" : "heatmapPost",
    "href" : "http://localhost:8080/heatmap/complex/path"
  }, {
    "rel" : "heatmapAbonnement",
    "href" : "http://localhost:8080/heatmap/abonnement"
  } ],
  "content" : [ ]
}* Connection #0 to host localhost left intact
* Closing connection #0

In that case
but http://localhost:8080/heatmap/complex/path resource results in a 404 error

C:\Documents and Settings\Administrator>curl -v "http://localhost:8080/heatmap/complex/pat
* About to connect() to localhost port 8080 (#0)
*   Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /heatmap/complex/path HTTP/1.1
> User-Agent: curl/7.21.1 (i686-pc-mingw32) libcurl/7.21.1 OpenSSL/0.9.8r zlib/1.2.3
> Host: localhost:8080
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Content-Type: text/html;charset=ISO-8859-1
< Cache-Control: must-revalidate,no-cache,no-store
< Content-Length: 1385
< Server: Jetty(8.1.8.v20121106)
<
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Error 404 Not Found</title>
</head>
<body><h2>HTTP ERROR 404</h2>
<p>Problem accessing /heatmap/complex/path. Reason:
<pre>    Not Found</pre></p><hr /><i><small>Powered by Jetty://</small></i><br/>

<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>

</body>
</html>
* Connection #0 to host localhost left intact
* Closing connection #0

Basically the lookupHandlerMethod method of RepositoryRestHandlerMapping does not find any matching repository and returns null


Affects: 1.1.0.M1

4 votes, 6 watchers

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with RepositoryRestHandlerMapping.lookupHandlerMethod, using the repository @RestResource(path="complex/path") example and the reported GET request as the reproduction. Trace why the exported link does not resolve, then verify that /heatmap/complex/path is mapped successfully instead of returning 404.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.