Browse Source

Polishing (backported from master)

pull/579/head
Juergen Hoeller 12 years ago
parent
commit
48f753f368
  1. 8
      spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java
  2. 8
      spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBean.java
  3. 6
      spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigUtils.java
  4. 9
      spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java
  5. 46
      spring-core/src/main/java/org/springframework/util/CompositeIterator.java
  6. 67
      spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java
  7. 73
      spring-core/src/test/java/org/springframework/util/CompositeIteratorTests.java
  8. 4
      spring-jms/src/main/java/org/springframework/jms/listener/AbstractJmsListeningContainer.java
  9. 12
      spring-web/src/main/java/org/springframework/http/client/SimpleBufferingAsyncClientHttpRequest.java
  10. 15
      spring-web/src/main/java/org/springframework/http/client/SimpleStreamingAsyncClientHttpRequest.java
  11. 4
      spring-web/src/main/java/org/springframework/remoting/httpinvoker/HttpInvokerClientInterceptor.java
  12. 2
      spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMapping.java
  13. 2
      spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java
  14. 10
      spring-webmvc/src/test/java/org/springframework/web/servlet/support/AnnotationConfigDispatcherServletInitializerTests.java
  15. 28
      spring-websocket/src/main/java/org/springframework/web/socket/client/standard/StandardWebSocketClient.java

8
spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@ -124,7 +124,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp @@ -124,7 +124,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
/** Resolution strategy for expressions in bean definition values */
private BeanExpressionResolver beanExpressionResolver;
/** Spring 3.0 ConversionService to use instead of PropertyEditors */
/** Spring ConversionService to use instead of PropertyEditors */
private ConversionService conversionService;
/** Custom PropertyEditorRegistrars to apply to the beans of this factory */
@ -160,9 +160,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp @@ -160,9 +160,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
private final Map<String, RootBeanDefinition> mergedBeanDefinitions =
new ConcurrentHashMap<String, RootBeanDefinition>(64);
/**
* Names of beans that have already been created at least once
*/
/** Names of beans that have already been created at least once */
private final Set<String> alreadyCreated = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>(64));
/** Names of beans that are currently in creation */

8
spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBean.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@ -86,8 +86,8 @@ import org.springframework.util.CollectionUtils; @@ -86,8 +86,8 @@ import org.springframework.util.CollectionUtils;
* @see org.quartz.impl.StdSchedulerFactory
* @see org.springframework.transaction.interceptor.TransactionProxyFactoryBean
*/
public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBean<Scheduler>, BeanNameAware,
ApplicationContextAware, InitializingBean, DisposableBean, SmartLifecycle {
public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBean<Scheduler>,
BeanNameAware, ApplicationContextAware, InitializingBean, DisposableBean, SmartLifecycle {
public static final String PROP_THREAD_COUNT = "org.quartz.threadPool.threadCount";
@ -707,7 +707,7 @@ public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBe @@ -707,7 +707,7 @@ public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBe
//---------------------------------------------------------------------
// Implementation of Lifecycle interface
// Implementation of SmartLifecycle interface
//---------------------------------------------------------------------
@Override

6
spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigUtils.java

@ -311,14 +311,15 @@ public class AnnotationConfigUtils { @@ -311,14 +311,15 @@ public class AnnotationConfigUtils {
static Set<AnnotationAttributes> attributesForRepeatable(AnnotationMetadata metadata,
Class<?> containerClass, Class<?> annotationClass) {
return attributesForRepeatable(metadata, containerClass.getName(), annotationClass.getName());
}
@SuppressWarnings("unchecked")
static Set<AnnotationAttributes> attributesForRepeatable(AnnotationMetadata metadata,
String containerClassName, String annotationClassName) {
Set<AnnotationAttributes> result = new LinkedHashSet<AnnotationAttributes>();
Set<AnnotationAttributes> result = new LinkedHashSet<AnnotationAttributes>();
addAttributesIfNotNull(result, metadata.getAnnotationAttributes(annotationClassName, false));
Map<String, Object> container = metadata.getAnnotationAttributes(containerClassName, false);
@ -330,8 +331,7 @@ public class AnnotationConfigUtils { @@ -330,8 +331,7 @@ public class AnnotationConfigUtils {
return Collections.unmodifiableSet(result);
}
private static void addAttributesIfNotNull(Set<AnnotationAttributes> result,
Map<String, Object> attributes) {
private static void addAttributesIfNotNull(Set<AnnotationAttributes> result, Map<String, Object> attributes) {
if (attributes != null) {
result.add(AnnotationAttributes.fromMap(attributes));
}

9
spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@ -94,19 +94,18 @@ public class SpringValidatorAdapter implements SmartValidator, javax.validation. @@ -94,19 +94,18 @@ public class SpringValidatorAdapter implements SmartValidator, javax.validation.
}
@Override
@SuppressWarnings("rawtypes")
public void validate(Object target, Errors errors, Object... validationHints) {
if (this.targetValidator != null) {
Set<Class> groups = new LinkedHashSet<Class>();
Set<Class<?>> groups = new LinkedHashSet<Class<?>>();
if (validationHints != null) {
for (Object hint : validationHints) {
if (hint instanceof Class) {
groups.add((Class) hint);
groups.add((Class<?>) hint);
}
}
}
processConstraintViolations(
this.targetValidator.validate(target, groups.toArray(new Class[groups.size()])), errors);
this.targetValidator.validate(target, groups.toArray(new Class<?>[groups.size()])), errors);
}
}

46
spring-core/src/main/java/org/springframework/util/CompositeIterator.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -13,46 +13,48 @@ @@ -13,46 +13,48 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.util;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.LinkedHashSet;
import java.util.NoSuchElementException;
import java.util.Set;
/**
* Iterator that combines multiple other iterators.
* This implementation maintains a list of iterators which are invoked in sequence until all iterators are exhausted.
* Composite iterator that combines multiple other iterators,
* as registered via {@link #add(Iterator)}.
*
* <p>This implementation maintains a linked set of iterators
* which are invoked in sequence until all iterators are exhausted.
*
* @author Erwin Vervaet
* @author Juergen Hoeller
* @since 3.0
*/
public class CompositeIterator<E> implements Iterator<E> {
private List<Iterator<E>> iterators = new LinkedList<Iterator<E>>();
private final Set<Iterator<E>> iterators = new LinkedHashSet<Iterator<E>>();
private boolean inUse = false;
/**
* Create a new composite iterator. Add iterators using the {@link #add(Iterator)} method.
*/
public CompositeIterator() {
}
/**
* Add given iterator to this composite.
*/
public void add(Iterator<E> iterator) {
Assert.state(!inUse, "You can no longer add iterator to a composite iterator that's already in use");
if (iterators.contains(iterator)) {
Assert.state(!this.inUse, "You can no longer add iterators to a composite iterator that's already in use");
if (this.iterators.contains(iterator)) {
throw new IllegalArgumentException("You cannot add the same iterator twice");
}
iterators.add(iterator);
this.iterators.add(iterator);
}
@Override
public boolean hasNext() {
inUse = true;
for (Iterator<Iterator<E>> it = iterators.iterator(); it.hasNext();) {
if (it.next().hasNext()) {
this.inUse = true;
for (Iterator<E> iterator : this.iterators) {
if (iterator.hasNext()) {
return true;
}
}
@ -61,18 +63,18 @@ public class CompositeIterator<E> implements Iterator<E> { @@ -61,18 +63,18 @@ public class CompositeIterator<E> implements Iterator<E> {
@Override
public E next() {
inUse = true;
for (Iterator<Iterator<E>> it = iterators.iterator(); it.hasNext();) {
Iterator<E> iterator = it.next();
this.inUse = true;
for (Iterator<E> iterator : this.iterators) {
if (iterator.hasNext()) {
return iterator.next();
}
}
throw new NoSuchElementException("Exhausted all iterators");
throw new NoSuchElementException("All iterators exhausted");
}
@Override
public void remove() {
throw new UnsupportedOperationException("Remove is not supported");
throw new UnsupportedOperationException("CompositeIterator does not support remove()");
}
}

67
spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java

@ -224,23 +224,23 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen @@ -224,23 +224,23 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
@Override
public V get(Object key) {
Reference<K, V> reference = getReference(key, Restructure.WHEN_NECESSARY);
Entry<K, V> entry = (reference == null ? null : reference.get());
Entry<K, V> entry = (reference != null ? reference.get() : null);
return (entry != null ? entry.getValue() : null);
}
@Override
public boolean containsKey(Object key) {
Reference<K, V> reference = getReference(key, Restructure.WHEN_NECESSARY);
Entry<K, V> entry = (reference == null ? null : reference.get());
Entry<K, V> entry = (reference != null ? reference.get() : null);
return (entry != null && ObjectUtils.nullSafeEquals(entry.getKey(), key));
}
/**
* Returns a {@link Reference} to the {@link Entry} for the specified {@code key} or
* {@code null} if not found.
* Return a {@link Reference} to the {@link Entry} for the specified {@code key},
* or {@code null} if not found.
* @param key the key (can be {@code null})
* @param restructure types of restructure allowed during this call
* @return the reference or {@code null}
* @return the reference, or {@code null} if not found
*/
protected final Reference<K, V> getReference(Object key, Restructure restructure) {
int hash = getHash(key);
@ -400,14 +400,10 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen @@ -400,14 +400,10 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
*/
public static enum ReferenceType {
/**
* Use {@link SoftReference}s.
*/
/** Use {@link SoftReference}s */
SOFT,
/**
* Use {@link WeakReference}s.
*/
/** Use {@link WeakReference}s */
WEAK
}
@ -462,8 +458,8 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen @@ -462,8 +458,8 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
}
/**
* Apply an update operation to this segment. The segment will be locked
* during update.
* Apply an update operation to this segment.
* The segment will be locked during the update.
* @param hash the hash of the key
* @param key the key
* @param task the update operation
@ -474,7 +470,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen @@ -474,7 +470,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
if (task.hasOption(TaskOption.RESTRUCTURE_BEFORE)) {
restructureIfNecessary(resize);
}
if (task.hasOption(TaskOption.SKIP_IF_EMPTY) && (this.count == 0)) {
if (task.hasOption(TaskOption.SKIP_IF_EMPTY) && this.count == 0) {
return task.execute(null, null, null);
}
lock();
@ -482,12 +478,12 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen @@ -482,12 +478,12 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
final int index = getIndex(hash, this.references);
final Reference<K, V> head = this.references[index];
Reference<K, V> reference = findInChain(head, key, hash);
Entry<K, V> entry = (reference == null ? null : reference.get());
Entry<K, V> entry = (reference != null ? reference.get() : null);
Entries entries = new Entries() {
@Override
public void add(V value) {
@SuppressWarnings("unchecked")
Entry<K, V> newEntry = new Entry<K, V>((K)key, value);
Entry<K, V> newEntry = new Entry<K, V>((K) key, value);
Reference<K, V> newReference = Segment.this.referenceManager.createReference(newEntry, hash, head);
Segment.this.references[index] = newReference;
Segment.this.count++;
@ -514,7 +510,8 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen @@ -514,7 +510,8 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
try {
setReferences(createReferenceArray(this.initialSize));
this.count = 0;
} finally {
}
finally {
unlock();
}
}
@ -545,16 +542,16 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen @@ -545,16 +542,16 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
// Recalculate taking into account count inside lock and items that
// will be purged
needsResize = ((countAfterRestructure > 0) && (countAfterRestructure >= this.resizeThreshold));
needsResize = (countAfterRestructure > 0 && countAfterRestructure >= this.resizeThreshold);
boolean resizing = false;
int restructureSize = this.references.length;
if (allowResize && needsResize && (restructureSize < MAXIMUM_SEGMENT_SIZE)) {
if (allowResize && needsResize && restructureSize < MAXIMUM_SEGMENT_SIZE) {
restructureSize <<= 1;
resizing = true;
}
// Either create a new table or reuse the existing one
Reference<K, V>[] restructured = (resizing ? createReferenceArray(restructureSize) : this.references);
Reference<K, V>[] restructured = (resizing ? createReferenceArray(restructureSize) : this.references);
// Restructure
for (int i = 0; i < this.references.length; i++) {
@ -578,7 +575,8 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen @@ -578,7 +575,8 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
setReferences(restructured);
}
this.count = Math.max(countAfterRestructure, 0);
} finally {
}
finally {
unlock();
}
}
@ -606,7 +604,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen @@ -606,7 +604,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
}
private int getIndex(int hash, Reference<K, V>[] references) {
return hash & (references.length - 1);
return (hash & (references.length - 1));
}
/**
@ -700,27 +698,26 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen @@ -700,27 +698,26 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
@Override
public String toString() {
return this.key + "=" + this.value;
return (this.key + "=" + this.value);
}
@Override
@SuppressWarnings("rawtypes")
public final boolean equals(Object o) {
if (o == this) {
public final boolean equals(Object other) {
if (this == other) {
return true;
}
if (o != null && o instanceof Map.Entry) {
Map.Entry other = (Map.Entry) o;
return ObjectUtils.nullSafeEquals(getKey(), other.getKey())
&& ObjectUtils.nullSafeEquals(getValue(), other.getValue());
if (!(other instanceof Map.Entry)) {
return false;
}
return false;
Map.Entry otherEntry = (Map.Entry) other;
return (ObjectUtils.nullSafeEquals(getKey(), otherEntry.getKey()) &&
ObjectUtils.nullSafeEquals(getValue(), otherEntry.getValue()));
}
@Override
public final int hashCode() {
return ObjectUtils.nullSafeHashCode(this.key)
^ ObjectUtils.nullSafeHashCode(this.value);
return (ObjectUtils.nullSafeHashCode(this.key) ^ ObjectUtils.nullSafeHashCode(this.value));
}
}
@ -802,7 +799,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen @@ -802,7 +799,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
if (o != null && o instanceof Map.Entry<?, ?>) {
Map.Entry<?, ?> entry = (java.util.Map.Entry<?, ?>) o;
Reference<K, V> reference = ConcurrentReferenceHashMap.this.getReference(entry.getKey(), Restructure.NEVER);
Entry<K, V> other = (reference == null ? null : reference.get());
Entry<K, V> other = (reference != null ? reference.get() : null);
if (other != null) {
return ObjectUtils.nullSafeEquals(entry.getValue(), other.getValue());
}
@ -855,7 +852,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen @@ -855,7 +852,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
@Override
public boolean hasNext() {
getNextIfNecessary();
return this.next != null;
return (this.next != null);
}
@Override
@ -987,7 +984,6 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen @@ -987,7 +984,6 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
enqueue();
clear();
}
}
@ -1021,7 +1017,6 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen @@ -1021,7 +1017,6 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
enqueue();
clear();
}
}
}

73
spring-core/src/test/java/org/springframework/util/CompositeIteratorTests.java

@ -1,3 +1,19 @@ @@ -1,3 +1,19 @@
/*
* Copyright 2002-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.util;
import java.util.Arrays;
@ -5,29 +21,36 @@ import java.util.Iterator; @@ -5,29 +21,36 @@ import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import junit.framework.TestCase;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Test case for {@link CompositeIterator}.
*
* @author Erwin Vervaet
* @author Juergen Hoeller
*/
public class CompositeIteratorTests extends TestCase {
public class CompositeIteratorTests {
@Test
public void testNoIterators() {
CompositeIterator it = new CompositeIterator();
CompositeIterator<String> it = new CompositeIterator<String>();
assertFalse(it.hasNext());
try {
it.next();
fail();
} catch (NoSuchElementException e) {
}
catch (NoSuchElementException ex) {
// expected
}
}
@Test
public void testSingleIterator() {
CompositeIterator it = new CompositeIterator();
it.add(Arrays.asList(new String[] { "0", "1" }).iterator());
CompositeIterator<String> it = new CompositeIterator<String>();
it.add(Arrays.asList("0", "1").iterator());
for (int i = 0; i < 2; i++) {
assertTrue(it.hasNext());
assertEquals(String.valueOf(i), it.next());
@ -36,16 +59,18 @@ public class CompositeIteratorTests extends TestCase { @@ -36,16 +59,18 @@ public class CompositeIteratorTests extends TestCase {
try {
it.next();
fail();
} catch (NoSuchElementException e) {
}
catch (NoSuchElementException ex) {
// expected
}
}
@Test
public void testMultipleIterators() {
CompositeIterator it = new CompositeIterator();
it.add(Arrays.asList(new String[] { "0", "1" }).iterator());
it.add(Arrays.asList(new String[] { "2" }).iterator());
it.add(Arrays.asList(new String[] { "3", "4" }).iterator());
CompositeIterator<String> it = new CompositeIterator<String>();
it.add(Arrays.asList("0", "1").iterator());
it.add(Arrays.asList("2").iterator());
it.add(Arrays.asList("3", "4").iterator());
for (int i = 0; i < 5; i++) {
assertTrue(it.hasNext());
assertEquals(String.valueOf(i), it.next());
@ -54,43 +79,49 @@ public class CompositeIteratorTests extends TestCase { @@ -54,43 +79,49 @@ public class CompositeIteratorTests extends TestCase {
try {
it.next();
fail();
} catch (NoSuchElementException e) {
}
catch (NoSuchElementException ex) {
// expected
}
}
@Test
public void testInUse() {
List list = Arrays.asList(new String[] { "0", "1" });
CompositeIterator it = new CompositeIterator();
List<String> list = Arrays.asList("0", "1");
CompositeIterator<String> it = new CompositeIterator<String>();
it.add(list.iterator());
it.hasNext();
try {
it.add(list.iterator());
fail();
} catch (IllegalStateException e) {
}
catch (IllegalStateException ex) {
// expected
}
it = new CompositeIterator();
it = new CompositeIterator<String>();
it.add(list.iterator());
it.next();
try {
it.add(list.iterator());
fail();
} catch (IllegalStateException e) {
}
catch (IllegalStateException ex) {
// expected
}
}
@Test
public void testDuplicateIterators() {
List list = Arrays.asList(new String[] { "0", "1" });
Iterator iterator = list.iterator();
CompositeIterator it = new CompositeIterator();
List<String> list = Arrays.asList("0", "1");
Iterator<String> iterator = list.iterator();
CompositeIterator<String> it = new CompositeIterator<String>();
it.add(iterator);
it.add(list.iterator());
try {
it.add(iterator);
fail();
} catch (IllegalArgumentException e) {
}
catch (IllegalArgumentException ex) {
// expected
}
}

4
spring-jms/src/main/java/org/springframework/jms/listener/AbstractJmsListeningContainer.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -58,7 +58,7 @@ import org.springframework.util.ClassUtils; @@ -58,7 +58,7 @@ import org.springframework.util.ClassUtils;
* @see #doShutdown()
*/
public abstract class AbstractJmsListeningContainer extends JmsDestinationAccessor
implements SmartLifecycle, BeanNameAware, DisposableBean {
implements BeanNameAware, DisposableBean, SmartLifecycle {
private String clientId;

12
spring-web/src/main/java/org/springframework/http/client/SimpleBufferingAsyncClientHttpRequest.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@ -37,7 +37,7 @@ import org.springframework.util.concurrent.ListenableFuture; @@ -37,7 +37,7 @@ import org.springframework.util.concurrent.ListenableFuture;
*
* @author Arjen Poutsma
* @since 3.0
* @see org.springframework.http.client.SimpleClientHttpRequestFactory#createRequest(java.net.URI, org.springframework.http.HttpMethod)
* @see org.springframework.http.client.SimpleClientHttpRequestFactory#createRequest
*/
final class SimpleBufferingAsyncClientHttpRequest extends AbstractBufferingAsyncClientHttpRequest {
@ -47,13 +47,16 @@ final class SimpleBufferingAsyncClientHttpRequest extends AbstractBufferingAsync @@ -47,13 +47,16 @@ final class SimpleBufferingAsyncClientHttpRequest extends AbstractBufferingAsync
private final AsyncListenableTaskExecutor taskExecutor;
SimpleBufferingAsyncClientHttpRequest(HttpURLConnection connection,
boolean outputStreaming, AsyncListenableTaskExecutor taskExecutor) {
this.connection = connection;
this.outputStreaming = outputStreaming;
this.taskExecutor = taskExecutor;
}
@Override
public HttpMethod getMethod() {
return HttpMethod.valueOf(this.connection.getRequestMethod());
@ -72,7 +75,8 @@ final class SimpleBufferingAsyncClientHttpRequest extends AbstractBufferingAsync @@ -72,7 +75,8 @@ final class SimpleBufferingAsyncClientHttpRequest extends AbstractBufferingAsync
@Override
protected ListenableFuture<ClientHttpResponse> executeInternal(
final HttpHeaders headers, final byte[] bufferedOutput) throws IOException {
return taskExecutor.submitListenable(new Callable<ClientHttpResponse>() {
return this.taskExecutor.submitListenable(new Callable<ClientHttpResponse>() {
@Override
public ClientHttpResponse call() throws Exception {
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
@ -81,11 +85,9 @@ final class SimpleBufferingAsyncClientHttpRequest extends AbstractBufferingAsync @@ -81,11 +85,9 @@ final class SimpleBufferingAsyncClientHttpRequest extends AbstractBufferingAsync
connection.addRequestProperty(headerName, headerValue);
}
}
if (connection.getDoOutput() && outputStreaming) {
connection.setFixedLengthStreamingMode(bufferedOutput.length);
}
connection.connect();
if (connection.getDoOutput()) {
FileCopyUtils.copy(bufferedOutput, connection.getOutputStream());

15
spring-web/src/main/java/org/springframework/http/client/SimpleStreamingAsyncClientHttpRequest.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@ -33,13 +33,12 @@ import org.springframework.util.concurrent.ListenableFuture; @@ -33,13 +33,12 @@ import org.springframework.util.concurrent.ListenableFuture;
/**
* {@link org.springframework.http.client.ClientHttpRequest} implementation that uses
* standard J2SE facilities to execute streaming requests. Created via the {@link
* standard Java facilities to execute streaming requests. Created via the {@link
* org.springframework.http.client.SimpleClientHttpRequestFactory}.
*
* @author Arjen Poutsma
* @see org.springframework.http.client.SimpleClientHttpRequestFactory#createRequest(java.net.URI,
* org.springframework.http.HttpMethod)
* @since 3.0
* @see org.springframework.http.client.SimpleClientHttpRequestFactory#createRequest
*/
final class SimpleStreamingAsyncClientHttpRequest extends AbstractAsyncClientHttpRequest {
@ -53,14 +52,17 @@ final class SimpleStreamingAsyncClientHttpRequest extends AbstractAsyncClientHtt @@ -53,14 +52,17 @@ final class SimpleStreamingAsyncClientHttpRequest extends AbstractAsyncClientHtt
private final AsyncListenableTaskExecutor taskExecutor;
SimpleStreamingAsyncClientHttpRequest(HttpURLConnection connection, int chunkSize,
boolean outputStreaming, AsyncListenableTaskExecutor taskExecutor) {
this.connection = connection;
this.chunkSize = chunkSize;
this.outputStreaming = outputStreaming;
this.taskExecutor = taskExecutor;
}
@Override
public HttpMethod getMethod() {
return HttpMethod.valueOf(this.connection.getRequestMethod());
@ -106,9 +108,8 @@ final class SimpleStreamingAsyncClientHttpRequest extends AbstractAsyncClientHtt @@ -106,9 +108,8 @@ final class SimpleStreamingAsyncClientHttpRequest extends AbstractAsyncClientHtt
}
@Override
protected ListenableFuture<ClientHttpResponse> executeInternal(final HttpHeaders headers)
throws IOException {
return taskExecutor.submitListenable(new Callable<ClientHttpResponse>() {
protected ListenableFuture<ClientHttpResponse> executeInternal(final HttpHeaders headers) throws IOException {
return this.taskExecutor.submitListenable(new Callable<ClientHttpResponse>() {
@Override
public ClientHttpResponse call() throws Exception {
try {

4
spring-web/src/main/java/org/springframework/remoting/httpinvoker/HttpInvokerClientInterceptor.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -139,7 +139,7 @@ public class HttpInvokerClientInterceptor extends RemoteInvocationBasedAccessor @@ -139,7 +139,7 @@ public class HttpInvokerClientInterceptor extends RemoteInvocationBasedAccessor
}
RemoteInvocation invocation = createRemoteInvocation(methodInvocation);
RemoteInvocationResult result = null;
RemoteInvocationResult result;
try {
result = executeRequest(invocation, methodInvocation);
}

2
spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMapping.java

@ -370,7 +370,7 @@ public @interface RequestMapping { @@ -370,7 +370,7 @@ public @interface RequestMapping {
* all requests with a {@code Accept} other than "text/plain".
* <p><b>Supported at the type level as well as at the method level!</b>
* When used at the type level, all method-level mappings override
* this consumes restriction.
* this produces restriction.
* @see org.springframework.http.MediaType
*/
String[] produces() default {};

2
spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java

@ -231,7 +231,7 @@ public class UriComponentsBuilder { @@ -231,7 +231,7 @@ public class UriComponentsBuilder {
builder.scheme((scheme != null) ? scheme.toLowerCase() : scheme);
builder.userInfo(m.group(4));
String host = m.group(5);
if(StringUtils.hasLength(scheme) && !StringUtils.hasLength(host)) {
if (StringUtils.hasLength(scheme) && !StringUtils.hasLength(host)) {
throw new IllegalArgumentException("[" + httpUrl + "] is not a valid HTTP URL");
}
builder.host(host);

10
spring-webmvc/src/test/java/org/springframework/web/servlet/support/AnnotationConfigDispatcherServletInitializerTests.java

@ -224,7 +224,7 @@ public class AnnotationConfigDispatcherServletInitializerTests { @@ -224,7 +224,7 @@ public class AnnotationConfigDispatcherServletInitializerTests {
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class[]{MyConfiguration.class};
return new Class<?>[] {MyConfiguration.class};
}
@Override
@ -254,16 +254,12 @@ public class AnnotationConfigDispatcherServletInitializerTests { @@ -254,16 +254,12 @@ public class AnnotationConfigDispatcherServletInitializerTests {
}
private static class MyBean {
public static class MyBean {
}
@Configuration
@SuppressWarnings("unused")
private static class MyConfiguration {
public MyConfiguration() {
}
public static class MyConfiguration {
@Bean
public MyBean bean() {

28
spring-websocket/src/main/java/org/springframework/web/socket/client/standard/StandardWebSocketClient.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@ -34,6 +34,7 @@ import javax.websocket.HandshakeResponse; @@ -34,6 +34,7 @@ import javax.websocket.HandshakeResponse;
import javax.websocket.WebSocketContainer;
import org.springframework.core.task.AsyncListenableTaskExecutor;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.http.HttpHeaders;
import org.springframework.util.Assert;
@ -58,7 +59,7 @@ public class StandardWebSocketClient extends AbstractWebSocketClient { @@ -58,7 +59,7 @@ public class StandardWebSocketClient extends AbstractWebSocketClient {
private final WebSocketContainer webSocketContainer;
private AsyncListenableTaskExecutor taskExecutor;
private AsyncListenableTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
/**
@ -72,9 +73,8 @@ public class StandardWebSocketClient extends AbstractWebSocketClient { @@ -72,9 +73,8 @@ public class StandardWebSocketClient extends AbstractWebSocketClient {
/**
* Constructor accepting an existing {@link WebSocketContainer} instance.
*
* <p>For XML configuration see {@link WebSocketContainerFactoryBean}. For Java
* configuration use {@code ContainerProvider.getWebSocketContainer()} to obtain
* <p>For XML configuration, see {@link WebSocketContainerFactoryBean}. For Java
* configuration, use {@code ContainerProvider.getWebSocketContainer()} to obtain
* the {@code WebSocketContainer} instance.
*/
public StandardWebSocketClient(WebSocketContainer webSocketContainer) {
@ -85,9 +85,9 @@ public class StandardWebSocketClient extends AbstractWebSocketClient { @@ -85,9 +85,9 @@ public class StandardWebSocketClient extends AbstractWebSocketClient {
/**
* Set an {@link AsyncListenableTaskExecutor} to use when opening connections.
*
* <p>If this property is not configured, calls to any of the
* If this property is set to {@code null}, calls to any of the
* {@code doHandshake} methods will block until the connection is established.
* <p>By default, an instance of {@code SimpleAsyncTaskExecutor} is used.
*/
public void setTaskExecutor(AsyncListenableTaskExecutor taskExecutor) {
this.taskExecutor = taskExecutor;
@ -113,16 +113,16 @@ public class StandardWebSocketClient extends AbstractWebSocketClient { @@ -113,16 +113,16 @@ public class StandardWebSocketClient extends AbstractWebSocketClient {
final StandardWebSocketSession session = new StandardWebSocketSession(headers,
attributes, localAddress, remoteAddress);
final ClientEndpointConfig.Builder configBuidler = ClientEndpointConfig.Builder.create();
configBuidler.configurator(new StandardWebSocketClientConfigurator(headers));
configBuidler.preferredSubprotocols(protocols);
configBuidler.extensions(adaptExtensions(extensions));
final ClientEndpointConfig.Builder configBuilder = ClientEndpointConfig.Builder.create();
configBuilder.configurator(new StandardWebSocketClientConfigurator(headers));
configBuilder.preferredSubprotocols(protocols);
configBuilder.extensions(adaptExtensions(extensions));
final Endpoint endpoint = new StandardWebSocketHandlerAdapter(webSocketHandler, session);
Callable<WebSocketSession> connectTask = new Callable<WebSocketSession>() {
@Override
public WebSocketSession call() throws Exception {
webSocketContainer.connectToServer(endpoint, configBuidler.build(), uri);
webSocketContainer.connectToServer(endpoint, configBuilder.build(), uri);
return session;
}
};
@ -139,8 +139,8 @@ public class StandardWebSocketClient extends AbstractWebSocketClient { @@ -139,8 +139,8 @@ public class StandardWebSocketClient extends AbstractWebSocketClient {
private static List<Extension> adaptExtensions(List<WebSocketExtension> extensions) {
List<Extension> result = new ArrayList<Extension>();
for (WebSocketExtension e : extensions) {
result.add(new WebSocketToStandardExtensionAdapter(e));
for (WebSocketExtension extension : extensions) {
result.add(new WebSocketToStandardExtensionAdapter(extension));
}
return result;
}

Loading…
Cancel
Save