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