@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -76,7 +76,7 @@ public class AspectJProxyFactory extends ProxyCreatorSupport {
|
||||
* Create a new {@code AspectJProxyFactory}.
|
||||
* No target, only interfaces. Must add interceptors.
|
||||
*/
|
||||
public AspectJProxyFactory(Class<?>[] interfaces) {
|
||||
public AspectJProxyFactory(Class<?>... interfaces) {
|
||||
setInterfaces(interfaces);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 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,9 +32,9 @@ import static org.junit.Assert.*;
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public final class AspectProxyFactoryTests {
|
||||
public class AspectProxyFactoryTests {
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testWithNonAspect() {
|
||||
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean());
|
||||
proxyFactory.addAspect(TestBean.class);
|
||||
@@ -70,7 +70,7 @@ public final class AspectProxyFactoryTests {
|
||||
assertEquals(2, proxy1.getAge());
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testWithInstanceWithNonAspect() throws Exception {
|
||||
AspectJProxyFactory pf = new AspectJProxyFactory();
|
||||
pf.addAspect(new TestBean());
|
||||
@@ -96,14 +96,14 @@ public final class AspectProxyFactoryTests {
|
||||
assertEquals(target.getAge() * multiple, serializedProxy.getAge());
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testWithNonSingletonAspectInstance() throws Exception {
|
||||
AspectJProxyFactory pf = new AspectJProxyFactory();
|
||||
pf.addAspect(new PerThisAspect());
|
||||
}
|
||||
|
||||
|
||||
public static interface ITestBean {
|
||||
public interface ITestBean {
|
||||
|
||||
int getAge();
|
||||
}
|
||||
|
||||
@@ -393,17 +393,14 @@ public abstract class YamlProcessor {
|
||||
*/
|
||||
protected static class StrictMapAppenderConstructor extends Constructor {
|
||||
|
||||
public StrictMapAppenderConstructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<Object, Object> constructMapping(MappingNode node) {
|
||||
try {
|
||||
return super.constructMapping(node);
|
||||
} catch (IllegalStateException e) {
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
throw new ParserException("while parsing MappingNode",
|
||||
node.getStartMark(), e.getMessage(), node.getEndMark());
|
||||
node.getStartMark(), ex.getMessage(), node.getEndMark());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -414,7 +411,7 @@ public abstract class YamlProcessor {
|
||||
@Override
|
||||
public Object put(Object key, Object value) {
|
||||
if (delegate.containsKey(key)) {
|
||||
throw new IllegalStateException("duplicate key: " + key);
|
||||
throw new IllegalStateException("Duplicate key: " + key);
|
||||
}
|
||||
return delegate.put(key, value);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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,7 +49,7 @@ import static org.junit.Assert.*;
|
||||
* @author Chris Beams
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public final class CglibProxyTests extends AbstractAopProxyTests implements Serializable {
|
||||
public class CglibProxyTests extends AbstractAopProxyTests implements Serializable {
|
||||
|
||||
private static final String DEPENDENCY_CHECK_CONTEXT =
|
||||
CglibProxyTests.class.getSimpleName() + "-with-dependency-checking.xml";
|
||||
@@ -74,6 +74,7 @@ public final class CglibProxyTests extends AbstractAopProxyTests implements Seri
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNullConfig() {
|
||||
try {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -20,6 +20,7 @@ import java.io.Serializable;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.aop.interceptor.ExposeInvocationInterceptor;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
@@ -28,7 +29,6 @@ import org.springframework.tests.sample.beans.ITestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
/**
|
||||
* @since 13.03.2003
|
||||
@@ -37,7 +37,7 @@ import static org.mockito.BDDMockito.*;
|
||||
* @author Chris Beams
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public final class JdkDynamicProxyTests extends AbstractAopProxyTests implements Serializable {
|
||||
public class JdkDynamicProxyTests extends AbstractAopProxyTests implements Serializable {
|
||||
|
||||
@Override
|
||||
protected Object createProxy(ProxyCreatorSupport as) {
|
||||
@@ -52,6 +52,8 @@ public final class JdkDynamicProxyTests extends AbstractAopProxyTests implements
|
||||
return new JdkDynamicAopProxy(as);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNullConfig() {
|
||||
try {
|
||||
new JdkDynamicAopProxy(null);
|
||||
@@ -62,6 +64,7 @@ public final class JdkDynamicProxyTests extends AbstractAopProxyTests implements
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProxyIsJustInterface() throws Throwable {
|
||||
TestBean raw = new TestBean();
|
||||
raw.setAge(32);
|
||||
@@ -74,32 +77,32 @@ public final class JdkDynamicProxyTests extends AbstractAopProxyTests implements
|
||||
assertTrue(!(proxy instanceof TestBean));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInterceptorIsInvokedWithNoTarget() throws Throwable {
|
||||
// Test return value
|
||||
int age = 25;
|
||||
MethodInterceptor mi = mock(MethodInterceptor.class);
|
||||
final Integer age = 25;
|
||||
MethodInterceptor mi = (invocation -> age);
|
||||
|
||||
AdvisedSupport pc = new AdvisedSupport(new Class<?>[] { ITestBean.class });
|
||||
AdvisedSupport pc = new AdvisedSupport(new Class<?>[] {ITestBean.class});
|
||||
pc.addAdvice(mi);
|
||||
AopProxy aop = createAopProxy(pc);
|
||||
|
||||
given(mi.invoke(null)).willReturn(age);
|
||||
|
||||
ITestBean tb = (ITestBean) aop.getProxy();
|
||||
assertTrue("correct return value", tb.getAge() == age);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTargetCanGetInvocationWithPrivateClass() throws Throwable {
|
||||
final ExposedInvocationTestBean expectedTarget = new ExposedInvocationTestBean() {
|
||||
@Override
|
||||
protected void assertions(MethodInvocation invocation) {
|
||||
assertTrue(invocation.getThis() == this);
|
||||
assertTrue("Invocation should be on ITestBean: " + invocation.getMethod(),
|
||||
invocation.getMethod().getDeclaringClass() == ITestBean.class);
|
||||
invocation.getMethod().getDeclaringClass() == ITestBean.class);
|
||||
}
|
||||
};
|
||||
|
||||
AdvisedSupport pc = new AdvisedSupport(new Class<?>[] { ITestBean.class, IOther.class });
|
||||
AdvisedSupport pc = new AdvisedSupport(new Class<?>[] {ITestBean.class, IOther.class});
|
||||
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
|
||||
TrapTargetInterceptor tii = new TrapTargetInterceptor() {
|
||||
@Override
|
||||
@@ -126,10 +129,11 @@ public final class JdkDynamicProxyTests extends AbstractAopProxyTests implements
|
||||
//assertTrue(target.invocation == tii.invocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProxyNotWrappedIfIncompatible() {
|
||||
FooBar bean = new FooBar();
|
||||
ProxyCreatorSupport as = new ProxyCreatorSupport();
|
||||
as.setInterfaces(new Class<?>[] {Foo.class});
|
||||
as.setInterfaces(Foo.class);
|
||||
as.setTarget(bean);
|
||||
|
||||
Foo proxy = (Foo) createProxy(as);
|
||||
@@ -138,6 +142,7 @@ public final class JdkDynamicProxyTests extends AbstractAopProxyTests implements
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsAndHashCodeDefined() throws Exception {
|
||||
AdvisedSupport as = new AdvisedSupport(new Class<?>[]{Named.class});
|
||||
as.setTarget(new Person());
|
||||
@@ -149,7 +154,7 @@ public final class JdkDynamicProxyTests extends AbstractAopProxyTests implements
|
||||
}
|
||||
|
||||
|
||||
public static interface Foo {
|
||||
public interface Foo {
|
||||
|
||||
Bar getBarThis();
|
||||
|
||||
@@ -157,8 +162,7 @@ public final class JdkDynamicProxyTests extends AbstractAopProxyTests implements
|
||||
}
|
||||
|
||||
|
||||
public static interface Bar {
|
||||
|
||||
public interface Bar {
|
||||
}
|
||||
|
||||
|
||||
@@ -176,7 +180,7 @@ public final class JdkDynamicProxyTests extends AbstractAopProxyTests implements
|
||||
}
|
||||
|
||||
|
||||
public static interface Named {
|
||||
public interface Named {
|
||||
|
||||
String getName();
|
||||
|
||||
@@ -201,11 +205,8 @@ public final class JdkDynamicProxyTests extends AbstractAopProxyTests implements
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
final Person person = (Person) o;
|
||||
|
||||
Person person = (Person) o;
|
||||
if (!name.equals(person.name)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -35,11 +35,11 @@ import org.springframework.util.ReflectionUtils;
|
||||
public class ReflectiveMethodExecutor implements MethodExecutor {
|
||||
|
||||
private final Method method;
|
||||
|
||||
|
||||
private final Integer varargsPosition;
|
||||
|
||||
private boolean computedPublicDeclaringClass = false;
|
||||
|
||||
|
||||
private Class<?> publicDeclaringClass;
|
||||
|
||||
private boolean argumentConversionOccurred = false;
|
||||
@@ -58,10 +58,10 @@ public class ReflectiveMethodExecutor implements MethodExecutor {
|
||||
public Method getMethod() {
|
||||
return this.method;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find the first public class in the methods declaring class hierarchy that declares this method.
|
||||
* Sometimes the reflective method discovery logic finds a suitable method that can easily be
|
||||
* Sometimes the reflective method discovery logic finds a suitable method that can easily be
|
||||
* called via reflection but cannot be called from generated code when compiling the expression
|
||||
* because of visibility restrictions. For example if a non public class overrides toString(), this
|
||||
* helper method will walk up the type hierarchy to find the first public type that declares the
|
||||
@@ -80,20 +80,21 @@ public class ReflectiveMethodExecutor implements MethodExecutor {
|
||||
try {
|
||||
clazz.getDeclaredMethod(method.getName(), method.getParameterTypes());
|
||||
return clazz;
|
||||
} catch (NoSuchMethodException nsme) {
|
||||
|
||||
}
|
||||
catch (NoSuchMethodException ex) {
|
||||
// Continue below...
|
||||
}
|
||||
}
|
||||
Class<?>[] intfaces = clazz.getInterfaces();
|
||||
for (Class<?> intface: intfaces) {
|
||||
discoverPublicClass(method, intface);
|
||||
Class<?>[] ifcs = clazz.getInterfaces();
|
||||
for (Class<?> ifc: ifcs) {
|
||||
discoverPublicClass(method, ifc);
|
||||
}
|
||||
if (clazz.getSuperclass() != null) {
|
||||
return discoverPublicClass(method, clazz.getSuperclass());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public boolean didArgumentConversionOccur() {
|
||||
return this.argumentConversionOccurred;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -58,9 +58,8 @@ public class StompDecoder {
|
||||
|
||||
|
||||
/**
|
||||
* Configure a
|
||||
* {@link org.springframework.messaging.support.MessageHeaderInitializer MessageHeaderInitializer}
|
||||
* to apply to the headers of {@link Message}s from decoded STOMP frames.
|
||||
* Configure a {@link MessageHeaderInitializer} to apply to the headers of
|
||||
* {@link Message}s from decoded STOMP frames.
|
||||
*/
|
||||
public void setHeaderInitializer(MessageHeaderInitializer headerInitializer) {
|
||||
this.headerInitializer = headerInitializer;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -38,22 +38,21 @@ public class ResponseBodyTests {
|
||||
|
||||
@Test
|
||||
public void json() throws Exception {
|
||||
|
||||
standaloneSetup(new PersonController()).build()
|
||||
.perform(get("/person/Lee").accept(MediaType.APPLICATION_JSON))
|
||||
.perform(get("/person/Lee").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType("application/json;charset=UTF-8"))
|
||||
.andExpect(jsonPath("$.name").value("Lee"));
|
||||
}
|
||||
|
||||
|
||||
@Controller
|
||||
private class PersonController {
|
||||
|
||||
@RequestMapping(value="/person/{name}")
|
||||
@ResponseBody
|
||||
public Person get(@PathVariable String name) {
|
||||
Person person = new Person(name);
|
||||
return person;
|
||||
return new Person(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -234,7 +234,7 @@ public class ContentNegotiationManagerFactoryBean
|
||||
strategies.add(new HeaderContentNegotiationStrategy());
|
||||
}
|
||||
|
||||
if(this.defaultNegotiationStrategy != null) {
|
||||
if (this.defaultNegotiationStrategy != null) {
|
||||
strategies.add(defaultNegotiationStrategy);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -23,7 +23,6 @@ import java.util.List;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
import org.springframework.http.converter.GenericHttpMessageConverter;
|
||||
@@ -31,12 +30,12 @@ import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Response extractor that uses the given {@linkplain HttpMessageConverter entity
|
||||
* converters} to convert the response into a type {@code T}.
|
||||
* Response extractor that uses the given {@linkplain HttpMessageConverter entity converters}
|
||||
* to convert the response into a type {@code T}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @see RestTemplate
|
||||
* @since 3.0
|
||||
* @see RestTemplate
|
||||
*/
|
||||
public class HttpMessageConverterExtractor<T> implements ResponseExtractor<T> {
|
||||
|
||||
@@ -48,19 +47,18 @@ public class HttpMessageConverterExtractor<T> implements ResponseExtractor<T> {
|
||||
|
||||
private final Log logger;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance of the {@code HttpMessageConverterExtractor} with the given
|
||||
* response type and message converters. The given converters must support the response
|
||||
* type.
|
||||
* Create a new instance of the {@code HttpMessageConverterExtractor} with the given response
|
||||
* type and message converters. The given converters must support the response type.
|
||||
*/
|
||||
public HttpMessageConverterExtractor(Class<T> responseType, List<HttpMessageConverter<?>> messageConverters) {
|
||||
this((Type) responseType, messageConverters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of the {@code HttpMessageConverterExtractor} with the given
|
||||
* response type and message converters. The given converters must support the response
|
||||
* type.
|
||||
* Creates a new instance of the {@code HttpMessageConverterExtractor} with the given response
|
||||
* type and message converters. The given converters must support the response type.
|
||||
*/
|
||||
public HttpMessageConverterExtractor(Type responseType, List<HttpMessageConverter<?>> messageConverters) {
|
||||
this(responseType, messageConverters, LogFactory.getLog(HttpMessageConverterExtractor.class));
|
||||
@@ -76,12 +74,12 @@ public class HttpMessageConverterExtractor<T> implements ResponseExtractor<T> {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public T extractData(ClientHttpResponse response) throws IOException {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public T extractData(ClientHttpResponse response) throws IOException {
|
||||
MessageBodyClientHttpResponseWrapper responseWrapper = new MessageBodyClientHttpResponseWrapper(response);
|
||||
if(!responseWrapper.hasMessageBody() || responseWrapper.hasEmptyMessageBody()) {
|
||||
if (!responseWrapper.hasMessageBody() || responseWrapper.hasEmptyMessageBody()) {
|
||||
return null;
|
||||
}
|
||||
MediaType contentType = getContentType(responseWrapper);
|
||||
@@ -107,9 +105,9 @@ public class HttpMessageConverterExtractor<T> implements ResponseExtractor<T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new RestClientException(
|
||||
"Could not extract response: no suitable HttpMessageConverter found for response type [" +
|
||||
this.responseType + "] and content type [" + contentType + "]");
|
||||
|
||||
throw new RestClientException("Could not extract response: no suitable HttpMessageConverter found " +
|
||||
"for response type [" + this.responseType + "] and content type [" + contentType + "]");
|
||||
}
|
||||
|
||||
private MediaType getContentType(ClientHttpResponse response) {
|
||||
|
||||
@@ -61,7 +61,7 @@ class MessageBodyClientHttpResponseWrapper implements ClientHttpResponse {
|
||||
responseStatus == HttpStatus.NOT_MODIFIED) {
|
||||
return false;
|
||||
}
|
||||
else if(this.getHeaders().getContentLength() == 0) {
|
||||
else if (this.getHeaders().getContentLength() == 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user