Polishing
This commit is contained in:
@@ -48,7 +48,7 @@ import org.springframework.util.ReflectionUtils;
|
|||||||
*/
|
*/
|
||||||
abstract class AbstractRecursiveAnnotationVisitor extends AnnotationVisitor {
|
abstract class AbstractRecursiveAnnotationVisitor extends AnnotationVisitor {
|
||||||
|
|
||||||
protected final Log logger = LogFactory.getLog(this.getClass());
|
protected final Log logger = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
protected final AnnotationAttributes attributes;
|
protected final AnnotationAttributes attributes;
|
||||||
|
|
||||||
@@ -94,10 +94,10 @@ abstract class AbstractRecursiveAnnotationVisitor extends AnnotationVisitor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (ClassNotFoundException ex) {
|
catch (ClassNotFoundException ex) {
|
||||||
this.logger.debug("Failed to classload enum type while reading annotation metadata", ex);
|
logger.debug("Failed to classload enum type while reading annotation metadata", ex);
|
||||||
}
|
}
|
||||||
catch (IllegalAccessException ex) {
|
catch (IllegalAccessException ex) {
|
||||||
this.logger.warn("Could not access enum value while reading annotation metadata", ex);
|
logger.warn("Could not access enum value while reading annotation metadata", ex);
|
||||||
}
|
}
|
||||||
return valueToUse;
|
return valueToUse;
|
||||||
}
|
}
|
||||||
@@ -169,7 +169,6 @@ class RecursiveAnnotationAttributesVisitor extends AbstractRecursiveAnnotationVi
|
|||||||
|
|
||||||
private final String annotationType;
|
private final String annotationType;
|
||||||
|
|
||||||
|
|
||||||
public RecursiveAnnotationAttributesVisitor(String annotationType, AnnotationAttributes attributes,
|
public RecursiveAnnotationAttributesVisitor(String annotationType, AnnotationAttributes attributes,
|
||||||
ClassLoader classLoader) {
|
ClassLoader classLoader) {
|
||||||
super(classLoader, attributes);
|
super(classLoader, attributes);
|
||||||
@@ -183,8 +182,8 @@ class RecursiveAnnotationAttributesVisitor extends AbstractRecursiveAnnotationVi
|
|||||||
doVisitEnd(annotationClass);
|
doVisitEnd(annotationClass);
|
||||||
}
|
}
|
||||||
catch (ClassNotFoundException ex) {
|
catch (ClassNotFoundException ex) {
|
||||||
this.logger.debug("Failed to class-load type while reading annotation metadata. "
|
logger.debug("Failed to class-load type while reading annotation metadata. " +
|
||||||
+ "This is a non-fatal error, but certain annotation metadata may be unavailable.", ex);
|
"This is a non-fatal error, but certain annotation metadata may be unavailable.", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,7 +245,6 @@ final class AnnotationAttributesReadingVisitor extends RecursiveAnnotationAttrib
|
|||||||
|
|
||||||
private final Map<String, Set<String>> metaAnnotationMap;
|
private final Map<String, Set<String>> metaAnnotationMap;
|
||||||
|
|
||||||
|
|
||||||
public AnnotationAttributesReadingVisitor(String annotationType,
|
public AnnotationAttributesReadingVisitor(String annotationType,
|
||||||
MultiValueMap<String, AnnotationAttributes> attributesMap, Map<String, Set<String>> metaAnnotationMap,
|
MultiValueMap<String, AnnotationAttributes> attributesMap, Map<String, Set<String>> metaAnnotationMap,
|
||||||
ClassLoader classLoader) {
|
ClassLoader classLoader) {
|
||||||
@@ -257,7 +255,6 @@ final class AnnotationAttributesReadingVisitor extends RecursiveAnnotationAttrib
|
|||||||
this.metaAnnotationMap = metaAnnotationMap;
|
this.metaAnnotationMap = metaAnnotationMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doVisitEnd(Class<?> annotationClass) {
|
public void doVisitEnd(Class<?> annotationClass) {
|
||||||
super.doVisitEnd(annotationClass);
|
super.doVisitEnd(annotationClass);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 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.
|
||||||
@@ -19,8 +19,8 @@ package org.springframework.core.type.filter;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.springframework.core.type.ClassMetadata;
|
import org.springframework.core.type.ClassMetadata;
|
||||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
|
||||||
import org.springframework.core.type.classreading.MetadataReader;
|
import org.springframework.core.type.classreading.MetadataReader;
|
||||||
|
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type filter that exposes a
|
* Type filter that exposes a
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 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.
|
||||||
@@ -29,8 +29,8 @@ import org.aspectj.weaver.patterns.PatternParser;
|
|||||||
import org.aspectj.weaver.patterns.SimpleScope;
|
import org.aspectj.weaver.patterns.SimpleScope;
|
||||||
import org.aspectj.weaver.patterns.TypePattern;
|
import org.aspectj.weaver.patterns.TypePattern;
|
||||||
|
|
||||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
|
||||||
import org.springframework.core.type.classreading.MetadataReader;
|
import org.springframework.core.type.classreading.MetadataReader;
|
||||||
|
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type filter that uses AspectJ type pattern for matching.
|
* Type filter that uses AspectJ type pattern for matching.
|
||||||
|
|||||||
@@ -310,7 +310,7 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
|
|||||||
|
|
||||||
resolvers.addAll(getCustomArgumentResolvers());
|
resolvers.addAll(getCustomArgumentResolvers());
|
||||||
resolvers.add(new PayloadArgumentResolver(this.messageConverter,
|
resolvers.add(new PayloadArgumentResolver(this.messageConverter,
|
||||||
(this.validator != null ? this.validator : new NoopValidator())));
|
(this.validator != null ? this.validator : new NoOpValidator())));
|
||||||
|
|
||||||
return resolvers;
|
return resolvers;
|
||||||
}
|
}
|
||||||
@@ -458,7 +458,7 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static final class NoopValidator implements Validator {
|
private static final class NoOpValidator implements Validator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supports(Class<?> clazz) {
|
public boolean supports(Class<?> clazz) {
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ import org.springframework.mock.web.MockHttpServletRequest;
|
|||||||
import org.springframework.mock.web.MockHttpServletResponse;
|
import org.springframework.mock.web.MockHttpServletResponse;
|
||||||
import org.springframework.mock.web.MockHttpSession;
|
import org.springframework.mock.web.MockHttpSession;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
@@ -57,11 +56,11 @@ import org.springframework.web.util.UriComponentsBuilder;
|
|||||||
import org.springframework.web.util.UriUtils;
|
import org.springframework.web.util.UriUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default builder for {@link MockHttpServletRequest} required as input to
|
* Default builder for {@link MockHttpServletRequest} required as input to perform
|
||||||
* perform request in {@link MockMvc}.
|
* requests in {@link MockMvc}.
|
||||||
*
|
*
|
||||||
* <p>Application tests will typically access this builder through the static
|
* <p>Application tests will typically access this builder through the static factory
|
||||||
* factory methods in {@link MockMvcBuilders}.
|
* methods in {@link org.springframework.test.web.servlet.setup.MockMvcBuilders}.
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
@@ -70,7 +69,6 @@ import org.springframework.web.util.UriUtils;
|
|||||||
public class MockHttpServletRequestBuilder
|
public class MockHttpServletRequestBuilder
|
||||||
implements ConfigurableSmartRequestBuilder<MockHttpServletRequestBuilder>, Mergeable {
|
implements ConfigurableSmartRequestBuilder<MockHttpServletRequestBuilder>, Mergeable {
|
||||||
|
|
||||||
|
|
||||||
private final HttpMethod method;
|
private final HttpMethod method;
|
||||||
|
|
||||||
private final UriComponents uriComponents;
|
private final UriComponents uriComponents;
|
||||||
@@ -144,6 +142,7 @@ public class MockHttpServletRequestBuilder
|
|||||||
this.uriComponents = UriComponentsBuilder.fromUri(uri).build();
|
this.uriComponents = UriComponentsBuilder.fromUri(uri).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a request parameter to the {@link MockHttpServletRequest}.
|
* Add a request parameter to the {@link MockHttpServletRequest}.
|
||||||
* If called more than once, the new values are added.
|
* If called more than once, the new values are added.
|
||||||
@@ -429,6 +428,7 @@ public class MockHttpServletRequestBuilder
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
* @return always returns {@code true}.
|
* @return always returns {@code true}.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 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.
|
||||||
@@ -18,20 +18,21 @@ package org.springframework.web.filter;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import javax.servlet.FilterChain;
|
import javax.servlet.FilterChain;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.ServletRequest;
|
import javax.servlet.ServletRequest;
|
||||||
import javax.servlet.ServletResponse;
|
import javax.servlet.ServletResponse;
|
||||||
import javax.servlet.ServletException;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import static org.junit.Assert.*;
|
import org.junit.Test;
|
||||||
|
|
||||||
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 org.springframework.util.FileCopyUtils;
|
import org.springframework.util.FileCopyUtils;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@link AbstractRequestLoggingFilter} and sub classes.
|
* Test for {@link AbstractRequestLoggingFilter} and sub classes.
|
||||||
*
|
*
|
||||||
@@ -41,11 +42,13 @@ public class RequestLoggingFilterTests {
|
|||||||
|
|
||||||
private MyRequestLoggingFilter filter;
|
private MyRequestLoggingFilter filter;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void createFilter() throws Exception {
|
public void createFilter() throws Exception {
|
||||||
filter = new MyRequestLoggingFilter();
|
filter = new MyRequestLoggingFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void uri() throws Exception {
|
public void uri() throws Exception {
|
||||||
final MockHttpServletRequest request = new MockHttpServletRequest("POST", "/hotels");
|
final MockHttpServletRequest request = new MockHttpServletRequest("POST", "/hotels");
|
||||||
@@ -53,17 +56,17 @@ public class RequestLoggingFilterTests {
|
|||||||
|
|
||||||
request.setQueryString("booking=42");
|
request.setQueryString("booking=42");
|
||||||
|
|
||||||
FilterChain filterChain = new NoopFilterChain();
|
FilterChain filterChain = new NoOpFilterChain();
|
||||||
|
|
||||||
filter.doFilter(request, response, filterChain);
|
filter.doFilter(request, response, filterChain);
|
||||||
|
|
||||||
assertNotNull(filter.beforeRequestMessage);
|
assertNotNull(filter.beforeRequestMessage);
|
||||||
assertTrue(filter.beforeRequestMessage.indexOf("uri=/hotel") != -1);
|
assertTrue(filter.beforeRequestMessage.contains("uri=/hotel"));
|
||||||
assertFalse(filter.beforeRequestMessage.indexOf("booking=42") != -1);
|
assertFalse(filter.beforeRequestMessage.contains("booking=42"));
|
||||||
|
|
||||||
assertNotNull(filter.afterRequestMessage);
|
assertNotNull(filter.afterRequestMessage);
|
||||||
assertTrue(filter.afterRequestMessage.indexOf("uri=/hotel") != -1);
|
assertTrue(filter.afterRequestMessage.contains("uri=/hotel"));
|
||||||
assertFalse(filter.afterRequestMessage.indexOf("booking=42") != -1);
|
assertFalse(filter.afterRequestMessage.contains("booking=42"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -75,15 +78,15 @@ public class RequestLoggingFilterTests {
|
|||||||
|
|
||||||
request.setQueryString("booking=42");
|
request.setQueryString("booking=42");
|
||||||
|
|
||||||
FilterChain filterChain = new NoopFilterChain();
|
FilterChain filterChain = new NoOpFilterChain();
|
||||||
|
|
||||||
filter.doFilter(request, response, filterChain);
|
filter.doFilter(request, response, filterChain);
|
||||||
|
|
||||||
assertNotNull(filter.beforeRequestMessage);
|
assertNotNull(filter.beforeRequestMessage);
|
||||||
assertTrue(filter.beforeRequestMessage.indexOf("uri=/hotels?booking=42") != -1);
|
assertTrue(filter.beforeRequestMessage.contains("uri=/hotels?booking=42"));
|
||||||
|
|
||||||
assertNotNull(filter.afterRequestMessage);
|
assertNotNull(filter.afterRequestMessage);
|
||||||
assertTrue(filter.afterRequestMessage.indexOf("uri=/hotels?booking=42") != -1);
|
assertTrue(filter.afterRequestMessage.contains("uri=/hotels?booking=42"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -109,7 +112,7 @@ public class RequestLoggingFilterTests {
|
|||||||
filter.doFilter(request, response, filterChain);
|
filter.doFilter(request, response, filterChain);
|
||||||
|
|
||||||
assertNotNull(filter.afterRequestMessage);
|
assertNotNull(filter.afterRequestMessage);
|
||||||
assertTrue(filter.afterRequestMessage.indexOf("Hello World") != -1);
|
assertTrue(filter.afterRequestMessage.contains("Hello World"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -135,7 +138,7 @@ public class RequestLoggingFilterTests {
|
|||||||
filter.doFilter(request, response, filterChain);
|
filter.doFilter(request, response, filterChain);
|
||||||
|
|
||||||
assertNotNull(filter.afterRequestMessage);
|
assertNotNull(filter.afterRequestMessage);
|
||||||
assertTrue(filter.afterRequestMessage.indexOf(requestBody) != -1);
|
assertTrue(filter.afterRequestMessage.contains(requestBody));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -162,10 +165,11 @@ public class RequestLoggingFilterTests {
|
|||||||
filter.doFilter(request, response, filterChain);
|
filter.doFilter(request, response, filterChain);
|
||||||
|
|
||||||
assertNotNull(filter.afterRequestMessage);
|
assertNotNull(filter.afterRequestMessage);
|
||||||
assertTrue(filter.afterRequestMessage.indexOf("Hel") != -1);
|
assertTrue(filter.afterRequestMessage.contains("Hel"));
|
||||||
assertFalse(filter.afterRequestMessage.indexOf("Hello World") != -1);
|
assertFalse(filter.afterRequestMessage.contains("Hello World"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class MyRequestLoggingFilter extends AbstractRequestLoggingFilter {
|
private static class MyRequestLoggingFilter extends AbstractRequestLoggingFilter {
|
||||||
|
|
||||||
private String beforeRequestMessage;
|
private String beforeRequestMessage;
|
||||||
@@ -183,7 +187,8 @@ public class RequestLoggingFilterTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class NoopFilterChain implements FilterChain {
|
|
||||||
|
private static class NoOpFilterChain implements FilterChain {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
|
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
|
||||||
|
|||||||
Reference in New Issue
Block a user