From df8a8912cdc907952cf7b07905d99d4b5db52167 Mon Sep 17 00:00:00 2001 From: Jon Brisbin Date: Wed, 16 May 2012 10:48:22 -0500 Subject: [PATCH] Changed the POST/create method to look for the query parameter "returnBody" and, if present and set to "true", return the entity in the body of the response. If it is not present or set to "false", then no content is returned in the body of the response, which is the current behaviour. --- .../data/rest/webmvc/RepositoryRestController.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestController.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestController.java index 8d02b92ec..2c8c50aa2 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestController.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestController.java @@ -17,6 +17,7 @@ import java.util.Map; import java.util.Set; import java.util.Stack; import java.util.concurrent.atomic.AtomicReference; +import javax.servlet.http.HttpServletRequest; import org.codehaus.jackson.map.ObjectMapper; import org.springframework.beans.BeansException; @@ -410,6 +411,7 @@ public class RepositoryRestController } ) public ModelAndView create(ServerHttpRequest request, + HttpServletRequest servletRequest, UriComponentsBuilder uriBuilder, @PathVariable String repository) throws IOException { URI baseUri = uriBuilder.build().toUri(); @@ -438,6 +440,14 @@ public class RepositoryRestController model.put(HEADERS, headers); model.put(STATUS, HttpStatus.CREATED); + if (null != servletRequest.getParameter("returnBody") && "true".equals(servletRequest.getParameter("returnBody"))) { + Map entityDto = extractPropertiesLinkAware(repoMeta.rel(), + savedEntity, + repoMeta.entityMetadata(), + buildUri(baseUri, repository, sId)); + addSelfLink(baseUri, entityDto, repository, sId); + model.put(RESOURCE, entityDto); + } } return new ModelAndView(viewName("after_create"), model); }