diff --git a/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java b/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java index 4d6ead59c1..447ee5540e 100644 --- a/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java +++ b/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java @@ -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. @@ -256,8 +256,8 @@ public abstract class AbstractApplicationEventMulticaster * for the given event type */ protected boolean supportsEvent(Class listenerType, ResolvableType eventType) { - if (GenericApplicationListener.class.isAssignableFrom(listenerType) - || SmartApplicationListener.class.isAssignableFrom(listenerType)) { + if (GenericApplicationListener.class.isAssignableFrom(listenerType) || + SmartApplicationListener.class.isAssignableFrom(listenerType)) { return true; } ResolvableType declaredEventType = GenericApplicationListenerAdapter.resolveDeclaredEventType(listenerType); diff --git a/spring-context/src/main/java/org/springframework/context/event/ApplicationEventMulticaster.java b/spring-context/src/main/java/org/springframework/context/event/ApplicationEventMulticaster.java index 9805323040..e00601d243 100644 --- a/spring-context/src/main/java/org/springframework/context/event/ApplicationEventMulticaster.java +++ b/spring-context/src/main/java/org/springframework/context/event/ApplicationEventMulticaster.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 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. @@ -79,6 +79,7 @@ public interface ApplicationEventMulticaster { * based on the {@code event} instance. * @param event the event to multicast * @param eventType the type of event (can be null) + * @since 4.2 */ void multicastEvent(ApplicationEvent event, ResolvableType eventType); diff --git a/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java b/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java index e291866991..e2f0c800e2 100644 --- a/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java @@ -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. @@ -144,7 +144,7 @@ public class EventListenerMethodProcessor implements SmartInitializingSingleton, if (CollectionUtils.isEmpty(annotatedMethods)) { this.nonAnnotatedClasses.add(targetType); if (logger.isTraceEnabled()) { - logger.trace("No @EventListener annotations found on bean class: " + targetType); + logger.trace("No @EventListener annotations found on bean class: " + targetType.getName()); } } else { diff --git a/spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java b/spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java index 438c126f8a..91f5ad54fd 100644 --- a/spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java +++ b/spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java @@ -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. @@ -27,8 +27,10 @@ import java.util.List; import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import javax.annotation.PostConstruct; import org.junit.After; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -39,6 +41,7 @@ import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanInitializationException; import org.springframework.beans.factory.ObjectFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.PayloadApplicationEvent; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -546,6 +549,14 @@ public class AnnotationDrivenEventListenerTests { assertThat(listener.order, contains("first", "second", "third")); } + @Test @Ignore // SPR-15122 + public void listenersReceiveEarlyEvents() { + load(EventOnPostConstruct.class, OrderedTestListener.class); + OrderedTestListener listener = this.context.getBean(OrderedTestListener.class); + + assertThat(listener.order, contains("first", "second", "third")); + } + private void load(Class... classes) { List> allClasses = new ArrayList<>(); @@ -936,6 +947,18 @@ public class AnnotationDrivenEventListenerTests { } + static class EventOnPostConstruct { + + @Autowired + ApplicationEventPublisher publisher; + + @PostConstruct + public void init() { + this.publisher.publishEvent("earlyEvent"); + } + } + + private static class CustomScope implements org.springframework.beans.factory.config.Scope { public boolean active = true; diff --git a/spring-web/src/main/java/org/springframework/http/converter/GenericHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/GenericHttpMessageConverter.java index 300783b211..f850bf24ac 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/GenericHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/GenericHttpMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 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. @@ -67,14 +67,14 @@ public interface GenericHttpMessageConverter extends HttpMessageConverter /** * Indicates whether the given class can be written by this converter. - * This method should perform the same checks than + *

This method should perform the same checks than * {@link HttpMessageConverter#canWrite(Class, MediaType)} with additional ones * related to the generic type. - * @param type the (potentially generic) type to test for writability, can be - * {@code null} if not specified. + * @param type the (potentially generic) type to test for writability + * (can be {@code null} if not specified) * @param clazz the source object class to test for writability - * @param mediaType the media type to write, can be {@code null} if not specified. - * Typically the value of an {@code Accept} header. + * @param mediaType the media type to write (can be {@code null} if not specified); + * typically the value of an {@code Accept} header. * @return {@code true} if writable; {@code false} otherwise * @since 4.2 */ diff --git a/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConverter.java index 661c559f41..4fc985333d 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 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. @@ -35,8 +35,8 @@ public interface HttpMessageConverter { /** * Indicates whether the given class can be read by this converter. * @param clazz the class to test for readability - * @param mediaType the media type to read, can be {@code null} if not specified. - * Typically the value of a {@code Content-Type} header. + * @param mediaType the media type to read (can be {@code null} if not specified); + * typically the value of a {@code Content-Type} header. * @return {@code true} if readable; {@code false} otherwise */ boolean canRead(Class clazz, MediaType mediaType); @@ -44,8 +44,8 @@ public interface HttpMessageConverter { /** * Indicates whether the given class can be written by this converter. * @param clazz the class to test for writability - * @param mediaType the media type to write, can be {@code null} if not specified. - * Typically the value of an {@code Accept} header. + * @param mediaType the media type to write (can be {@code null} if not specified); + * typically the value of an {@code Accept} header. * @return {@code true} if writable; {@code false} otherwise */ boolean canWrite(Class clazz, MediaType mediaType); diff --git a/spring-web/src/main/java/org/springframework/http/converter/cbor/package-info.java b/spring-web/src/main/java/org/springframework/http/converter/cbor/package-info.java new file mode 100644 index 0000000000..993f0e5f4d --- /dev/null +++ b/spring-web/src/main/java/org/springframework/http/converter/cbor/package-info.java @@ -0,0 +1,4 @@ +/** + * Provides an HttpMessageConverter for the CBOR data format. + */ +package org.springframework.http.converter.cbor; diff --git a/spring-web/src/main/java/org/springframework/http/converter/protobuf/ProtobufHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/protobuf/ProtobufHttpMessageConverter.java index d26afc54ae..93b8db7fa3 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/protobuf/ProtobufHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/protobuf/ProtobufHttpMessageConverter.java @@ -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. @@ -50,17 +50,16 @@ import org.springframework.util.ClassUtils; * *

Other formats can be supported with additional libraries: *

    - *
  • {@code "application/json"} with the official library - * {@code "com.google.protobuf:protobuf-java-util"} - *
  • {@code "application/json"}, {@code "application/xml"} and {@code "text/html"} (write only) - * can be supported with the 3rd party library - * {@code "com.googlecode.protobuf-java-format:protobuf-java-format"} + *
  • {@code "application/json"} with the official library + * {@code "com.google.protobuf:protobuf-java-util"} + *
  • {@code "application/json"}, {@code "application/xml"} and {@code "text/html"} (write only) + * can be supported with the 3rd party library + * {@code "com.googlecode.protobuf-java-format:protobuf-java-format"} *
* *

To generate {@code Message} Java classes, you need to install the {@code protoc} binary. * - *

Requires Protobuf 2.6 and Protobuf Java Format 1.4, as of Spring 4.3. - * Supports up to Protobuf 3.0.0. + *

Requires Protobuf 2.6 or 3.x and Protobuf Java Format 1.4 or higher, as of Spring 5.0. * * @author Alex Antonov * @author Brian Clozel @@ -83,14 +82,15 @@ public class ProtobufHttpMessageConverter extends AbstractHttpMessageConverter, Method> methodCache = new ConcurrentHashMap<>(); + private final ProtobufFormatSupport protobufFormatSupport; + private final ExtensionRegistry extensionRegistry = ExtensionRegistry.newInstance(); + + private static final MediaType[] SUPPORTED_MEDIATYPES; + static { if (isProtobufJavaFormatPresent) { SUPPORTED_MEDIATYPES = new MediaType[] {PROTOBUF, MediaType.TEXT_PLAIN, MediaType.APPLICATION_XML, @@ -104,27 +104,28 @@ public class ProtobufHttpMessageConverter extends AbstractHttpMessageConverter contextClass) { if (type instanceof Class && List.class.isAssignableFrom((Class)type)) { @@ -555,6 +553,7 @@ public class MappingJackson2HttpMessageConverterTests { } } + private static class BeanWithNoDefaultConstructor { private final String property1; @@ -573,7 +572,6 @@ public class MappingJackson2HttpMessageConverterTests { public String getProperty2() { return property2; } - } } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultReturnValueHandlerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultReturnValueHandlerTests.java index ba7f516328..872498c6cf 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultReturnValueHandlerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultReturnValueHandlerTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.servlet.mvc.method.annotation; import java.util.concurrent.CompletableFuture; @@ -33,10 +34,8 @@ import org.springframework.web.context.request.async.StandardServletAsyncWebRequ import org.springframework.web.context.request.async.WebAsyncUtils; import org.springframework.web.method.support.ModelAndViewContainer; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.springframework.web.method.ResolvableMethod.on; +import static org.junit.Assert.*; +import static org.springframework.web.method.ResolvableMethod.*; /** * Unit tests for {@link DeferredResultMethodReturnValueHandler}. @@ -67,7 +66,6 @@ public class DeferredResultReturnValueHandlerTests { @Test public void supportsReturnType() throws Exception { - assertTrue(this.handler.supportsReturnType( on(TestController.class).resolveReturnType(DeferredResult.class, String.class))); @@ -103,7 +101,7 @@ public class DeferredResultReturnValueHandlerTests { } @Test - public void deferredResultWitError() throws Exception { + public void deferredResultWithError() throws Exception { DeferredResult result = new DeferredResult<>(); testHandle(result, DeferredResult.class, () -> result.setResult("foo"), "foo"); } @@ -122,6 +120,7 @@ public class DeferredResultReturnValueHandlerTests { testHandle(future, CompletableFuture.class, () -> future.setException(ex), ex); } + private void testHandle(Object returnValue, Class asyncType, Runnable setResultTask, Object expectedValue) throws Exception {