Browse Source

Polishing

pull/1723/head
Juergen Hoeller 8 years ago
parent
commit
87abdb92da
  1. 16
      spring-test/src/main/java/org/springframework/mock/web/MockHttpSession.java
  2. 16
      spring-web/src/test/java/org/springframework/mock/web/test/MockHttpSession.java
  3. 9
      spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistration.java
  4. 20
      spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MappedInterceptor.java

16
spring-test/src/main/java/org/springframework/mock/web/MockHttpSession.java

@ -73,7 +73,6 @@ public class MockHttpSession implements HttpSession {
/** /**
* Create a new MockHttpSession with a default {@link MockServletContext}. * Create a new MockHttpSession with a default {@link MockServletContext}.
*
* @see MockServletContext * @see MockServletContext
*/ */
public MockHttpSession() { public MockHttpSession() {
@ -82,7 +81,6 @@ public class MockHttpSession implements HttpSession {
/** /**
* Create a new MockHttpSession. * Create a new MockHttpSession.
*
* @param servletContext the ServletContext that the session runs in * @param servletContext the ServletContext that the session runs in
*/ */
public MockHttpSession(ServletContext servletContext) { public MockHttpSession(ServletContext servletContext) {
@ -91,7 +89,6 @@ public class MockHttpSession implements HttpSession {
/** /**
* Create a new MockHttpSession. * Create a new MockHttpSession.
*
* @param servletContext the ServletContext that the session runs in * @param servletContext the ServletContext that the session runs in
* @param id a unique identifier for this session * @param id a unique identifier for this session
*/ */
@ -100,6 +97,7 @@ public class MockHttpSession implements HttpSession {
this.id = (id != null ? id : Integer.toString(nextId++)); this.id = (id != null ? id : Integer.toString(nextId++));
} }
@Override @Override
public long getCreationTime() { public long getCreationTime() {
assertIsValid(); assertIsValid();
@ -112,8 +110,8 @@ public class MockHttpSession implements HttpSession {
} }
/** /**
* As of Servlet 3.1 the id of a session can be changed. * As of Servlet 3.1, the id of a session can be changed.
* @return the new session id. * @return the new session id
* @since 4.0.3 * @since 4.0.3
*/ */
public String changeSessionId() { public String changeSessionId() {
@ -228,7 +226,6 @@ public class MockHttpSession implements HttpSession {
/** /**
* Invalidates this session then unbinds any objects bound to it. * Invalidates this session then unbinds any objects bound to it.
*
* @throws IllegalStateException if this method is called on an already invalidated session * @throws IllegalStateException if this method is called on an already invalidated session
*/ */
@Override @Override
@ -245,13 +242,10 @@ public class MockHttpSession implements HttpSession {
/** /**
* Convenience method for asserting that this session has not been * Convenience method for asserting that this session has not been
* {@linkplain #invalidate() invalidated}. * {@linkplain #invalidate() invalidated}.
*
* @throws IllegalStateException if this session has been invalidated * @throws IllegalStateException if this session has been invalidated
*/ */
private void assertIsValid() { private void assertIsValid() {
if (isInvalid()) { Assert.state(!isInvalid(), "The session has already been invalidated");
throw new IllegalStateException("The session has already been invalidated");
}
} }
public void setNew(boolean value) { public void setNew(boolean value) {
@ -267,7 +261,6 @@ public class MockHttpSession implements HttpSession {
/** /**
* Serialize the attributes of this session into an object that can be * Serialize the attributes of this session into an object that can be
* turned into a byte array with standard Java serialization. * turned into a byte array with standard Java serialization.
*
* @return a representation of this session's serialized state * @return a representation of this session's serialized state
*/ */
public Serializable serializeState() { public Serializable serializeState() {
@ -294,7 +287,6 @@ public class MockHttpSession implements HttpSession {
/** /**
* Deserialize the attributes of this session from a state object created by * Deserialize the attributes of this session from a state object created by
* {@link #serializeState()}. * {@link #serializeState()}.
*
* @param state a representation of this session's serialized state * @param state a representation of this session's serialized state
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

16
spring-web/src/test/java/org/springframework/mock/web/test/MockHttpSession.java

@ -73,7 +73,6 @@ public class MockHttpSession implements HttpSession {
/** /**
* Create a new MockHttpSession with a default {@link MockServletContext}. * Create a new MockHttpSession with a default {@link MockServletContext}.
*
* @see MockServletContext * @see MockServletContext
*/ */
public MockHttpSession() { public MockHttpSession() {
@ -82,7 +81,6 @@ public class MockHttpSession implements HttpSession {
/** /**
* Create a new MockHttpSession. * Create a new MockHttpSession.
*
* @param servletContext the ServletContext that the session runs in * @param servletContext the ServletContext that the session runs in
*/ */
public MockHttpSession(ServletContext servletContext) { public MockHttpSession(ServletContext servletContext) {
@ -91,7 +89,6 @@ public class MockHttpSession implements HttpSession {
/** /**
* Create a new MockHttpSession. * Create a new MockHttpSession.
*
* @param servletContext the ServletContext that the session runs in * @param servletContext the ServletContext that the session runs in
* @param id a unique identifier for this session * @param id a unique identifier for this session
*/ */
@ -100,6 +97,7 @@ public class MockHttpSession implements HttpSession {
this.id = (id != null ? id : Integer.toString(nextId++)); this.id = (id != null ? id : Integer.toString(nextId++));
} }
@Override @Override
public long getCreationTime() { public long getCreationTime() {
assertIsValid(); assertIsValid();
@ -112,8 +110,8 @@ public class MockHttpSession implements HttpSession {
} }
/** /**
* As of Servlet 3.1 the id of a session can be changed. * As of Servlet 3.1, the id of a session can be changed.
* @return the new session id. * @return the new session id
* @since 4.0.3 * @since 4.0.3
*/ */
public String changeSessionId() { public String changeSessionId() {
@ -228,7 +226,6 @@ public class MockHttpSession implements HttpSession {
/** /**
* Invalidates this session then unbinds any objects bound to it. * Invalidates this session then unbinds any objects bound to it.
*
* @throws IllegalStateException if this method is called on an already invalidated session * @throws IllegalStateException if this method is called on an already invalidated session
*/ */
@Override @Override
@ -245,13 +242,10 @@ public class MockHttpSession implements HttpSession {
/** /**
* Convenience method for asserting that this session has not been * Convenience method for asserting that this session has not been
* {@linkplain #invalidate() invalidated}. * {@linkplain #invalidate() invalidated}.
*
* @throws IllegalStateException if this session has been invalidated * @throws IllegalStateException if this session has been invalidated
*/ */
private void assertIsValid() { private void assertIsValid() {
if (isInvalid()) { Assert.state(!isInvalid(), "The session has already been invalidated");
throw new IllegalStateException("The session has already been invalidated");
}
} }
public void setNew(boolean value) { public void setNew(boolean value) {
@ -267,7 +261,6 @@ public class MockHttpSession implements HttpSession {
/** /**
* Serialize the attributes of this session into an object that can be * Serialize the attributes of this session into an object that can be
* turned into a byte array with standard Java serialization. * turned into a byte array with standard Java serialization.
*
* @return a representation of this session's serialized state * @return a representation of this session's serialized state
*/ */
public Serializable serializeState() { public Serializable serializeState() {
@ -294,7 +287,6 @@ public class MockHttpSession implements HttpSession {
/** /**
* Deserialize the attributes of this session from a state object created by * Deserialize the attributes of this session from a state object created by
* {@link #serializeState()}. * {@link #serializeState()}.
*
* @param state a representation of this session's serialized state * @param state a representation of this session's serialized state
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

9
spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistration.java

@ -45,13 +45,14 @@ public class InterceptorRegistration {
/** /**
* Creates an {@link InterceptorRegistration} instance. * Create an {@link InterceptorRegistration} instance.
*/ */
public InterceptorRegistration(HandlerInterceptor interceptor) { public InterceptorRegistration(HandlerInterceptor interceptor) {
Assert.notNull(interceptor, "Interceptor is required"); Assert.notNull(interceptor, "Interceptor is required");
this.interceptor = interceptor; this.interceptor = interceptor;
} }
/** /**
* Add URL patterns to which the registered interceptor should apply to. * Add URL patterns to which the registered interceptor should apply to.
*/ */
@ -80,8 +81,8 @@ public class InterceptorRegistration {
} }
/** /**
* Returns the underlying interceptor. If URL patterns are provided the returned type is * Build the underlying interceptor. If URL patterns are provided, the returned
* {@link MappedInterceptor}; otherwise {@link HandlerInterceptor}. * type is {@link MappedInterceptor}; otherwise {@link HandlerInterceptor}.
*/ */
protected Object getInterceptor() { protected Object getInterceptor() {
if (this.includePatterns.isEmpty() && this.excludePatterns.isEmpty()) { if (this.includePatterns.isEmpty() && this.excludePatterns.isEmpty()) {
@ -91,11 +92,9 @@ public class InterceptorRegistration {
String[] include = StringUtils.toStringArray(this.includePatterns); String[] include = StringUtils.toStringArray(this.includePatterns);
String[] exclude = StringUtils.toStringArray(this.excludePatterns); String[] exclude = StringUtils.toStringArray(this.excludePatterns);
MappedInterceptor mappedInterceptor = new MappedInterceptor(include, exclude, this.interceptor); MappedInterceptor mappedInterceptor = new MappedInterceptor(include, exclude, this.interceptor);
if (this.pathMatcher != null) { if (this.pathMatcher != null) {
mappedInterceptor.setPathMatcher(this.pathMatcher); mappedInterceptor.setPathMatcher(this.pathMatcher);
} }
return mappedInterceptor; return mappedInterceptor;
} }

20
spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MappedInterceptor.java

@ -76,7 +76,7 @@ public final class MappedInterceptor implements HandlerInterceptor {
/** /**
* Create a new MappedInterceptor instance. * Create a new MappedInterceptor instance.
* @param includePatterns the path patterns to map with a {@code null} value matching to all paths * @param includePatterns the path patterns to map (empty for matching to all paths)
* @param interceptor the WebRequestInterceptor instance to map to the given patterns * @param interceptor the WebRequestInterceptor instance to map to the given patterns
*/ */
public MappedInterceptor(String[] includePatterns, WebRequestInterceptor interceptor) { public MappedInterceptor(String[] includePatterns, WebRequestInterceptor interceptor) {
@ -85,7 +85,8 @@ public final class MappedInterceptor implements HandlerInterceptor {
/** /**
* Create a new MappedInterceptor instance. * Create a new MappedInterceptor instance.
* @param includePatterns the path patterns to map with a {@code null} value matching to all paths * @param includePatterns the path patterns to map (empty for matching to all paths)
* @param excludePatterns the path patterns to exclude (empty for no specific excludes)
* @param interceptor the WebRequestInterceptor instance to map to the given patterns * @param interceptor the WebRequestInterceptor instance to map to the given patterns
*/ */
public MappedInterceptor(String[] includePatterns, String[] excludePatterns, WebRequestInterceptor interceptor) { public MappedInterceptor(String[] includePatterns, String[] excludePatterns, WebRequestInterceptor interceptor) {
@ -94,11 +95,11 @@ public final class MappedInterceptor implements HandlerInterceptor {
/** /**
* Configure a PathMatcher to use with this MappedInterceptor instead of the * Configure a PathMatcher to use with this MappedInterceptor instead of the one passed
* one passed by default to the {@link #matches(String, org.springframework.util.PathMatcher)} * by default to the {@link #matches(String, org.springframework.util.PathMatcher)} method.
* method. This is an advanced property that is only required when using custom * <p>This is an advanced property that is only required when using custom PathMatcher
* PathMatcher implementations that support mapping metadata other than the * implementations that support mapping metadata other than the Ant-style path patterns
* Ant-style path patterns supported by default. * supported by default.
*/ */
public void setPathMatcher(PathMatcher pathMatcher) { public void setPathMatcher(PathMatcher pathMatcher) {
this.pathMatcher = pathMatcher; this.pathMatcher = pathMatcher;
@ -119,14 +120,15 @@ public final class MappedInterceptor implements HandlerInterceptor {
} }
/** /**
* The actual Interceptor reference. * The actual {@link HandlerInterceptor} reference.
*/ */
public HandlerInterceptor getInterceptor() { public HandlerInterceptor getInterceptor() {
return this.interceptor; return this.interceptor;
} }
/** /**
* Returns {@code true} if the interceptor applies to the given request path. * Determine a match for the given lookup path.
* @param lookupPath the current request path * @param lookupPath the current request path
* @param pathMatcher a path matcher for path pattern matching * @param pathMatcher a path matcher for path pattern matching
*/ */

Loading…
Cancel
Save