Polishing
This commit is contained in:
parent
e1bb697cf9
commit
e9019cd7d1
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -169,8 +169,7 @@ public class SqlLobValue implements DisposableSqlTypeValue {
|
||||||
* Set the specified content via the LobCreator.
|
* Set the specified content via the LobCreator.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setTypeValue(PreparedStatement ps, int paramIndex, int sqlType, String typeName)
|
public void setTypeValue(PreparedStatement ps, int paramIndex, int sqlType, String typeName) throws SQLException {
|
||||||
throws SQLException {
|
|
||||||
if (sqlType == Types.BLOB) {
|
if (sqlType == Types.BLOB) {
|
||||||
if (this.content instanceof byte[] || this.content == null) {
|
if (this.content instanceof byte[] || this.content == null) {
|
||||||
this.lobCreator.setBlobAsBytes(ps, paramIndex, (byte[]) this.content);
|
this.lobCreator.setBlobAsBytes(ps, paramIndex, (byte[]) this.content);
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* Provides a stategy interface for Large OBject handling,
|
* Provides a strategy interface for Large OBject handling,
|
||||||
* with implementations for various databases.
|
* as well as a customizable default implementation.
|
||||||
*
|
|
||||||
* <p>Can be used independently from jdbc.core and jdbc.object,
|
|
||||||
* for example in custom JDBC access code.
|
|
||||||
*/
|
*/
|
||||||
package org.springframework.jdbc.support.lob;
|
package org.springframework.jdbc.support.lob;
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -131,8 +131,8 @@ public abstract class ConnectionFactoryUtils {
|
||||||
* @return the transactional Session, or {@code null} if none found
|
* @return the transactional Session, or {@code null} if none found
|
||||||
* @throws JMSException in case of JMS failure
|
* @throws JMSException in case of JMS failure
|
||||||
*/
|
*/
|
||||||
public static Session getTransactionalSession(
|
public static Session getTransactionalSession(final ConnectionFactory cf,
|
||||||
final ConnectionFactory cf, final Connection existingCon, final boolean synchedLocalTransactionAllowed)
|
final Connection existingCon, final boolean synchedLocalTransactionAllowed)
|
||||||
throws JMSException {
|
throws JMSException {
|
||||||
|
|
||||||
return doGetTransactionalSession(cf, new ResourceFactory() {
|
return doGetTransactionalSession(cf, new ResourceFactory() {
|
||||||
|
|
@ -173,8 +173,8 @@ public abstract class ConnectionFactoryUtils {
|
||||||
* @return the transactional Session, or {@code null} if none found
|
* @return the transactional Session, or {@code null} if none found
|
||||||
* @throws JMSException in case of JMS failure
|
* @throws JMSException in case of JMS failure
|
||||||
*/
|
*/
|
||||||
public static QueueSession getTransactionalQueueSession(
|
public static QueueSession getTransactionalQueueSession(final QueueConnectionFactory cf,
|
||||||
final QueueConnectionFactory cf, final QueueConnection existingCon, final boolean synchedLocalTransactionAllowed)
|
final QueueConnection existingCon, final boolean synchedLocalTransactionAllowed)
|
||||||
throws JMSException {
|
throws JMSException {
|
||||||
|
|
||||||
return (QueueSession) doGetTransactionalSession(cf, new ResourceFactory() {
|
return (QueueSession) doGetTransactionalSession(cf, new ResourceFactory() {
|
||||||
|
|
@ -215,8 +215,8 @@ public abstract class ConnectionFactoryUtils {
|
||||||
* @return the transactional Session, or {@code null} if none found
|
* @return the transactional Session, or {@code null} if none found
|
||||||
* @throws JMSException in case of JMS failure
|
* @throws JMSException in case of JMS failure
|
||||||
*/
|
*/
|
||||||
public static TopicSession getTransactionalTopicSession(
|
public static TopicSession getTransactionalTopicSession(final TopicConnectionFactory cf,
|
||||||
final TopicConnectionFactory cf, final TopicConnection existingCon, final boolean synchedLocalTransactionAllowed)
|
final TopicConnection existingCon, final boolean synchedLocalTransactionAllowed)
|
||||||
throws JMSException {
|
throws JMSException {
|
||||||
|
|
||||||
return (TopicSession) doGetTransactionalSession(cf, new ResourceFactory() {
|
return (TopicSession) doGetTransactionalSession(cf, new ResourceFactory() {
|
||||||
|
|
@ -234,7 +234,8 @@ public abstract class ConnectionFactoryUtils {
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public Session createSession(Connection con) throws JMSException {
|
public Session createSession(Connection con) throws JMSException {
|
||||||
return ((TopicConnection) con).createTopicSession(synchedLocalTransactionAllowed, Session.AUTO_ACKNOWLEDGE);
|
return ((TopicConnection) con).createTopicSession(
|
||||||
|
synchedLocalTransactionAllowed, Session.AUTO_ACKNOWLEDGE);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean isSynchedLocalTransactionAllowed() {
|
public boolean isSynchedLocalTransactionAllowed() {
|
||||||
|
|
@ -339,8 +340,8 @@ public abstract class ConnectionFactoryUtils {
|
||||||
}
|
}
|
||||||
if (resourceHolderToUse != resourceHolder) {
|
if (resourceHolderToUse != resourceHolder) {
|
||||||
TransactionSynchronizationManager.registerSynchronization(
|
TransactionSynchronizationManager.registerSynchronization(
|
||||||
new JmsResourceSynchronization(
|
new JmsResourceSynchronization(resourceHolderToUse, connectionFactory,
|
||||||
resourceHolderToUse, connectionFactory, resourceFactory.isSynchedLocalTransactionAllowed()));
|
resourceFactory.isSynchedLocalTransactionAllowed()));
|
||||||
resourceHolderToUse.setSynchronizedWithTransaction(true);
|
resourceHolderToUse.setSynchronizedWithTransaction(true);
|
||||||
TransactionSynchronizationManager.bindResource(connectionFactory, resourceHolderToUse);
|
TransactionSynchronizationManager.bindResource(connectionFactory, resourceHolderToUse);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -40,15 +40,12 @@ public abstract class TransactionCallbackWithoutResult implements TransactionCal
|
||||||
* context. Does not need to care about transactions itself, although it can retrieve
|
* 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,
|
* and influence the status of the current transaction via the given status object,
|
||||||
* e.g. setting rollback-only.
|
* e.g. setting rollback-only.
|
||||||
*
|
|
||||||
* <p>A RuntimeException thrown by the callback is treated as application
|
* <p>A RuntimeException thrown by the callback is treated as application
|
||||||
* exception that enforces a rollback. An exception gets propagated to the
|
* exception that enforces a rollback. An exception gets propagated to the
|
||||||
* caller of the template.
|
* caller of the template.
|
||||||
*
|
|
||||||
* <p>Note when using JTA: JTA transactions only work with transactional
|
* <p>Note when using JTA: JTA transactions only work with transactional
|
||||||
* JNDI resources, so implementations need to use such resources if they
|
* JNDI resources, so implementations need to use such resources if they
|
||||||
* want transaction support.
|
* want transaction support.
|
||||||
*
|
|
||||||
* @param status associated transaction status
|
* @param status associated transaction status
|
||||||
* @see TransactionTemplate#execute
|
* @see TransactionTemplate#execute
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -85,8 +85,8 @@ public abstract class BodyInserters {
|
||||||
* @param <P> the type of the {@code Publisher}
|
* @param <P> the type of the {@code Publisher}
|
||||||
* @return a {@code BodyInserter} that writes a {@code Publisher}
|
* @return a {@code BodyInserter} that writes a {@code Publisher}
|
||||||
*/
|
*/
|
||||||
public static <T, P extends Publisher<T>> BodyInserter<P, ReactiveHttpOutputMessage> fromPublisher(P publisher,
|
public static <T, P extends Publisher<T>> BodyInserter<P, ReactiveHttpOutputMessage> fromPublisher(
|
||||||
Class<T> elementClass) {
|
P publisher, Class<T> elementClass) {
|
||||||
|
|
||||||
Assert.notNull(publisher, "'publisher' must not be null");
|
Assert.notNull(publisher, "'publisher' must not be null");
|
||||||
Assert.notNull(elementClass, "'elementClass' must not be null");
|
Assert.notNull(elementClass, "'elementClass' must not be null");
|
||||||
|
|
@ -101,8 +101,8 @@ public abstract class BodyInserters {
|
||||||
* @param <P> the type of the {@code Publisher}
|
* @param <P> the type of the {@code Publisher}
|
||||||
* @return a {@code BodyInserter} that writes a {@code Publisher}
|
* @return a {@code BodyInserter} that writes a {@code Publisher}
|
||||||
*/
|
*/
|
||||||
public static <T, P extends Publisher<T>> BodyInserter<P, ReactiveHttpOutputMessage> fromPublisher(P publisher,
|
public static <T, P extends Publisher<T>> BodyInserter<P, ReactiveHttpOutputMessage> fromPublisher(
|
||||||
ResolvableType elementType) {
|
P publisher, ResolvableType elementType) {
|
||||||
|
|
||||||
Assert.notNull(publisher, "'publisher' must not be null");
|
Assert.notNull(publisher, "'publisher' must not be null");
|
||||||
Assert.notNull(elementType, "'elementType' 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}.
|
* 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
|
* <p>If the resource can be resolved to a {@linkplain Resource#getFile() file}, it will
|
||||||
* using
|
* be copied using <a href="https://en.wikipedia.org/wiki/Zero-copy">zero-copy</a>.
|
||||||
* <a href="https://en.wikipedia.org/wiki/Zero-copy">zero-copy</a>
|
|
||||||
* @param resource the resource to write to the output message
|
* @param resource the resource to write to the output message
|
||||||
* @param <T> the type of the {@code Resource}
|
* @param <T> the type of the {@code Resource}
|
||||||
* @return a {@code BodyInserter} that writes a {@code Publisher}
|
* @return a {@code BodyInserter} that writes a {@code Publisher}
|
||||||
|
|
@ -133,7 +132,7 @@ public abstract class BodyInserters {
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.map(BodyInserters::<Resource>cast)
|
.map(BodyInserters::<Resource>cast)
|
||||||
.orElseThrow(() -> new IllegalStateException(
|
.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
|
* @param formData the form data to write to the output message
|
||||||
* @return a {@code BodyInserter} that writes form data
|
* @return a {@code BodyInserter} that writes form data
|
||||||
*/
|
*/
|
||||||
public static BodyInserter<MultiValueMap<String, String>, ClientHttpRequest> fromFormData(MultiValueMap<String, String> formData) {
|
public static BodyInserter<MultiValueMap<String, String>, ClientHttpRequest> fromFormData(
|
||||||
Assert.notNull(formData, "'formData' must not be null");
|
MultiValueMap<String, String> formData) {
|
||||||
|
|
||||||
|
Assert.notNull(formData, "'formData' must not be null");
|
||||||
return (outputMessage, context) -> {
|
return (outputMessage, context) -> {
|
||||||
HttpMessageWriter<MultiValueMap<String, String>> messageWriter =
|
HttpMessageWriter<MultiValueMap<String, String>> messageWriter =
|
||||||
findMessageWriter(context, FORM_TYPE, MediaType.APPLICATION_FORM_URLENCODED);
|
findMessageWriter(context, FORM_TYPE, MediaType.APPLICATION_FORM_URLENCODED);
|
||||||
|
|
@ -223,9 +223,8 @@ public abstract class BodyInserters {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> HttpMessageWriter<T> findMessageWriter(BodyInserter.Context context,
|
private static <T> HttpMessageWriter<T> findMessageWriter(
|
||||||
ResolvableType type,
|
BodyInserter.Context context, ResolvableType type, MediaType mediaType) {
|
||||||
MediaType mediaType) {
|
|
||||||
|
|
||||||
return context.messageWriters().get()
|
return context.messageWriters().get()
|
||||||
.filter(messageWriter -> messageWriter.canWrite(type, mediaType))
|
.filter(messageWriter -> messageWriter.canWrite(type, mediaType))
|
||||||
|
|
@ -238,24 +237,24 @@ public abstract class BodyInserters {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a {@code BodyInserter} that writes the given {@code Publisher<DataBuffer>} to the
|
* Return a {@code BodyInserter} that writes the given {@code Publisher<DataBuffer>} to the body.
|
||||||
* body.
|
|
||||||
* @param publisher the data buffer publisher to write
|
* @param publisher the data buffer publisher to write
|
||||||
* @param <T> the type of the publisher
|
* @param <T> the type of the publisher
|
||||||
* @return a {@code BodyInserter} that writes directly to the body
|
* @return a {@code BodyInserter} that writes directly to the body
|
||||||
* @see ReactiveHttpOutputMessage#writeWith(Publisher)
|
* @see ReactiveHttpOutputMessage#writeWith(Publisher)
|
||||||
*/
|
*/
|
||||||
public static <T extends Publisher<DataBuffer>> BodyInserter<T, ReactiveHttpOutputMessage> fromDataBuffers(T publisher) {
|
public static <T extends Publisher<DataBuffer>> BodyInserter<T, ReactiveHttpOutputMessage> fromDataBuffers(
|
||||||
Assert.notNull(publisher, "'publisher' must not be null");
|
T publisher) {
|
||||||
|
|
||||||
|
Assert.notNull(publisher, "'publisher' must not be null");
|
||||||
return (outputMessage, context) -> outputMessage.writeWith(publisher);
|
return (outputMessage, context) -> outputMessage.writeWith(publisher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static <T, P extends Publisher<?>, M extends ReactiveHttpOutputMessage> BodyInserter<T, M> bodyInserterFor(P body, ResolvableType bodyType) {
|
private static <T, P extends Publisher<?>, M extends ReactiveHttpOutputMessage> BodyInserter<T, M> bodyInserterFor(
|
||||||
|
P body, ResolvableType bodyType) {
|
||||||
|
|
||||||
return (m, context) -> {
|
return (m, context) -> {
|
||||||
|
|
||||||
MediaType contentType = m.getHeaders().getContentType();
|
MediaType contentType = m.getHeaders().getContentType();
|
||||||
Supplier<Stream<HttpMessageWriter<?>>> messageWriters = context.messageWriters();
|
Supplier<Stream<HttpMessageWriter<?>>> messageWriters = context.messageWriters();
|
||||||
return messageWriters.get()
|
return messageWriters.get()
|
||||||
|
|
@ -280,5 +279,4 @@ public abstract class BodyInserters {
|
||||||
return (HttpMessageWriter<T>) messageWriter;
|
return (HttpMessageWriter<T>) messageWriter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -41,12 +41,11 @@ public interface RouterFunction<T extends ServerResponse> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a composed routing function that first invokes this function,
|
* 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
|
* and then invokes the {@code other} function (of the same type {@code T})
|
||||||
* {@linkplain Mono#empty() no result}.
|
* 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
|
* @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
|
* @return a composed function that first routes with this function and then the
|
||||||
* function has no result
|
* {@code other} function if this function has no result
|
||||||
*/
|
*/
|
||||||
default RouterFunction<T> andSame(RouterFunction<T> other) {
|
default RouterFunction<T> andSame(RouterFunction<T> other) {
|
||||||
return request -> this.route(request).otherwiseIfEmpty(other.route(request));
|
return request -> this.route(request).otherwiseIfEmpty(other.route(request));
|
||||||
|
|
@ -56,10 +55,9 @@ public interface RouterFunction<T extends ServerResponse> {
|
||||||
* Return a composed routing function that first invokes this function,
|
* 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
|
* and then invokes the {@code other} function (of a different type) if this route had
|
||||||
* {@linkplain Optional#empty() no result}.
|
* {@linkplain Optional#empty() no result}.
|
||||||
*
|
|
||||||
* @param other the function to apply when this function has 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
|
* @return a composed function that first routes with this function and then the
|
||||||
* function has no result
|
* {@code other} function if this function has no result
|
||||||
*/
|
*/
|
||||||
default RouterFunction<?> and(RouterFunction<?> other) {
|
default RouterFunction<?> and(RouterFunction<?> other) {
|
||||||
return request -> this.route(request)
|
return request -> this.route(request)
|
||||||
|
|
@ -72,24 +70,24 @@ public interface RouterFunction<T extends ServerResponse> {
|
||||||
* and then routes to the given handler function if the given request predicate applies. This
|
* 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
|
* method is a convenient combination of {@link #and(RouterFunction)} and
|
||||||
* {@link RouterFunctions#route(RequestPredicate, HandlerFunction)}.
|
* {@link RouterFunctions#route(RequestPredicate, HandlerFunction)}.
|
||||||
|
* @param <S> the handler function type
|
||||||
* @param predicate the predicate to test
|
* @param predicate the predicate to test
|
||||||
* @param handlerFunction the handler function to route to
|
* @param handlerFunction the handler function to route to
|
||||||
* @param <S> the handler function type
|
|
||||||
* @return a composed function that first routes with this function and then the function
|
* @return a composed function that first routes with this function and then the function
|
||||||
* created from {@code predicate} and {@code handlerFunction} if this
|
* created from {@code predicate} and {@code handlerFunction} if this
|
||||||
* function has no result
|
* function has no result
|
||||||
*/
|
*/
|
||||||
default <S extends ServerResponse> RouterFunction<?> andRoute(RequestPredicate predicate,
|
default <S extends ServerResponse> RouterFunction<?> andRoute(RequestPredicate predicate,
|
||||||
HandlerFunction<S> handlerFunction) {
|
HandlerFunction<S> handlerFunction) {
|
||||||
|
|
||||||
return and(RouterFunctions.route(predicate, handlerFunction));
|
return and(RouterFunctions.route(predicate, handlerFunction));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter all {@linkplain HandlerFunction handler functions} routed by this function with the given
|
* Filter all {@linkplain HandlerFunction handler functions} routed by this function with the given
|
||||||
* {@linkplain HandlerFilterFunction filter function}.
|
* {@linkplain HandlerFilterFunction filter function}.
|
||||||
*
|
|
||||||
* @param filterFunction the filter to apply
|
|
||||||
* @param <S> the filter return type
|
* @param <S> the filter return type
|
||||||
|
* @param filterFunction the filter to apply
|
||||||
* @return the filtered routing function
|
* @return the filtered routing function
|
||||||
*/
|
*/
|
||||||
default <S extends ServerResponse> RouterFunction<S> filter(HandlerFilterFunction<T, S> filterFunction) {
|
default <S extends ServerResponse> RouterFunction<S> filter(HandlerFilterFunction<T, S> filterFunction) {
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ import org.springframework.web.server.ServerWebExchange;
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractView implements View, ApplicationContextAware {
|
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";
|
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".
|
* Default is "text/html;charset=UTF-8".
|
||||||
*/
|
*/
|
||||||
public void setSupportedMediaTypes(List<MediaType> supportedMediaTypes) {
|
public void setSupportedMediaTypes(List<MediaType> supportedMediaTypes) {
|
||||||
Assert.notEmpty(supportedMediaTypes, "'supportedMediaTypes' is required.");
|
Assert.notEmpty(supportedMediaTypes, "MediaType List must not be empty");
|
||||||
this.mediaTypes.clear();
|
this.mediaTypes.clear();
|
||||||
if (supportedMediaTypes != null) {
|
if (supportedMediaTypes != null) {
|
||||||
this.mediaTypes.addAll(supportedMediaTypes);
|
this.mediaTypes.addAll(supportedMediaTypes);
|
||||||
|
|
@ -122,7 +122,7 @@ public abstract class AbstractView implements View, ApplicationContextAware {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApplicationContext getApplicationContext() {
|
public ApplicationContext getApplicationContext() {
|
||||||
return applicationContext;
|
return this.applicationContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -25,7 +25,6 @@ import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.util.PatternMatchUtils;
|
import org.springframework.util.PatternMatchUtils;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link ViewResolver} that allow direct resolution of symbolic view names
|
* A {@link ViewResolver} that allow direct resolution of symbolic view names
|
||||||
* to URLs without explicit mapping definition. This is useful if symbolic names
|
* to URLs without explicit mapping definition. This is useful if symbolic names
|
||||||
|
|
@ -52,6 +51,7 @@ import org.springframework.util.PatternMatchUtils;
|
||||||
*
|
*
|
||||||
* <p>Note: This class does not support localized resolution, i.e. resolving
|
* <p>Note: This class does not support localized resolution, i.e. resolving
|
||||||
* a symbolic view name to different resources depending on the current locale.
|
* a symbolic view name to different resources depending on the current locale.
|
||||||
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Sebastien Deleuze
|
* @author Sebastien Deleuze
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
|
|
@ -75,7 +75,7 @@ public class UrlBasedViewResolver extends ViewResolverSupport implements ViewRes
|
||||||
|
|
||||||
private String[] viewNames;
|
private String[] viewNames;
|
||||||
|
|
||||||
private Function<String, RedirectView> redirectViewProvider = url -> new RedirectView(url);
|
private Function<String, RedirectView> redirectViewProvider = RedirectView::new;
|
||||||
|
|
||||||
private String requestContextAttribute;
|
private String requestContextAttribute;
|
||||||
|
|
||||||
|
|
@ -194,6 +194,7 @@ public class UrlBasedViewResolver extends ViewResolverSupport implements ViewRes
|
||||||
if (!canHandle(viewName, locale)) {
|
if (!canHandle(viewName, locale)) {
|
||||||
return Mono.empty();
|
return Mono.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractUrlBasedView urlBasedView;
|
AbstractUrlBasedView urlBasedView;
|
||||||
if (viewName.startsWith(REDIRECT_URL_PREFIX)) {
|
if (viewName.startsWith(REDIRECT_URL_PREFIX)) {
|
||||||
String redirectUrl = viewName.substring(REDIRECT_URL_PREFIX.length());
|
String redirectUrl = viewName.substring(REDIRECT_URL_PREFIX.length());
|
||||||
|
|
@ -202,6 +203,7 @@ public class UrlBasedViewResolver extends ViewResolverSupport implements ViewRes
|
||||||
else {
|
else {
|
||||||
urlBasedView = createUrlBasedView(viewName);
|
urlBasedView = createUrlBasedView(viewName);
|
||||||
}
|
}
|
||||||
|
|
||||||
View view = applyLifecycleMethods(viewName, urlBasedView);
|
View view = applyLifecycleMethods(viewName, urlBasedView);
|
||||||
try {
|
try {
|
||||||
return (urlBasedView.checkResourceExists(locale) ? Mono.just(view) : Mono.empty());
|
return (urlBasedView.checkResourceExists(locale) ? Mono.just(view) : Mono.empty());
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -57,7 +57,7 @@ public abstract class ViewResolverSupport implements ApplicationContextAware, Or
|
||||||
* Default is "text/html;charset=UTF-8".
|
* Default is "text/html;charset=UTF-8".
|
||||||
*/
|
*/
|
||||||
public void setSupportedMediaTypes(List<MediaType> supportedMediaTypes) {
|
public void setSupportedMediaTypes(List<MediaType> supportedMediaTypes) {
|
||||||
Assert.notEmpty(supportedMediaTypes, "'supportedMediaTypes' is required.");
|
Assert.notEmpty(supportedMediaTypes, "MediaType List must not be empty");
|
||||||
this.mediaTypes.clear();
|
this.mediaTypes.clear();
|
||||||
if (supportedMediaTypes != null) {
|
if (supportedMediaTypes != null) {
|
||||||
this.mediaTypes.addAll(supportedMediaTypes);
|
this.mediaTypes.addAll(supportedMediaTypes);
|
||||||
|
|
@ -77,7 +77,7 @@ public abstract class ViewResolverSupport implements ApplicationContextAware, Or
|
||||||
* Default is {@linkplain StandardCharsets#UTF_8 UTF 8}.
|
* Default is {@linkplain StandardCharsets#UTF_8 UTF 8}.
|
||||||
*/
|
*/
|
||||||
public void setDefaultCharset(Charset defaultCharset) {
|
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;
|
this.defaultCharset = defaultCharset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.web.reactive.result.view.freemarker;
|
package org.springframework.web.reactive.result.view.freemarker;
|
||||||
|
|
||||||
import org.springframework.web.reactive.result.view.UrlBasedViewResolver;
|
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 {
|
public class FreeMarkerViewResolver extends UrlBasedViewResolver {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple constructor.
|
* Simple constructor.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
/**
|
||||||
|
* Support classes for the integration of
|
||||||
|
* <a href="http://www.freemarker.org">FreeMarker</a>
|
||||||
|
* as Spring web view technology.
|
||||||
|
* Contains a View implementation for FreeMarker templates.
|
||||||
|
*/
|
||||||
|
package org.springframework.web.reactive.result.view.freemarker;
|
||||||
|
|
@ -81,7 +81,6 @@ public class RequestPredicatesTests {
|
||||||
predicate = RequestPredicates.OPTIONS("/p*");
|
predicate = RequestPredicates.OPTIONS("/p*");
|
||||||
request = MockServerRequest.builder().method(HttpMethod.OPTIONS).uri(uri).build();
|
request = MockServerRequest.builder().method(HttpMethod.OPTIONS).uri(uri).build();
|
||||||
assertTrue(predicate.test(request));
|
assertTrue(predicate.test(request));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -100,10 +99,8 @@ public class RequestPredicatesTests {
|
||||||
String name = "MyHeader";
|
String name = "MyHeader";
|
||||||
String value = "MyValue";
|
String value = "MyValue";
|
||||||
RequestPredicate predicate =
|
RequestPredicate predicate =
|
||||||
RequestPredicates.headers(headers -> {
|
RequestPredicates.headers(
|
||||||
return headers.header(name).equals(
|
headers -> headers.header(name).equals(Collections.singletonList(value)));
|
||||||
Collections.singletonList(value));
|
|
||||||
});
|
|
||||||
MockServerRequest request = MockServerRequest.builder().header(name, value).build();
|
MockServerRequest request = MockServerRequest.builder().header(name, value).build();
|
||||||
assertTrue(predicate.test(request));
|
assertTrue(predicate.test(request));
|
||||||
|
|
||||||
|
|
@ -115,8 +112,7 @@ public class RequestPredicatesTests {
|
||||||
public void contentType() throws Exception {
|
public void contentType() throws Exception {
|
||||||
MediaType json = MediaType.APPLICATION_JSON;
|
MediaType json = MediaType.APPLICATION_JSON;
|
||||||
RequestPredicate predicate = RequestPredicates.contentType(json);
|
RequestPredicate predicate = RequestPredicates.contentType(json);
|
||||||
MockServerRequest
|
MockServerRequest request = MockServerRequest.builder().header("Content-Type", json.toString()).build();
|
||||||
request = MockServerRequest.builder().header("Content-Type", json.toString()).build();
|
|
||||||
assertTrue(predicate.test(request));
|
assertTrue(predicate.test(request));
|
||||||
|
|
||||||
request = MockServerRequest.builder().build();
|
request = MockServerRequest.builder().build();
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -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.reactive.result.view.ViewResolver;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.*;
|
||||||
import static org.mockito.Mockito.any;
|
import static org.mockito.Mockito.*;
|
||||||
import static org.mockito.Mockito.eq;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
|
|
@ -114,7 +111,6 @@ public class RouterFunctionsTests {
|
||||||
StepVerifier.create(resultHandlerFunction)
|
StepVerifier.create(resultHandlerFunction)
|
||||||
.expectComplete()
|
.expectComplete()
|
||||||
.verify();
|
.verify();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -140,7 +136,6 @@ public class RouterFunctionsTests {
|
||||||
RequestPredicate requestPredicate = mock(RequestPredicate.class);
|
RequestPredicate requestPredicate = mock(RequestPredicate.class);
|
||||||
when(requestPredicate.test(request)).thenReturn(false);
|
when(requestPredicate.test(request)).thenReturn(false);
|
||||||
|
|
||||||
|
|
||||||
HttpHandler result = RouterFunctions.toHttpHandler(routerFunction, strategies);
|
HttpHandler result = RouterFunctions.toHttpHandler(routerFunction, strategies);
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue