Polishing

This commit is contained in:
Juergen Hoeller 2017-07-19 22:22:27 +02:00
parent 46eba3dbfa
commit ac1d3b22c9
10 changed files with 38 additions and 41 deletions

View File

@ -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
* @return the generated bean to be used to reference the target bean
*/

View File

@ -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");
* 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 TESTBEAN_CONTEXT = new ClassPathResource(CLASSNAME + "-testbean.xml", CLASS);
/* SPR-2108 */
@Test
@Test // SPR-2108
public void testProxyAssignable() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(MAP_CONTEXT);

View File

@ -6,16 +6,16 @@
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">
<aop:scoped-proxy proxy-target-class="false"/>
<property name="age" value="99"/>
</bean>
<aop:scoped-proxy proxy-target-class="false"/>
<property name="age" value="99"/>
</bean>
<bean class="org.springframework.beans.factory.config.PropertyOverrideConfigurer">
<property name="properties">
<map>
<entry key="testBean.sex" value="male"/>
</map>
</property>
</bean>
<bean class="org.springframework.beans.factory.config.PropertyOverrideConfigurer">
<property name="properties">
<map>
<entry key="testBean.sex" value="male"/>
</map>
</property>
</bean>
</beans>

View File

@ -93,7 +93,7 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter {
/**
* Enables mode in which any "Forwarded" or "X-Forwarded-*" headers are
* 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
*/
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
* also required to do) also taking forwarded headers into consideration.
* @param relativeRedirects whether to use relative redirects
* @since 5.0
* @since 4.3.10
*/
public void setRelativeRedirects(boolean relativeRedirects) {
this.relativeRedirects = relativeRedirects;
@ -148,9 +148,9 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter {
}
else {
HttpServletRequest theRequest = new ForwardedHeaderExtractingRequest(request, this.pathHelper);
HttpServletResponse theResponse = this.relativeRedirects ?
HttpServletResponse theResponse = (this.relativeRedirects ?
RelativeRedirectResponseWrapper.wrapIfNecessary(response, HttpStatus.SEE_OTHER) :
new ForwardedHeaderExtractingResponse(response, theRequest);
new ForwardedHeaderExtractingResponse(response, theRequest));
filterChain.doFilter(theRequest, theResponse);
}
}

View File

@ -16,14 +16,14 @@
package org.springframework.web.filter;
import org.springframework.http.HttpStatus;
import org.springframework.util.Assert;
import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
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
@ -32,12 +32,12 @@ import java.io.IOException;
* recommendation in <a href="https://tools.ietf.org/html/rfc7231#section-7.1.2">
* 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.
*
* @author Rob Winch
* @author Rossen Stoyanchev
* @since 5.0
* @since 4.3.10
*/
public class RelativeRedirectFilter extends OncePerRequestFilter {
@ -50,8 +50,8 @@ public class RelativeRedirectFilter extends OncePerRequestFilter {
* @param status the 3xx redirect status to use
*/
public void setRedirectStatus(HttpStatus status) {
Assert.notNull(status, "HttpStatus is required");
Assert.isTrue(status.is3xxRedirection(), "Not a redirect status: " + status);
Assert.notNull(status, "Property 'redirectStatus' is required");
Assert.isTrue(status.is3xxRedirection(), "Not a redirect status code");
this.redirectStatus = status;
}

View File

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

View File

@ -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");
* 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.MockHttpServletResponse;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
/**
* Unit tests for {@link ForwardedHeaderFilter}.
@ -61,7 +58,7 @@ public class ForwardedHeaderFilterTests {
@Before
@SuppressWarnings("serial")
public void setUp() throws Exception {
public void setup() throws Exception {
this.request = new MockHttpServletRequest();
this.request.setScheme("http");
this.request.setServerName("localhost");

View File

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

View File

@ -113,7 +113,7 @@ public class RedirectView extends AbstractUrlBasedView {
* {@link HttpStatus#PERMANENT_REDIRECT}.
*/
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;
}

View File

@ -54,7 +54,7 @@ public class RedirectViewControllerRegistration {
* will select {@code HttpStatus.MOVED_TEMPORARILY (302)} by default.
*/
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);
return this;
}