Polishing
This commit is contained in:
parent
75117f42b8
commit
652266bcc2
|
|
@ -1208,7 +1208,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isRequired(DependencyDescriptor descriptor) {
|
private boolean isRequired(DependencyDescriptor descriptor) {
|
||||||
return this.autowireCandidateResolver.isRequired(descriptor);
|
return getAutowireCandidateResolver().isRequired(descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean indicatesMultipleBeans(Class<?> type) {
|
private boolean indicatesMultipleBeans(Class<?> type) {
|
||||||
|
|
|
||||||
|
|
@ -1283,8 +1283,8 @@ public abstract class AnnotationUtils {
|
||||||
* single-element Annotation, given an annotation instance.
|
* single-element Annotation, given an annotation instance.
|
||||||
* @param annotation the annotation instance from which to retrieve the value
|
* @param annotation the annotation instance from which to retrieve the value
|
||||||
* @return the attribute value, or {@code null} if not found unless the attribute
|
* @return the attribute value, or {@code null} if not found unless the attribute
|
||||||
* value cannot be retrieved due to an {@link AnnotationConfigurationException}, in
|
* value cannot be retrieved due to an {@link AnnotationConfigurationException},
|
||||||
* which case such an exception will be rethrown
|
* in which case such an exception will be rethrown
|
||||||
* @see #getValue(Annotation, String)
|
* @see #getValue(Annotation, String)
|
||||||
*/
|
*/
|
||||||
public static Object getValue(Annotation annotation) {
|
public static Object getValue(Annotation annotation) {
|
||||||
|
|
@ -1296,8 +1296,8 @@ public abstract class AnnotationUtils {
|
||||||
* @param annotation the annotation instance from which to retrieve the value
|
* @param annotation the annotation instance from which to retrieve the value
|
||||||
* @param attributeName the name of the attribute value to retrieve
|
* @param attributeName the name of the attribute value to retrieve
|
||||||
* @return the attribute value, or {@code null} if not found unless the attribute
|
* @return the attribute value, or {@code null} if not found unless the attribute
|
||||||
* value cannot be retrieved due to an {@link AnnotationConfigurationException}, in
|
* value cannot be retrieved due to an {@link AnnotationConfigurationException},
|
||||||
* which case such an exception will be rethrown
|
* in which case such an exception will be rethrown
|
||||||
* @see #getValue(Annotation)
|
* @see #getValue(Annotation)
|
||||||
* @see #rethrowAnnotationConfigurationException(Throwable)
|
* @see #rethrowAnnotationConfigurationException(Throwable)
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import javax.servlet.http.Cookie;
|
||||||
|
|
||||||
import org.hamcrest.Matcher;
|
import org.hamcrest.Matcher;
|
||||||
|
|
||||||
|
import org.springframework.test.web.servlet.MvcResult;
|
||||||
import org.springframework.test.web.servlet.ResultMatcher;
|
import org.springframework.test.web.servlet.ResultMatcher;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.*;
|
import static org.hamcrest.MatcherAssert.*;
|
||||||
|
|
@ -50,8 +51,7 @@ public class CookieResultMatchers {
|
||||||
*/
|
*/
|
||||||
public ResultMatcher value(final String name, final Matcher<? super String> matcher) {
|
public ResultMatcher value(final String name, final Matcher<? super String> matcher) {
|
||||||
return result -> {
|
return result -> {
|
||||||
Cookie cookie = result.getResponse().getCookie(name);
|
Cookie cookie = getCookie(result, name);
|
||||||
assertTrue("Response cookie '" + name + "' not found", cookie != null);
|
|
||||||
assertThat("Response cookie '" + name + "'", cookie.getValue(), matcher);
|
assertThat("Response cookie '" + name + "'", cookie.getValue(), matcher);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -61,8 +61,7 @@ public class CookieResultMatchers {
|
||||||
*/
|
*/
|
||||||
public ResultMatcher value(final String name, final String expectedValue) {
|
public ResultMatcher value(final String name, final String expectedValue) {
|
||||||
return result -> {
|
return result -> {
|
||||||
Cookie cookie = result.getResponse().getCookie(name);
|
Cookie cookie = getCookie(result, name);
|
||||||
assertTrue("Response cookie '" + name + "' not found", cookie != null);
|
|
||||||
assertEquals("Response cookie", expectedValue, cookie.getValue());
|
assertEquals("Response cookie", expectedValue, cookie.getValue());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -72,10 +71,7 @@ public class CookieResultMatchers {
|
||||||
* max age is 0 (i.e. expired).
|
* max age is 0 (i.e. expired).
|
||||||
*/
|
*/
|
||||||
public ResultMatcher exists(final String name) {
|
public ResultMatcher exists(final String name) {
|
||||||
return result -> {
|
return result -> getCookie(result, name);
|
||||||
Cookie cookie = result.getResponse().getCookie(name);
|
|
||||||
assertTrue("No cookie with name '" + name + "'", cookie != null);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -94,8 +90,7 @@ public class CookieResultMatchers {
|
||||||
*/
|
*/
|
||||||
public ResultMatcher maxAge(final String name, final Matcher<? super Integer> matcher) {
|
public ResultMatcher maxAge(final String name, final Matcher<? super Integer> matcher) {
|
||||||
return result -> {
|
return result -> {
|
||||||
Cookie cookie = result.getResponse().getCookie(name);
|
Cookie cookie = getCookie(result, name);
|
||||||
assertTrue("No cookie with name '" + name + "'", cookie != null);
|
|
||||||
assertThat("Response cookie '" + name + "' maxAge", cookie.getMaxAge(), matcher);
|
assertThat("Response cookie '" + name + "' maxAge", cookie.getMaxAge(), matcher);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -105,8 +100,7 @@ public class CookieResultMatchers {
|
||||||
*/
|
*/
|
||||||
public ResultMatcher maxAge(final String name, final int maxAge) {
|
public ResultMatcher maxAge(final String name, final int maxAge) {
|
||||||
return result -> {
|
return result -> {
|
||||||
Cookie cookie = result.getResponse().getCookie(name);
|
Cookie cookie = getCookie(result, name);
|
||||||
assertTrue("No cookie with name: " + name, cookie != null);
|
|
||||||
assertEquals("Response cookie '" + name + "' maxAge", maxAge, cookie.getMaxAge());
|
assertEquals("Response cookie '" + name + "' maxAge", maxAge, cookie.getMaxAge());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -116,14 +110,14 @@ public class CookieResultMatchers {
|
||||||
*/
|
*/
|
||||||
public ResultMatcher path(final String name, final Matcher<? super String> matcher) {
|
public ResultMatcher path(final String name, final Matcher<? super String> matcher) {
|
||||||
return result -> {
|
return result -> {
|
||||||
Cookie cookie = result.getResponse().getCookie(name);
|
Cookie cookie = getCookie(result, name);
|
||||||
assertThat("Response cookie '" + name + "' path", cookie.getPath(), matcher);
|
assertThat("Response cookie '" + name + "' path", cookie.getPath(), matcher);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultMatcher path(final String name, final String path) {
|
public ResultMatcher path(final String name, final String path) {
|
||||||
return result -> {
|
return result -> {
|
||||||
Cookie cookie = result.getResponse().getCookie(name);
|
Cookie cookie = getCookie(result, name);
|
||||||
assertEquals("Response cookie '" + name + "' path", path, cookie.getPath());
|
assertEquals("Response cookie '" + name + "' path", path, cookie.getPath());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -133,7 +127,7 @@ public class CookieResultMatchers {
|
||||||
*/
|
*/
|
||||||
public ResultMatcher domain(final String name, final Matcher<? super String> matcher) {
|
public ResultMatcher domain(final String name, final Matcher<? super String> matcher) {
|
||||||
return result -> {
|
return result -> {
|
||||||
Cookie cookie = result.getResponse().getCookie(name);
|
Cookie cookie = getCookie(result, name);
|
||||||
assertThat("Response cookie '" + name + "' domain", cookie.getDomain(), matcher);
|
assertThat("Response cookie '" + name + "' domain", cookie.getDomain(), matcher);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -143,7 +137,7 @@ public class CookieResultMatchers {
|
||||||
*/
|
*/
|
||||||
public ResultMatcher domain(final String name, final String domain) {
|
public ResultMatcher domain(final String name, final String domain) {
|
||||||
return result -> {
|
return result -> {
|
||||||
Cookie cookie = result.getResponse().getCookie(name);
|
Cookie cookie = getCookie(result, name);
|
||||||
assertEquals("Response cookie '" + name + "' domain", domain, cookie.getDomain());
|
assertEquals("Response cookie '" + name + "' domain", domain, cookie.getDomain());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -153,7 +147,7 @@ public class CookieResultMatchers {
|
||||||
*/
|
*/
|
||||||
public ResultMatcher comment(final String name, final Matcher<? super String> matcher) {
|
public ResultMatcher comment(final String name, final Matcher<? super String> matcher) {
|
||||||
return result -> {
|
return result -> {
|
||||||
Cookie cookie = result.getResponse().getCookie(name);
|
Cookie cookie = getCookie(result, name);
|
||||||
assertThat("Response cookie '" + name + "' comment", cookie.getComment(), matcher);
|
assertThat("Response cookie '" + name + "' comment", cookie.getComment(), matcher);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -163,7 +157,7 @@ public class CookieResultMatchers {
|
||||||
*/
|
*/
|
||||||
public ResultMatcher comment(final String name, final String comment) {
|
public ResultMatcher comment(final String name, final String comment) {
|
||||||
return result -> {
|
return result -> {
|
||||||
Cookie cookie = result.getResponse().getCookie(name);
|
Cookie cookie = getCookie(result, name);
|
||||||
assertEquals("Response cookie '" + name + "' comment", comment, cookie.getComment());
|
assertEquals("Response cookie '" + name + "' comment", comment, cookie.getComment());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -173,7 +167,7 @@ public class CookieResultMatchers {
|
||||||
*/
|
*/
|
||||||
public ResultMatcher version(final String name, final Matcher<? super Integer> matcher) {
|
public ResultMatcher version(final String name, final Matcher<? super Integer> matcher) {
|
||||||
return result -> {
|
return result -> {
|
||||||
Cookie cookie = result.getResponse().getCookie(name);
|
Cookie cookie = getCookie(result, name);
|
||||||
assertThat("Response cookie '" + name + "' version", cookie.getVersion(), matcher);
|
assertThat("Response cookie '" + name + "' version", cookie.getVersion(), matcher);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -183,7 +177,7 @@ public class CookieResultMatchers {
|
||||||
*/
|
*/
|
||||||
public ResultMatcher version(final String name, final int version) {
|
public ResultMatcher version(final String name, final int version) {
|
||||||
return result -> {
|
return result -> {
|
||||||
Cookie cookie = result.getResponse().getCookie(name);
|
Cookie cookie = getCookie(result, name);
|
||||||
assertEquals("Response cookie '" + name + "' version", version, cookie.getVersion());
|
assertEquals("Response cookie '" + name + "' version", version, cookie.getVersion());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -193,7 +187,7 @@ public class CookieResultMatchers {
|
||||||
*/
|
*/
|
||||||
public ResultMatcher secure(final String name, final boolean secure) {
|
public ResultMatcher secure(final String name, final boolean secure) {
|
||||||
return result -> {
|
return result -> {
|
||||||
Cookie cookie = result.getResponse().getCookie(name);
|
Cookie cookie = getCookie(result, name);
|
||||||
assertEquals("Response cookie '" + name + "' secure", secure, cookie.getSecure());
|
assertEquals("Response cookie '" + name + "' secure", secure, cookie.getSecure());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -204,9 +198,16 @@ public class CookieResultMatchers {
|
||||||
*/
|
*/
|
||||||
public ResultMatcher httpOnly(final String name, final boolean httpOnly) {
|
public ResultMatcher httpOnly(final String name, final boolean httpOnly) {
|
||||||
return result -> {
|
return result -> {
|
||||||
Cookie cookie = result.getResponse().getCookie(name);
|
Cookie cookie = getCookie(result, name);
|
||||||
assertEquals("Response cookie '" + name + "' httpOnly", httpOnly, cookie.isHttpOnly());
|
assertEquals("Response cookie '" + name + "' httpOnly", httpOnly, cookie.isHttpOnly());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static Cookie getCookie(MvcResult result, String name) {
|
||||||
|
Cookie cookie = result.getResponse().getCookie(name);
|
||||||
|
assertTrue("No cookie with name '" + name + "'", cookie != null);
|
||||||
|
return cookie;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,6 @@ public class HandlerResultMatchers {
|
||||||
* mockMvc.perform(get("/"))
|
* mockMvc.perform(get("/"))
|
||||||
* .andExpect(handler().methodCall(on(SimpleController.class).handle()));
|
* .andExpect(handler().methodCall(on(SimpleController.class).handle()));
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
|
||||||
* @param obj either the value returned from a "mock" controller invocation
|
* @param obj either the value returned from a "mock" controller invocation
|
||||||
* or the "mock" controller itself after an invocation
|
* or the "mock" controller itself after an invocation
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -66,12 +66,12 @@ public class MultipartHttpMessageWriter implements HttpMessageWriter<MultiValueM
|
||||||
public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
|
public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
|
||||||
|
|
||||||
|
|
||||||
|
private final DataBufferFactory bufferFactory = new DefaultDataBufferFactory();
|
||||||
|
|
||||||
private final List<HttpMessageWriter<?>> partWriters;
|
private final List<HttpMessageWriter<?>> partWriters;
|
||||||
|
|
||||||
private Charset charset = DEFAULT_CHARSET;
|
private Charset charset = DEFAULT_CHARSET;
|
||||||
|
|
||||||
private final DataBufferFactory bufferFactory = new DefaultDataBufferFactory();
|
|
||||||
|
|
||||||
|
|
||||||
public MultipartHttpMessageWriter() {
|
public MultipartHttpMessageWriter() {
|
||||||
this.partWriters = Arrays.asList(
|
this.partWriters = Arrays.asList(
|
||||||
|
|
@ -84,13 +84,14 @@ public class MultipartHttpMessageWriter implements HttpMessageWriter<MultiValueM
|
||||||
this.partWriters = partWriters;
|
this.partWriters = partWriters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the character set to use for part headers such as
|
* Set the character set to use for part headers such as
|
||||||
* "Content-Disposition" (and its filename parameter).
|
* "Content-Disposition" (and its filename parameter).
|
||||||
* <p>By default this is set to "UTF-8".
|
* <p>By default this is set to "UTF-8".
|
||||||
*/
|
*/
|
||||||
public void setCharset(Charset charset) {
|
public void setCharset(Charset charset) {
|
||||||
Assert.notNull(charset, "'charset' must not be null");
|
Assert.notNull(charset, "Charset must not be null");
|
||||||
this.charset = charset;
|
this.charset = charset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -126,11 +127,9 @@ public class MultipartHttpMessageWriter implements HttpMessageWriter<MultiValueM
|
||||||
outputMessage.getHeaders().setContentType(new MediaType(MediaType.MULTIPART_FORM_DATA, params));
|
outputMessage.getHeaders().setContentType(new MediaType(MediaType.MULTIPART_FORM_DATA, params));
|
||||||
|
|
||||||
return Mono.from(inputStream).flatMap(map -> {
|
return Mono.from(inputStream).flatMap(map -> {
|
||||||
|
|
||||||
Flux<DataBuffer> body = Flux.fromIterable(map.entrySet())
|
Flux<DataBuffer> body = Flux.fromIterable(map.entrySet())
|
||||||
.concatMap(entry -> encodePartValues(boundary, entry.getKey(), entry.getValue()))
|
.concatMap(entry -> encodePartValues(boundary, entry.getKey(), entry.getValue()))
|
||||||
.concatWith(Mono.just(generateLastLine(boundary)));
|
.concatWith(Mono.just(generateLastLine(boundary)));
|
||||||
|
|
||||||
return outputMessage.writeWith(body);
|
return outputMessage.writeWith(body);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -150,9 +149,7 @@ public class MultipartHttpMessageWriter implements HttpMessageWriter<MultiValueM
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private <T> Flux<DataBuffer> encodePart(byte[] boundary, String name, T value) {
|
private <T> Flux<DataBuffer> encodePart(byte[] boundary, String name, T value) {
|
||||||
|
MultipartHttpOutputMessage outputMessage = new MultipartHttpOutputMessage(this.bufferFactory, getCharset());
|
||||||
MultipartHttpOutputMessage outputMessage =
|
|
||||||
new MultipartHttpOutputMessage(this.bufferFactory, getCharset());
|
|
||||||
|
|
||||||
T body;
|
T body;
|
||||||
if (value instanceof HttpEntity) {
|
if (value instanceof HttpEntity) {
|
||||||
|
|
@ -173,7 +170,7 @@ public class MultipartHttpMessageWriter implements HttpMessageWriter<MultiValueM
|
||||||
.filter(partWriter -> partWriter.canWrite(bodyType, contentType))
|
.filter(partWriter -> partWriter.canWrite(bodyType, contentType))
|
||||||
.findFirst();
|
.findFirst();
|
||||||
|
|
||||||
if(!writer.isPresent()) {
|
if (!writer.isPresent()) {
|
||||||
return Flux.error(new CodecException("No suitable writer found for part: " + name));
|
return Flux.error(new CodecException("No suitable writer found for part: " + name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -182,17 +179,14 @@ public class MultipartHttpMessageWriter implements HttpMessageWriter<MultiValueM
|
||||||
|
|
||||||
// partWritten.subscribe() is required in order to make sure MultipartHttpOutputMessage#getBody()
|
// partWritten.subscribe() is required in order to make sure MultipartHttpOutputMessage#getBody()
|
||||||
// returns a non-null value (occurs with ResourceHttpMessageWriter that invokes
|
// returns a non-null value (occurs with ResourceHttpMessageWriter that invokes
|
||||||
// ReactiveHttpOutputMessage.writeWith() only when at least one element has been
|
// ReactiveHttpOutputMessage.writeWith() only when at least one element has been requested).
|
||||||
// requested).
|
|
||||||
partWritten.subscribe();
|
partWritten.subscribe();
|
||||||
|
|
||||||
return Flux.concat(
|
return Flux.concat(
|
||||||
Mono.just(generateBoundaryLine(boundary)),
|
Mono.just(generateBoundaryLine(boundary)), outputMessage.getBody(), Mono.just(generateNewLine()));
|
||||||
outputMessage.getBody(),
|
|
||||||
Mono.just(generateNewLine())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private DataBuffer generateBoundaryLine(byte[] boundary) {
|
private DataBuffer generateBoundaryLine(byte[] boundary) {
|
||||||
DataBuffer buffer = this.bufferFactory.allocateBuffer(boundary.length + 4);
|
DataBuffer buffer = this.bufferFactory.allocateBuffer(boundary.length + 4);
|
||||||
buffer.write((byte)'-');
|
buffer.write((byte)'-');
|
||||||
|
|
@ -231,17 +225,15 @@ public class MultipartHttpMessageWriter implements HttpMessageWriter<MultiValueM
|
||||||
|
|
||||||
private final HttpHeaders headers = new HttpHeaders();
|
private final HttpHeaders headers = new HttpHeaders();
|
||||||
|
|
||||||
private final AtomicBoolean commited = new AtomicBoolean();
|
private final AtomicBoolean committed = new AtomicBoolean();
|
||||||
|
|
||||||
private Flux<DataBuffer> body;
|
private Flux<DataBuffer> body;
|
||||||
|
|
||||||
|
|
||||||
public MultipartHttpOutputMessage(DataBufferFactory bufferFactory, Charset charset) {
|
public MultipartHttpOutputMessage(DataBufferFactory bufferFactory, Charset charset) {
|
||||||
this.bufferFactory = bufferFactory;
|
this.bufferFactory = bufferFactory;
|
||||||
this.charset = charset;
|
this.charset = charset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HttpHeaders getHeaders() {
|
public HttpHeaders getHeaders() {
|
||||||
return (this.body != null ? HttpHeaders.readOnlyHttpHeaders(this.headers) : this.headers);
|
return (this.body != null ? HttpHeaders.readOnlyHttpHeaders(this.headers) : this.headers);
|
||||||
|
|
@ -254,12 +246,12 @@ public class MultipartHttpMessageWriter implements HttpMessageWriter<MultiValueM
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeCommit(Supplier<? extends Mono<Void>> action) {
|
public void beforeCommit(Supplier<? extends Mono<Void>> action) {
|
||||||
this.commited.set(true);
|
this.committed.set(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCommitted() {
|
public boolean isCommitted() {
|
||||||
return this.commited.get();
|
return this.committed.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -305,7 +297,6 @@ public class MultipartHttpMessageWriter implements HttpMessageWriter<MultiValueM
|
||||||
return (this.body != null ? this.body.then() :
|
return (this.body != null ? this.body.then() :
|
||||||
Mono.error(new IllegalStateException("Body has not been written yet")));
|
Mono.error(new IllegalStateException("Body has not been written yet")));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue