diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/SqlLobValue.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/SqlLobValue.java index 8e46d42b750..6845773d55f 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/SqlLobValue.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/SqlLobValue.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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. @@ -169,8 +169,7 @@ public class SqlLobValue implements DisposableSqlTypeValue { * Set the specified content via the LobCreator. */ @Override - public void setTypeValue(PreparedStatement ps, int paramIndex, int sqlType, String typeName) - throws SQLException { + public void setTypeValue(PreparedStatement ps, int paramIndex, int sqlType, String typeName) throws SQLException { if (sqlType == Types.BLOB) { if (this.content instanceof byte[] || this.content == null) { this.lobCreator.setBlobAsBytes(ps, paramIndex, (byte[]) this.content); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/package-info.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/package-info.java index ceea8ac1bc3..4ae1cfe995d 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/package-info.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/package-info.java @@ -1,8 +1,5 @@ /** - * Provides a stategy interface for Large OBject handling, - * with implementations for various databases. - * - *

Can be used independently from jdbc.core and jdbc.object, - * for example in custom JDBC access code. + * Provides a strategy interface for Large OBject handling, + * as well as a customizable default implementation. */ package org.springframework.jdbc.support.lob; diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/ConnectionFactoryUtils.java b/spring-jms/src/main/java/org/springframework/jms/connection/ConnectionFactoryUtils.java index 72f04974538..97fc2997b1b 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/ConnectionFactoryUtils.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/ConnectionFactoryUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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. @@ -131,8 +131,8 @@ public abstract class ConnectionFactoryUtils { * @return the transactional Session, or {@code null} if none found * @throws JMSException in case of JMS failure */ - public static Session getTransactionalSession( - final ConnectionFactory cf, final Connection existingCon, final boolean synchedLocalTransactionAllowed) + public static Session getTransactionalSession(final ConnectionFactory cf, + final Connection existingCon, final boolean synchedLocalTransactionAllowed) throws JMSException { return doGetTransactionalSession(cf, new ResourceFactory() { @@ -173,8 +173,8 @@ public abstract class ConnectionFactoryUtils { * @return the transactional Session, or {@code null} if none found * @throws JMSException in case of JMS failure */ - public static QueueSession getTransactionalQueueSession( - final QueueConnectionFactory cf, final QueueConnection existingCon, final boolean synchedLocalTransactionAllowed) + public static QueueSession getTransactionalQueueSession(final QueueConnectionFactory cf, + final QueueConnection existingCon, final boolean synchedLocalTransactionAllowed) throws JMSException { return (QueueSession) doGetTransactionalSession(cf, new ResourceFactory() { @@ -215,8 +215,8 @@ public abstract class ConnectionFactoryUtils { * @return the transactional Session, or {@code null} if none found * @throws JMSException in case of JMS failure */ - public static TopicSession getTransactionalTopicSession( - final TopicConnectionFactory cf, final TopicConnection existingCon, final boolean synchedLocalTransactionAllowed) + public static TopicSession getTransactionalTopicSession(final TopicConnectionFactory cf, + final TopicConnection existingCon, final boolean synchedLocalTransactionAllowed) throws JMSException { return (TopicSession) doGetTransactionalSession(cf, new ResourceFactory() { @@ -234,7 +234,8 @@ public abstract class ConnectionFactoryUtils { } @Override public Session createSession(Connection con) throws JMSException { - return ((TopicConnection) con).createTopicSession(synchedLocalTransactionAllowed, Session.AUTO_ACKNOWLEDGE); + return ((TopicConnection) con).createTopicSession( + synchedLocalTransactionAllowed, Session.AUTO_ACKNOWLEDGE); } @Override public boolean isSynchedLocalTransactionAllowed() { @@ -339,8 +340,8 @@ public abstract class ConnectionFactoryUtils { } if (resourceHolderToUse != resourceHolder) { TransactionSynchronizationManager.registerSynchronization( - new JmsResourceSynchronization( - resourceHolderToUse, connectionFactory, resourceFactory.isSynchedLocalTransactionAllowed())); + new JmsResourceSynchronization(resourceHolderToUse, connectionFactory, + resourceFactory.isSynchedLocalTransactionAllowed())); resourceHolderToUse.setSynchronizedWithTransaction(true); TransactionSynchronizationManager.bindResource(connectionFactory, resourceHolderToUse); } diff --git a/spring-tx/src/main/java/org/springframework/transaction/support/TransactionCallbackWithoutResult.java b/spring-tx/src/main/java/org/springframework/transaction/support/TransactionCallbackWithoutResult.java index a4b57b3b0bb..8088bc2870b 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/support/TransactionCallbackWithoutResult.java +++ b/spring-tx/src/main/java/org/springframework/transaction/support/TransactionCallbackWithoutResult.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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. @@ -40,15 +40,12 @@ public abstract class TransactionCallbackWithoutResult implements TransactionCal * context. Does not need to care about transactions itself, although it can retrieve * and influence the status of the current transaction via the given status object, * e.g. setting rollback-only. - * *

A RuntimeException thrown by the callback is treated as application * exception that enforces a rollback. An exception gets propagated to the * caller of the template. - * *

Note when using JTA: JTA transactions only work with transactional * JNDI resources, so implementations need to use such resources if they * want transaction support. - * * @param status associated transaction status * @see TransactionTemplate#execute */ diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserters.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserters.java index bb56868c93f..83e9a612a85 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserters.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserters.java @@ -85,8 +85,8 @@ public abstract class BodyInserters { * @param

the type of the {@code Publisher} * @return a {@code BodyInserter} that writes a {@code Publisher} */ - public static > BodyInserter fromPublisher(P publisher, - Class elementClass) { + public static > BodyInserter fromPublisher( + P publisher, Class elementClass) { Assert.notNull(publisher, "'publisher' must not be null"); Assert.notNull(elementClass, "'elementClass' must not be null"); @@ -101,8 +101,8 @@ public abstract class BodyInserters { * @param

the type of the {@code Publisher} * @return a {@code BodyInserter} that writes a {@code Publisher} */ - public static > BodyInserter fromPublisher(P publisher, - ResolvableType elementType) { + public static > BodyInserter fromPublisher( + P publisher, ResolvableType elementType) { Assert.notNull(publisher, "'publisher' must not be null"); Assert.notNull(elementType, "'elementType' must not be null"); @@ -111,9 +111,8 @@ public abstract class BodyInserters { /** * Return a {@code BodyInserter} that writes the given {@code Resource}. - * If the resource can be resolved to a {@linkplain Resource#getFile() file}, it will be copied - * using - * zero-copy + *

If the resource can be resolved to a {@linkplain Resource#getFile() file}, it will + * be copied using zero-copy. * @param resource the resource to write to the output message * @param the type of the {@code Resource} * @return a {@code BodyInserter} that writes a {@code Publisher} @@ -133,7 +132,7 @@ public abstract class BodyInserters { .findFirst() .map(BodyInserters::cast) .orElseThrow(() -> new IllegalStateException( - "Could not find HttpMessageWriter that supports Resources.")); + "Could not find HttpMessageWriter that supports Resource objects")); } /** @@ -212,9 +211,10 @@ public abstract class BodyInserters { * @param formData the form data to write to the output message * @return a {@code BodyInserter} that writes form data */ - public static BodyInserter, ClientHttpRequest> fromFormData(MultiValueMap formData) { - Assert.notNull(formData, "'formData' must not be null"); + public static BodyInserter, ClientHttpRequest> fromFormData( + MultiValueMap formData) { + Assert.notNull(formData, "'formData' must not be null"); return (outputMessage, context) -> { HttpMessageWriter> messageWriter = findMessageWriter(context, FORM_TYPE, MediaType.APPLICATION_FORM_URLENCODED); @@ -223,9 +223,8 @@ public abstract class BodyInserters { }; } - private static HttpMessageWriter findMessageWriter(BodyInserter.Context context, - ResolvableType type, - MediaType mediaType) { + private static HttpMessageWriter findMessageWriter( + BodyInserter.Context context, ResolvableType type, MediaType mediaType) { return context.messageWriters().get() .filter(messageWriter -> messageWriter.canWrite(type, mediaType)) @@ -238,24 +237,24 @@ public abstract class BodyInserters { /** - * Return a {@code BodyInserter} that writes the given {@code Publisher} to the - * body. + * Return a {@code BodyInserter} that writes the given {@code Publisher} to the body. * @param publisher the data buffer publisher to write * @param the type of the publisher * @return a {@code BodyInserter} that writes directly to the body * @see ReactiveHttpOutputMessage#writeWith(Publisher) */ - public static > BodyInserter fromDataBuffers(T publisher) { - Assert.notNull(publisher, "'publisher' must not be null"); + public static > BodyInserter fromDataBuffers( + T publisher) { + Assert.notNull(publisher, "'publisher' must not be null"); return (outputMessage, context) -> outputMessage.writeWith(publisher); } - private static , M extends ReactiveHttpOutputMessage> BodyInserter bodyInserterFor(P body, ResolvableType bodyType) { + private static , M extends ReactiveHttpOutputMessage> BodyInserter bodyInserterFor( + P body, ResolvableType bodyType) { return (m, context) -> { - MediaType contentType = m.getHeaders().getContentType(); Supplier>> messageWriters = context.messageWriters(); return messageWriters.get() @@ -280,5 +279,4 @@ public abstract class BodyInserters { return (HttpMessageWriter) messageWriter; } - } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RouterFunction.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RouterFunction.java index a7f4dfe2164..210486c55a4 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RouterFunction.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RouterFunction.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. @@ -41,12 +41,11 @@ public interface RouterFunction { /** * Return a composed routing function that first invokes this function, - * and then invokes the {@code other} function (of the same type {@code T}) if this route had - * {@linkplain Mono#empty() no result}. - * + * and then invokes the {@code other} function (of the same type {@code T}) + * if this route had {@linkplain Mono#empty() no result}. * @param other the function of type {@code T} to apply when this function has no result - * @return a composed function that first routes with this function and then the {@code other} function if this - * function has no result + * @return a composed function that first routes with this function and then the + * {@code other} function if this function has no result */ default RouterFunction andSame(RouterFunction other) { return request -> this.route(request).otherwiseIfEmpty(other.route(request)); @@ -56,10 +55,9 @@ public interface RouterFunction { * Return a composed routing function that first invokes this function, * and then invokes the {@code other} function (of a different type) if this route had * {@linkplain Optional#empty() no result}. - * * @param other the function to apply when this function has no result - * @return a composed function that first routes with this function and then the {@code other} function if this - * function has no result + * @return a composed function that first routes with this function and then the + * {@code other} function if this function has no result */ default RouterFunction and(RouterFunction other) { return request -> this.route(request) @@ -72,24 +70,24 @@ public interface RouterFunction { * and then routes to the given handler function if the given request predicate applies. This * method is a convenient combination of {@link #and(RouterFunction)} and * {@link RouterFunctions#route(RequestPredicate, HandlerFunction)}. + * @param the handler function type * @param predicate the predicate to test * @param handlerFunction the handler function to route to - * @param the handler function type * @return a composed function that first routes with this function and then the function * created from {@code predicate} and {@code handlerFunction} if this * function has no result */ default RouterFunction andRoute(RequestPredicate predicate, HandlerFunction handlerFunction) { + return and(RouterFunctions.route(predicate, handlerFunction)); } /** * Filter all {@linkplain HandlerFunction handler functions} routed by this function with the given * {@linkplain HandlerFilterFunction filter function}. - * + * @param the filter return type * @param filterFunction the filter to apply - * @param the filter return type * @return the filtered routing function */ default RouterFunction filter(HandlerFilterFunction filterFunction) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/AbstractView.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/AbstractView.java index 5729f68e055..c0440c70720 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/AbstractView.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/AbstractView.java @@ -41,7 +41,7 @@ import org.springframework.web.server.ServerWebExchange; */ public abstract class AbstractView implements View, ApplicationContextAware { - /** Well-known name for the RequestDataValueProcessor in the bean factory. */ + /** Well-known name for the RequestDataValueProcessor in the bean factory */ public static final String REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME = "requestDataValueProcessor"; @@ -68,7 +68,7 @@ public abstract class AbstractView implements View, ApplicationContextAware { * Default is "text/html;charset=UTF-8". */ public void setSupportedMediaTypes(List supportedMediaTypes) { - Assert.notEmpty(supportedMediaTypes, "'supportedMediaTypes' is required."); + Assert.notEmpty(supportedMediaTypes, "MediaType List must not be empty"); this.mediaTypes.clear(); if (supportedMediaTypes != null) { this.mediaTypes.addAll(supportedMediaTypes); @@ -122,7 +122,7 @@ public abstract class AbstractView implements View, ApplicationContextAware { } public ApplicationContext getApplicationContext() { - return applicationContext; + return this.applicationContext; } /** diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/UrlBasedViewResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/UrlBasedViewResolver.java index b357738bb41..0dc0236bbe9 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/UrlBasedViewResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/UrlBasedViewResolver.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. @@ -25,7 +25,6 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.InitializingBean; import org.springframework.util.PatternMatchUtils; - /** * A {@link ViewResolver} that allow direct resolution of symbolic view names * to URLs without explicit mapping definition. This is useful if symbolic names @@ -52,6 +51,7 @@ import org.springframework.util.PatternMatchUtils; * *

Note: This class does not support localized resolution, i.e. resolving * a symbolic view name to different resources depending on the current locale. + * * @author Rossen Stoyanchev * @author Sebastien Deleuze * @since 5.0 @@ -75,7 +75,7 @@ public class UrlBasedViewResolver extends ViewResolverSupport implements ViewRes private String[] viewNames; - private Function redirectViewProvider = url -> new RedirectView(url); + private Function redirectViewProvider = RedirectView::new; private String requestContextAttribute; @@ -194,6 +194,7 @@ public class UrlBasedViewResolver extends ViewResolverSupport implements ViewRes if (!canHandle(viewName, locale)) { return Mono.empty(); } + AbstractUrlBasedView urlBasedView; if (viewName.startsWith(REDIRECT_URL_PREFIX)) { String redirectUrl = viewName.substring(REDIRECT_URL_PREFIX.length()); @@ -202,6 +203,7 @@ public class UrlBasedViewResolver extends ViewResolverSupport implements ViewRes else { urlBasedView = createUrlBasedView(viewName); } + View view = applyLifecycleMethods(viewName, urlBasedView); try { return (urlBasedView.checkResourceExists(locale) ? Mono.just(view) : Mono.empty()); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/ViewResolverSupport.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/ViewResolverSupport.java index 5fec6c17049..c53d7a21e04 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/ViewResolverSupport.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/ViewResolverSupport.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. @@ -57,7 +57,7 @@ public abstract class ViewResolverSupport implements ApplicationContextAware, Or * Default is "text/html;charset=UTF-8". */ public void setSupportedMediaTypes(List supportedMediaTypes) { - Assert.notEmpty(supportedMediaTypes, "'supportedMediaTypes' is required."); + Assert.notEmpty(supportedMediaTypes, "MediaType List must not be empty"); this.mediaTypes.clear(); if (supportedMediaTypes != null) { this.mediaTypes.addAll(supportedMediaTypes); @@ -77,7 +77,7 @@ public abstract class ViewResolverSupport implements ApplicationContextAware, Or * Default is {@linkplain StandardCharsets#UTF_8 UTF 8}. */ public void setDefaultCharset(Charset defaultCharset) { - Assert.notNull(defaultCharset, "'defaultCharset' must not be null"); + Assert.notNull(defaultCharset, "Default Charset must not be null"); this.defaultCharset = defaultCharset; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerViewResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerViewResolver.java index 215efcfa1f5..b54a99fe1c6 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerViewResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerViewResolver.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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.reactive.result.view.freemarker; import org.springframework.web.reactive.result.view.UrlBasedViewResolver; @@ -29,7 +30,6 @@ import org.springframework.web.reactive.result.view.UrlBasedViewResolver; */ public class FreeMarkerViewResolver extends UrlBasedViewResolver { - /** * Simple constructor. */ diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/freemarker/package-info.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/freemarker/package-info.java new file mode 100644 index 00000000000..2514b6b9b89 --- /dev/null +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/freemarker/package-info.java @@ -0,0 +1,7 @@ +/** + * Support classes for the integration of + * FreeMarker + * as Spring web view technology. + * Contains a View implementation for FreeMarker templates. + */ +package org.springframework.web.reactive.result.view.freemarker; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/RequestPredicatesTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/RequestPredicatesTests.java index f73fafa1ca9..7fa2bfdc8b3 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/RequestPredicatesTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/RequestPredicatesTests.java @@ -81,7 +81,6 @@ public class RequestPredicatesTests { predicate = RequestPredicates.OPTIONS("/p*"); request = MockServerRequest.builder().method(HttpMethod.OPTIONS).uri(uri).build(); assertTrue(predicate.test(request)); - } @Test @@ -100,10 +99,8 @@ public class RequestPredicatesTests { String name = "MyHeader"; String value = "MyValue"; RequestPredicate predicate = - RequestPredicates.headers(headers -> { - return headers.header(name).equals( - Collections.singletonList(value)); - }); + RequestPredicates.headers( + headers -> headers.header(name).equals(Collections.singletonList(value))); MockServerRequest request = MockServerRequest.builder().header(name, value).build(); assertTrue(predicate.test(request)); @@ -115,8 +112,7 @@ public class RequestPredicatesTests { public void contentType() throws Exception { MediaType json = MediaType.APPLICATION_JSON; RequestPredicate predicate = RequestPredicates.contentType(json); - MockServerRequest - request = MockServerRequest.builder().header("Content-Type", json.toString()).build(); + MockServerRequest request = MockServerRequest.builder().header("Content-Type", json.toString()).build(); assertTrue(predicate.test(request)); request = MockServerRequest.builder().build(); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/RouterFunctionsTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/RouterFunctionsTests.java index ed8ef6e28f9..20c557b5822 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/RouterFunctionsTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/RouterFunctionsTests.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. @@ -30,11 +30,8 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse import org.springframework.web.reactive.result.view.ViewResolver; import org.springframework.web.server.ServerWebExchange; -import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; /** * @author Arjen Poutsma @@ -114,7 +111,6 @@ public class RouterFunctionsTests { StepVerifier.create(resultHandlerFunction) .expectComplete() .verify(); - } @Test @@ -140,7 +136,6 @@ public class RouterFunctionsTests { RequestPredicate requestPredicate = mock(RequestPredicate.class); when(requestPredicate.test(request)).thenReturn(false); - HttpHandler result = RouterFunctions.toHttpHandler(routerFunction, strategies); assertNotNull(result);