From 39a53f6841924da8614458e1c147daa419a47c76 Mon Sep 17 00:00:00 2001 From: Jon Brisbin Date: Tue, 2 Oct 2012 10:37:26 -0500 Subject: [PATCH] Fix bug in URI-generation for links. --- .../rest/webmvc/json/JsonSchemaController.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/JsonSchemaController.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/JsonSchemaController.java index a8434ca7e..0ead75f0c 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/JsonSchemaController.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/JsonSchemaController.java @@ -12,7 +12,6 @@ import org.springframework.hateoas.Link; import org.springframework.hateoas.Resource; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.http.server.ServletServerHttpRequest; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -38,19 +37,25 @@ public class JsonSchemaController extends RepositoryExporterSupport schemaForRepository(ServletServerHttpRequest request, - URI baseUri, + public ResponseEntity schemaForRepository(URI baseUri, @PathVariable String repository) throws IOException { RepositoryMetadata repoMeta = repositoryMetadataFor(repository); if(null == repoMeta) { - throw new IllegalArgumentException("Resource /" + repository + "/schema not found."); + return new ResponseEntity(HttpStatus.NOT_FOUND); } JsonSchema schema = mapper.generateJsonSchema(repoMeta.domainType()); - URI requestUri = UriComponentsBuilder.fromUri(baseUri).path(repository).build().toUri(); + URI schemaUri = UriComponentsBuilder.fromUri(baseUri) + .pathSegment(repository, "schema") + .build() + .toUri(); + URI requestUri = UriComponentsBuilder.fromUri(baseUri) + .pathSegment(repository) + .build() + .toUri(); Resource resource = new Resource(schema, - new Link(request.getURI().toString(), "self"), + new Link(schemaUri.toString(), "self"), new Link(requestUri.toString(), repoMeta.rel())); String output = mapper.writeValueAsString(resource);