-
Notifications
You must be signed in to change notification settings - Fork 560
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DATAREST-333 - Added controller mappings for OPTIONS requests.
The root resource, collection and item resources as well as the search and query method resources now expose a handler method to handle OPTIONS requests and return a response with the Allow header set to the HTTP methods appropriate to the resource requested. Added some additional methods for HEAD requests and a few integration tests for functionality that previously existed. Related ticket: DATAREST-330.
- Loading branch information
Showing
10 changed files
with
298 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
.../test/java/org/springframework/data/rest/webmvc/RepositoryControllerIntegrationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2014 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.rest.webmvc; | ||
|
||
import static org.hamcrest.Matchers.*; | ||
import static org.junit.Assert.*; | ||
import static org.springframework.data.rest.webmvc.WebTestUtils.*; | ||
|
||
import org.junit.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.rest.webmvc.jpa.JpaRepositoryConfig; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
/** | ||
* Integration tests for {@link RepositoryController}. | ||
* | ||
* @author Oliver Gierke | ||
*/ | ||
@ContextConfiguration(classes = JpaRepositoryConfig.class) | ||
@Transactional | ||
public class RepositoryControllerIntegrationTests extends AbstractControllerIntegrationTests { | ||
|
||
@Autowired RepositoryController controller; | ||
|
||
/** | ||
* @see DATAREST-333 | ||
*/ | ||
@Test | ||
public void rootResourceExposesGetOnly() { | ||
|
||
HttpEntity<?> response = controller.optionsForRepositories(); | ||
assertAllowHeaders(response, HttpMethod.GET); | ||
} | ||
|
||
/** | ||
* @see DATAREST-333, DATAREST-330 | ||
*/ | ||
@Test | ||
public void headRequestReturnsNoContent() { | ||
assertThat(controller.headForRepositories().getStatusCode(), is(HttpStatus.NO_CONTENT)); | ||
} | ||
|
||
@Test | ||
public void exposesLinksToRepositories() { | ||
|
||
RepositoryLinksResource resource = controller.listRepositories().getBody(); | ||
|
||
assertThat(resource.getLinks(), hasSize(5)); | ||
|
||
assertThat(resource.hasLink("people"), is(true)); | ||
assertThat(resource.hasLink("orders"), is(true)); | ||
assertThat(resource.hasLink("addresses"), is(true)); | ||
assertThat(resource.hasLink("books"), is(true)); | ||
assertThat(resource.hasLink("authors"), is(true)); | ||
} | ||
} |
Oops, something went wrong.
This line breaks my setup. I have my rest configuration configured in a separate jar like this:
and also my storefront war (holds the rest jar in WEB-INF/lib) configured like this:
and now that I try to access the http://localhost:8111/storefront/ I get an exception that there are multiple controllers mapped to / :
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP
path 'http://localhost:8111/storefront/': {public java.lang.String com.xxxx.storefront.controllers.pages.HomePageController.home(org.springframework.ui.Model,java.lang
.String,javax.servlet.http.HttpServletRequest), public org.springframework.http.HttpEntity org.springframework.data.rest.webmvc.RepositoryController.listRepositories()}
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:973)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:711)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1644)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
...