Browse Source

Polishing

pull/1480/merge
Juergen Hoeller 9 years ago
parent
commit
ac1d3b22c9
  1. 2
      spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyUtils.java
  2. 6
      spring-context/src/test/java/org/springframework/aop/scope/ScopedProxyTests.java
  3. 20
      spring-context/src/test/resources/org/springframework/aop/scope/ScopedProxyTests-override.xml
  4. 8
      spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java
  5. 16
      spring-web/src/main/java/org/springframework/web/filter/RelativeRedirectFilter.java
  6. 7
      spring-web/src/main/java/org/springframework/web/filter/RelativeRedirectResponseWrapper.java
  7. 9
      spring-web/src/test/java/org/springframework/web/filter/ForwardedHeaderFilterTests.java
  8. 7
      spring-web/src/test/java/org/springframework/web/filter/RelativeRedirectFilterTests.java
  9. 2
      spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RedirectView.java
  10. 2
      spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/RedirectViewControllerRegistration.java

2
spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyUtils.java

@ -90,7 +90,7 @@ public abstract class ScopedProxyUtils {
} }
/** /**
* Generates the bean name that is used within the scoped proxy to reference the target bean. * Generate the bean name that is used within the scoped proxy to reference the target bean.
* @param originalBeanName the original name of bean * @param originalBeanName the original name of bean
* @return the generated bean to be used to reference the target bean * @return the generated bean to be used to reference the target bean
*/ */

6
spring-context/src/test/java/org/springframework/aop/scope/ScopedProxyTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -49,8 +49,8 @@ public class ScopedProxyTests {
private static final ClassPathResource OVERRIDE_CONTEXT = new ClassPathResource(CLASSNAME + "-override.xml", CLASS); private static final ClassPathResource OVERRIDE_CONTEXT = new ClassPathResource(CLASSNAME + "-override.xml", CLASS);
private static final ClassPathResource TESTBEAN_CONTEXT = new ClassPathResource(CLASSNAME + "-testbean.xml", CLASS); private static final ClassPathResource TESTBEAN_CONTEXT = new ClassPathResource(CLASSNAME + "-testbean.xml", CLASS);
/* SPR-2108 */
@Test @Test // SPR-2108
public void testProxyAssignable() throws Exception { public void testProxyAssignable() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(MAP_CONTEXT); new XmlBeanDefinitionReader(bf).loadBeanDefinitions(MAP_CONTEXT);

20
spring-context/src/test/resources/org/springframework/aop/scope/ScopedProxyTests-override.xml

@ -6,16 +6,16 @@
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<bean id="testBean" class="org.springframework.tests.sample.beans.TestBean" scope="request"> <bean id="testBean" class="org.springframework.tests.sample.beans.TestBean" scope="request">
<aop:scoped-proxy proxy-target-class="false"/> <aop:scoped-proxy proxy-target-class="false"/>
<property name="age" value="99"/> <property name="age" value="99"/>
</bean> </bean>
<bean class="org.springframework.beans.factory.config.PropertyOverrideConfigurer"> <bean class="org.springframework.beans.factory.config.PropertyOverrideConfigurer">
<property name="properties"> <property name="properties">
<map> <map>
<entry key="testBean.sex" value="male"/> <entry key="testBean.sex" value="male"/>
</map> </map>
</property> </property>
</bean> </bean>
</beans> </beans>

8
spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java

@ -93,7 +93,7 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter {
/** /**
* Enables mode in which any "Forwarded" or "X-Forwarded-*" headers are * Enables mode in which any "Forwarded" or "X-Forwarded-*" headers are
* removed only and the information in them ignored. * removed only and the information in them ignored.
* @param removeOnly whether to discard and ingore forwarded headers * @param removeOnly whether to discard and ignore forwarded headers
* @since 4.3.9 * @since 4.3.9
*/ */
public void setRemoveOnly(boolean removeOnly) { public void setRemoveOnly(boolean removeOnly) {
@ -109,7 +109,7 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter {
* to turn relative into absolute URLs since (which Servlet containers are * to turn relative into absolute URLs since (which Servlet containers are
* also required to do) also taking forwarded headers into consideration. * also required to do) also taking forwarded headers into consideration.
* @param relativeRedirects whether to use relative redirects * @param relativeRedirects whether to use relative redirects
* @since 5.0 * @since 4.3.10
*/ */
public void setRelativeRedirects(boolean relativeRedirects) { public void setRelativeRedirects(boolean relativeRedirects) {
this.relativeRedirects = relativeRedirects; this.relativeRedirects = relativeRedirects;
@ -148,9 +148,9 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter {
} }
else { else {
HttpServletRequest theRequest = new ForwardedHeaderExtractingRequest(request, this.pathHelper); HttpServletRequest theRequest = new ForwardedHeaderExtractingRequest(request, this.pathHelper);
HttpServletResponse theResponse = this.relativeRedirects ? HttpServletResponse theResponse = (this.relativeRedirects ?
RelativeRedirectResponseWrapper.wrapIfNecessary(response, HttpStatus.SEE_OTHER) : RelativeRedirectResponseWrapper.wrapIfNecessary(response, HttpStatus.SEE_OTHER) :
new ForwardedHeaderExtractingResponse(response, theRequest); new ForwardedHeaderExtractingResponse(response, theRequest));
filterChain.doFilter(theRequest, theResponse); filterChain.doFilter(theRequest, theResponse);
} }
} }

16
spring-web/src/main/java/org/springframework/web/filter/RelativeRedirectFilter.java

@ -16,14 +16,14 @@
package org.springframework.web.filter; package org.springframework.web.filter;
import org.springframework.http.HttpStatus; import java.io.IOException;
import org.springframework.util.Assert;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import org.springframework.http.HttpStatus;
import org.springframework.util.Assert;
/** /**
* Overrides {@link HttpServletResponse#sendRedirect(String)} and handles it by * Overrides {@link HttpServletResponse#sendRedirect(String)} and handles it by
@ -32,12 +32,12 @@ import java.io.IOException;
* recommendation in <a href="https://tools.ietf.org/html/rfc7231#section-7.1.2"> * recommendation in <a href="https://tools.ietf.org/html/rfc7231#section-7.1.2">
* RFC 7231 Section 7.1.2</a>. * RFC 7231 Section 7.1.2</a>.
* *
* <p><strong>Note:</strong> while relative redirects are more efficient they * <p><strong>Note:</strong> While relative redirects are more efficient they
* may not work with reverse proxies under some configurations. * may not work with reverse proxies under some configurations.
* *
* @author Rob Winch * @author Rob Winch
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @since 5.0 * @since 4.3.10
*/ */
public class RelativeRedirectFilter extends OncePerRequestFilter { public class RelativeRedirectFilter extends OncePerRequestFilter {
@ -50,8 +50,8 @@ public class RelativeRedirectFilter extends OncePerRequestFilter {
* @param status the 3xx redirect status to use * @param status the 3xx redirect status to use
*/ */
public void setRedirectStatus(HttpStatus status) { public void setRedirectStatus(HttpStatus status) {
Assert.notNull(status, "HttpStatus is required"); Assert.notNull(status, "Property 'redirectStatus' is required");
Assert.isTrue(status.is3xxRedirection(), "Not a redirect status: " + status); Assert.isTrue(status.is3xxRedirection(), "Not a redirect status code");
this.redirectStatus = status; this.redirectStatus = status;
} }

7
spring-web/src/main/java/org/springframework/web/filter/RelativeRedirectResponseWrapper.java

@ -29,7 +29,7 @@ import org.springframework.util.Assert;
* {@link RelativeRedirectFilter} also shared with {@link ForwardedHeaderFilter}. * {@link RelativeRedirectFilter} also shared with {@link ForwardedHeaderFilter}.
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @since 5.0 * @since 4.3.10
*/ */
class RelativeRedirectResponseWrapper extends HttpServletResponseWrapper { class RelativeRedirectResponseWrapper extends HttpServletResponseWrapper {
@ -38,7 +38,7 @@ class RelativeRedirectResponseWrapper extends HttpServletResponseWrapper {
private RelativeRedirectResponseWrapper(HttpServletResponse response, HttpStatus redirectStatus) { private RelativeRedirectResponseWrapper(HttpServletResponse response, HttpStatus redirectStatus) {
super(response); super(response);
Assert.notNull(redirectStatus, "'redirectStatus' is required."); Assert.notNull(redirectStatus, "'redirectStatus' is required");
this.redirectStatus = redirectStatus; this.redirectStatus = redirectStatus;
} }
@ -53,8 +53,7 @@ class RelativeRedirectResponseWrapper extends HttpServletResponseWrapper {
public static HttpServletResponse wrapIfNecessary(HttpServletResponse response, public static HttpServletResponse wrapIfNecessary(HttpServletResponse response,
HttpStatus redirectStatus) { HttpStatus redirectStatus) {
return hasWrapper(response) ? response : return (hasWrapper(response) ? response : new RelativeRedirectResponseWrapper(response, redirectStatus));
new RelativeRedirectResponseWrapper(response, redirectStatus);
} }
private static boolean hasWrapper(ServletResponse response) { private static boolean hasWrapper(ServletResponse response) {

9
spring-web/src/test/java/org/springframework/web/filter/ForwardedHeaderFilterTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -32,10 +32,7 @@ import org.springframework.mock.web.test.MockFilterChain;
import org.springframework.mock.web.test.MockHttpServletRequest; import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse; import org.springframework.mock.web.test.MockHttpServletResponse;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/** /**
* Unit tests for {@link ForwardedHeaderFilter}. * Unit tests for {@link ForwardedHeaderFilter}.
@ -61,7 +58,7 @@ public class ForwardedHeaderFilterTests {
@Before @Before
@SuppressWarnings("serial") @SuppressWarnings("serial")
public void setUp() throws Exception { public void setup() throws Exception {
this.request = new MockHttpServletRequest(); this.request = new MockHttpServletRequest();
this.request.setScheme("http"); this.request.setScheme("http");
this.request.setServerName("localhost"); this.request.setServerName("localhost");

7
spring-web/src/test/java/org/springframework/web/filter/RelativeRedirectFilterTests.java

@ -32,11 +32,11 @@ import org.springframework.mock.web.test.MockFilterChain;
import org.springframework.mock.web.test.MockHttpServletRequest; import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse; import org.springframework.mock.web.test.MockHttpServletResponse;
import static org.junit.Assert.assertNotSame; import static org.junit.Assert.*;
import static org.junit.Assert.assertSame;
/** /**
* Unit tests for {@link RelativeRedirectFilter}. * Unit tests for {@link RelativeRedirectFilter}.
*
* @author Rob Winch * @author Rob Winch
*/ */
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
@ -110,4 +110,5 @@ public class RelativeRedirectFilterTests {
HttpServletResponse wrappedResponse = (HttpServletResponse) chain.getResponse(); HttpServletResponse wrappedResponse = (HttpServletResponse) chain.getResponse();
wrappedResponse.sendRedirect(location); wrappedResponse.sendRedirect(location);
} }
}
}

2
spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RedirectView.java

@ -113,7 +113,7 @@ public class RedirectView extends AbstractUrlBasedView {
* {@link HttpStatus#PERMANENT_REDIRECT}. * {@link HttpStatus#PERMANENT_REDIRECT}.
*/ */
public void setStatusCode(HttpStatus statusCode) { public void setStatusCode(HttpStatus statusCode) {
Assert.isTrue(statusCode.is3xxRedirection(), "Must be a redirection (3xx status code)"); Assert.isTrue(statusCode.is3xxRedirection(), "Not a redirect status code");
this.statusCode = statusCode; this.statusCode = statusCode;
} }

2
spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/RedirectViewControllerRegistration.java

@ -54,7 +54,7 @@ public class RedirectViewControllerRegistration {
* will select {@code HttpStatus.MOVED_TEMPORARILY (302)} by default. * will select {@code HttpStatus.MOVED_TEMPORARILY (302)} by default.
*/ */
public RedirectViewControllerRegistration setStatusCode(HttpStatus statusCode) { public RedirectViewControllerRegistration setStatusCode(HttpStatus statusCode) {
Assert.isTrue(statusCode.is3xxRedirection(), "Not a redirect status code."); Assert.isTrue(statusCode.is3xxRedirection(), "Not a redirect status code");
this.redirectView.setStatusCode(statusCode); this.redirectView.setStatusCode(statusCode);
return this; return this;
} }

Loading…
Cancel
Save