Fix bug with custom RequestCondition
A custom RequestCondition which can be provided by overriding methods in RequestMappingHandlerMapping worked only for conditions that match and did not return null (as it should have) for conditions that don't match. Issues: SPR-9134
This commit is contained in:
@@ -108,7 +108,7 @@ public final class RequestConditionHolder extends AbstractRequestCondition<Reque
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
RequestCondition<?> match = (RequestCondition<?>) condition.getMatchingCondition(request);
|
RequestCondition<?> match = (RequestCondition<?>) condition.getMatchingCondition(request);
|
||||||
return new RequestConditionHolder(match);
|
return (match != null) ? new RequestConditionHolder(match) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.springframework.web.servlet.mvc.condition;
|
package org.springframework.web.servlet.mvc.condition;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@@ -24,10 +25,6 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.mock.web.MockHttpServletRequest;
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.servlet.mvc.condition.HeadersRequestCondition;
|
|
||||||
import org.springframework.web.servlet.mvc.condition.ParamsRequestCondition;
|
|
||||||
import org.springframework.web.servlet.mvc.condition.RequestConditionHolder;
|
|
||||||
import org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A test fixture for
|
* A test fixture for
|
||||||
@@ -75,6 +72,16 @@ public class RequestConditionHolderTests {
|
|||||||
assertEquals(expected, custom.getMatchingCondition(request).getCondition());
|
assertEquals(expected, custom.getMatchingCondition(request).getCondition());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void noMatch() {
|
||||||
|
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
|
||||||
|
|
||||||
|
RequestMethodsRequestCondition rm = new RequestMethodsRequestCondition(RequestMethod.POST);
|
||||||
|
RequestConditionHolder custom = new RequestConditionHolder(rm);
|
||||||
|
|
||||||
|
assertNull(custom.getMatchingCondition(request));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchEmpty() {
|
public void matchEmpty() {
|
||||||
RequestConditionHolder empty = new RequestConditionHolder(null);
|
RequestConditionHolder empty = new RequestConditionHolder(null);
|
||||||
|
|||||||
Reference in New Issue
Block a user