diff --git a/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/AbstractWebIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/AbstractWebIntegrationTests.java index cba3785b8..27ed9089d 100644 --- a/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/AbstractWebIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/AbstractWebIntegrationTests.java @@ -46,6 +46,7 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration; import com.jayway.jsonpath.InvalidPathException; import com.jayway.jsonpath.JsonPath; @@ -61,7 +62,7 @@ import com.jayway.jsonpath.JsonPath; */ @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration -@ContextConfiguration(classes = RepositoryRestMvcConfiguration.class) +@ContextConfiguration(classes = { RepositoryRestMvcConfiguration.class, DelegatingWebMvcConfiguration.class }) public abstract class AbstractWebIntegrationTests { private static final String CONTENT_LINK_JSONPATH = "$._embedded.._links.%s.href"; diff --git a/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/CommonWebTests.java b/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/CommonWebTests.java index fe7ba0a35..e0842ceeb 100644 --- a/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/CommonWebTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/CommonWebTests.java @@ -267,4 +267,17 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests { // PATCH to non-existing resource mvc.perform(patch(URI.create(uri))).andExpect(status().isNotFound()); } + + @Test // DATAREST-1003 + public void rejectsUnsupportedAcceptTypeForResources() throws Exception { + + for (String string : expectedRootLinkRels()) { + + Link link = client.discoverUnique(string); + + mvc.perform(get(link.expand().getHref())// + .accept(MediaType.valueOf("application/schema+json")))// + .andExpect(status().isNotAcceptable()); + } + } } diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMapping.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMapping.java index 7e669eaa6..1ad7c94c8 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMapping.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMapping.java @@ -28,7 +28,6 @@ import org.springframework.data.rest.core.config.RepositoryRestConfiguration; import org.springframework.data.rest.core.mapping.ResourceMappings; import org.springframework.data.rest.webmvc.support.JpaHelper; import org.springframework.http.MediaType; -import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; import org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -48,9 +47,6 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl */ public class RepositoryRestHandlerMapping extends BasePathAwareHandlerMapping { - private static final MediaType EVERYTHING_JSON_MEDIA_TYPE = new MediaType("application", "*+json", - AbstractJackson2HttpMessageConverter.DEFAULT_CHARSET); - private final ResourceMappings mappings; private final RepositoryRestConfiguration configuration; @@ -150,7 +146,6 @@ public class RepositoryRestHandlerMapping extends BasePathAwareHandlerMapping { HashSet mediaTypes = new LinkedHashSet(); mediaTypes.add(configuration.getDefaultMediaType().toString()); mediaTypes.add(MediaType.APPLICATION_JSON_VALUE); - mediaTypes.add(EVERYTHING_JSON_MEDIA_TYPE.toString()); return new ProducesRequestCondition(mediaTypes.toArray(new String[mediaTypes.size()])); }