Polishing

(cherry picked from commit 40efcc9)
This commit is contained in:
Juergen Hoeller
2018-06-28 14:51:31 +02:00
parent 3e64388b20
commit a631af80c1
113 changed files with 648 additions and 693 deletions

View File

@@ -101,9 +101,9 @@ public final class MultipartBodyBuilder {
HttpHeaders partHeaders = new HttpHeaders();
if (part instanceof HttpEntity) {
HttpEntity<?> other = (HttpEntity<?>) part;
partBody = other.getBody();
partHeaders.addAll(other.getHeaders());
HttpEntity<?> httpEntity = (HttpEntity<?>) part;
partBody = httpEntity.getBody();
partHeaders.addAll(httpEntity.getHeaders());
}
else {
partBody = part;

View File

@@ -18,6 +18,7 @@ package org.springframework.http.codec;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -48,8 +49,6 @@ import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.lang.Nullable;
import org.springframework.util.MimeTypeUtils;
import static java.util.Collections.*;
/**
* {@code HttpMessageWriter} that can write a {@link Resource}.
*
@@ -232,7 +231,7 @@ public class ResourceHttpMessageWriter implements HttpMessageWriter<Resource> {
.orElseGet(() -> {
Publisher<? extends ResourceRegion> input = Mono.just(region);
MediaType mediaType = message.getHeaders().getContentType();
return encodeAndWriteRegions(input, mediaType, message, emptyMap());
return encodeAndWriteRegions(input, mediaType, message, Collections.emptyMap());
});
}

View File

@@ -90,19 +90,14 @@ public class SynchronossPartHttpMessageReader implements HttpMessageReader<Part>
@Override
public Flux<Part> read(ResolvableType elementType, ReactiveHttpInputMessage message,
Map<String, Object> hints) {
public Flux<Part> read(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) {
return Flux.create(new SynchronossPartGenerator(message, this.bufferFactory, this.streamStorageFactory));
}
@Override
public Mono<Part> readMono(ResolvableType elementType, ReactiveHttpInputMessage message,
Map<String, Object> hints) {
return Mono.error(new UnsupportedOperationException(
"Can't read a multipart request body into a single Part."));
public Mono<Part> readMono(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) {
return Mono.error(new UnsupportedOperationException("Cannot read multipart request body into single Part"));
}
@@ -115,18 +110,17 @@ public class SynchronossPartHttpMessageReader implements HttpMessageReader<Part>
private final ReactiveHttpInputMessage inputMessage;
private final DataBufferFactory bufferFactory;
private final PartBodyStreamStorageFactory streamStorageFactory;
private final PartBodyStreamStorageFactory streamStorageFactory;
SynchronossPartGenerator(ReactiveHttpInputMessage inputMessage, DataBufferFactory bufferFactory,
PartBodyStreamStorageFactory streamStorageFactory) {
this.inputMessage = inputMessage;
this.bufferFactory = bufferFactory;
this.streamStorageFactory = streamStorageFactory;
}
@Override
public void accept(FluxSink<Part> emitter) {
HttpHeaders headers = this.inputMessage.getHeaders();
@@ -140,7 +134,7 @@ public class SynchronossPartHttpMessageReader implements HttpMessageReader<Part>
NioMultipartParserListener listener = new FluxSinkAdapterListener(emitter, this.bufferFactory, context);
NioMultipartParser parser = Multipart
.multipart(context)
.usePartBodyStreamStorageFactory(streamStorageFactory)
.usePartBodyStreamStorageFactory(this.streamStorageFactory)
.forNIO(listener);
this.inputMessage.getBody().subscribe(buffer -> {
@@ -189,14 +183,12 @@ public class SynchronossPartHttpMessageReader implements HttpMessageReader<Part>
private final AtomicInteger terminated = new AtomicInteger(0);
FluxSinkAdapterListener(FluxSink<Part> sink, DataBufferFactory factory, MultipartContext context) {
this.sink = sink;
this.bufferFactory = factory;
this.context = context;
}
@Override
public void onPartFinished(StreamStorage storage, Map<String, List<String>> headers) {
HttpHeaders httpHeaders = new HttpHeaders();
@@ -250,16 +242,14 @@ public class SynchronossPartHttpMessageReader implements HttpMessageReader<Part>
private final DataBufferFactory bufferFactory;
AbstractSynchronossPart(HttpHeaders headers, DataBufferFactory bufferFactory) {
Assert.notNull(headers, "HttpHeaders is required");
Assert.notNull(bufferFactory, "'bufferFactory' is required");
Assert.notNull(bufferFactory, "DataBufferFactory is required");
this.name = MultipartUtils.getFieldName(headers);
this.headers = headers;
this.bufferFactory = bufferFactory;
}
@Override
public String name() {
return this.name;
@@ -280,14 +270,12 @@ public class SynchronossPartHttpMessageReader implements HttpMessageReader<Part>
private final StreamStorage storage;
SynchronossPart(HttpHeaders headers, StreamStorage storage, DataBufferFactory factory) {
super(headers, factory);
Assert.notNull(storage, "'storage' is required");
Assert.notNull(storage, "StreamStorage is required");
this.storage = storage;
}
@Override
public Flux<DataBuffer> content() {
return DataBufferUtils.readInputStream(getStorage()::getInputStream, getBufferFactory(), 4096);
@@ -301,21 +289,16 @@ public class SynchronossPartHttpMessageReader implements HttpMessageReader<Part>
private static class SynchronossFilePart extends SynchronossPart implements FilePart {
private static final OpenOption[] FILE_CHANNEL_OPTIONS = {
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE };
private static final OpenOption[] FILE_CHANNEL_OPTIONS =
{StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE};
private final String filename;
SynchronossFilePart(HttpHeaders headers, String filename, StreamStorage storage,
DataBufferFactory factory) {
SynchronossFilePart(HttpHeaders headers, String filename, StreamStorage storage, DataBufferFactory factory) {
super(headers, storage, factory);
this.filename = filename;
}
@Override
public String filename() {
return this.filename;
@@ -366,13 +349,11 @@ public class SynchronossPartHttpMessageReader implements HttpMessageReader<Part>
private final String content;
SynchronossFormFieldPart(HttpHeaders headers, DataBufferFactory bufferFactory, String content) {
super(headers, bufferFactory);
this.content = content;
}
@Override
public String value() {
return this.content;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@@ -132,10 +132,10 @@ class DefaultRequestPath implements RequestPath {
if (other == null || getClass() != other.getClass()) {
return false;
}
DefaultRequestPath that = (DefaultRequestPath) other;
return (this.fullPath.equals(that.fullPath) &&
this.contextPath.equals(that.contextPath) &&
this.pathWithinApplication.equals(that.pathWithinApplication));
DefaultRequestPath otherPath= (DefaultRequestPath) other;
return (this.fullPath.equals(otherPath.fullPath) &&
this.contextPath.equals(otherPath.contextPath) &&
this.pathWithinApplication.equals(otherPath.pathWithinApplication));
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@@ -63,6 +63,8 @@ import org.springframework.stereotype.Component;
* @author Brian Clozel
* @author Sam Brannen
* @since 3.2
* @see org.springframework.stereotype.Controller
* @see RestControllerAdvice
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 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,6 +41,8 @@ import org.springframework.core.annotation.AliasFor;
*
* @author Rossen Stoyanchev
* @since 4.3
* @see RestController
* @see ControllerAdvice
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)

View File

@@ -237,15 +237,15 @@ public class ServletContextResource extends AbstractFileResolvingResource implem
* This implementation compares the underlying ServletContext resource locations.
*/
@Override
public boolean equals(Object obj) {
if (obj == this) {
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (obj instanceof ServletContextResource) {
ServletContextResource otherRes = (ServletContextResource) obj;
return (this.servletContext.equals(otherRes.servletContext) && this.path.equals(otherRes.path));
if (!(other instanceof ServletContextResource)) {
return false;
}
return false;
ServletContextResource otherRes = (ServletContextResource) other;
return (this.servletContext.equals(otherRes.servletContext) && this.path.equals(otherRes.path));
}
/**

View File

@@ -43,13 +43,12 @@ import org.springframework.web.multipart.MultipartResolver;
*
* <pre class="code">
* public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
* // ...
* &#064;Override
* protected void customizeRegistration(ServletRegistration.Dynamic registration) {
*
* // Optionally also set maxFileSize, maxRequestSize, fileSizeThreshold
* registration.setMultipartConfig(new MultipartConfigElement("/tmp"));
* }
* // ...
* &#064;Override
* protected void customizeRegistration(ServletRegistration.Dynamic registration) {
* // Optionally also set maxFileSize, maxRequestSize, fileSizeThreshold
* registration.setMultipartConfig(new MultipartConfigElement("/tmp"));
* }
* }
* </pre>
*
@@ -84,8 +83,7 @@ public class StandardServletMultipartResolver implements MultipartResolver {
if (!"post".equalsIgnoreCase(request.getMethod())) {
return false;
}
String contentType = request.getContentType();
return StringUtils.startsWithIgnoreCase(contentType, "multipart/");
return StringUtils.startsWithIgnoreCase(request.getContentType(), "multipart/");
}
@Override

View File

@@ -54,6 +54,51 @@ final class HierarchicalUriComponents extends UriComponents {
private static final String PATH_DELIMITER_STRING = "/";
/**
* Represents an empty path.
*/
static final PathComponent NULL_PATH_COMPONENT = new PathComponent() {
@Override
public String getPath() {
return "";
}
@Override
public List<String> getPathSegments() {
return Collections.emptyList();
}
@Override
public PathComponent encode(Charset charset) {
return this;
}
@Override
public void verify() {
}
@Override
public PathComponent expand(UriTemplateVariables uriVariables) {
return this;
}
@Override
public void copyToUriComponentsBuilder(UriComponentsBuilder builder) {
}
@Override
public boolean equals(Object other) {
return (this == other);
}
@Override
public int hashCode() {
return getClass().hashCode();
}
};
@Nullable
private final String userInfo;
@@ -462,21 +507,21 @@ final class HierarchicalUriComponents extends UriComponents {
@Override
public boolean equals(Object obj) {
if (this == obj) {
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(obj instanceof HierarchicalUriComponents)) {
if (!(other instanceof HierarchicalUriComponents)) {
return false;
}
HierarchicalUriComponents other = (HierarchicalUriComponents) obj;
return ObjectUtils.nullSafeEquals(getScheme(), other.getScheme()) &&
ObjectUtils.nullSafeEquals(getUserInfo(), other.getUserInfo()) &&
ObjectUtils.nullSafeEquals(getHost(), other.getHost()) &&
getPort() == other.getPort() &&
this.path.equals(other.path) &&
this.queryParams.equals(other.queryParams) &&
ObjectUtils.nullSafeEquals(getFragment(), other.getFragment());
HierarchicalUriComponents otherComp = (HierarchicalUriComponents) other;
return (ObjectUtils.nullSafeEquals(getScheme(), otherComp.getScheme()) &&
ObjectUtils.nullSafeEquals(getUserInfo(), otherComp.getUserInfo()) &&
ObjectUtils.nullSafeEquals(getHost(), otherComp.getHost()) &&
getPort() == otherComp.getPort() &&
this.path.equals(otherComp.path) &&
this.queryParams.equals(otherComp.queryParams) &&
ObjectUtils.nullSafeEquals(getFragment(), otherComp.getFragment()));
}
@Override
@@ -708,9 +753,9 @@ final class HierarchicalUriComponents extends UriComponents {
}
@Override
public boolean equals(Object obj) {
return (this == obj || (obj instanceof FullPathComponent &&
getPath().equals(((FullPathComponent) obj).getPath())));
public boolean equals(Object other) {
return (this == other || (other instanceof FullPathComponent &&
getPath().equals(((FullPathComponent) other).getPath())));
}
@Override
@@ -786,9 +831,9 @@ final class HierarchicalUriComponents extends UriComponents {
}
@Override
public boolean equals(Object obj) {
return (this == obj || (obj instanceof PathSegmentComponent &&
getPathSegments().equals(((PathSegmentComponent) obj).getPathSegments())));
public boolean equals(Object other) {
return (this == other || (other instanceof PathSegmentComponent &&
getPathSegments().equals(((PathSegmentComponent) other).getPathSegments())));
}
@Override
@@ -862,43 +907,6 @@ final class HierarchicalUriComponents extends UriComponents {
}
/**
* Represents an empty path.
*/
static final PathComponent NULL_PATH_COMPONENT = new PathComponent() {
@Override
public String getPath() {
return "";
}
@Override
public List<String> getPathSegments() {
return Collections.emptyList();
}
@Override
public PathComponent encode(Charset charset) {
return this;
}
@Override
public void verify() {
}
@Override
public PathComponent expand(UriTemplateVariables uriVariables) {
return this;
}
@Override
public void copyToUriComponentsBuilder(UriComponentsBuilder builder) {
}
@Override
public boolean equals(Object obj) {
return (this == obj);
}
@Override
public int hashCode() {
return getClass().hashCode();
}
};
private static class QueryUriTemplateVariables implements UriTemplateVariables {
private final UriTemplateVariables delegate;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@@ -157,19 +157,17 @@ final class OpaqueUriComponents extends UriComponents {
@Override
public boolean equals(Object obj) {
if (this == obj) {
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(obj instanceof OpaqueUriComponents)) {
if (!(other instanceof OpaqueUriComponents)) {
return false;
}
OpaqueUriComponents other = (OpaqueUriComponents) obj;
return ObjectUtils.nullSafeEquals(getScheme(), other.getScheme()) &&
ObjectUtils.nullSafeEquals(this.ssp, other.ssp) &&
ObjectUtils.nullSafeEquals(getFragment(), other.getFragment());
OpaqueUriComponents otherComp = (OpaqueUriComponents) other;
return (ObjectUtils.nullSafeEquals(getScheme(), otherComp.getScheme()) &&
ObjectUtils.nullSafeEquals(this.ssp, otherComp.ssp) &&
ObjectUtils.nullSafeEquals(getFragment(), otherComp.getFragment()));
}
@Override

View File

@@ -209,17 +209,17 @@ public class ResolvableMethod {
}
private String formatMethod() {
return this.method().getName() +
return (this.method().getName() +
Arrays.stream(this.method.getParameters())
.map(this::formatParameter)
.collect(joining(",\n\t", "(\n\t", "\n)"));
.collect(joining(",\n\t", "(\n\t", "\n)")));
}
private String formatParameter(Parameter param) {
Annotation[] annot = param.getAnnotations();
return annot.length > 0 ?
Arrays.stream(annot).map(this::formatAnnotation).collect(joining(",", "[", "]")) + " " + param :
param.toString();
Annotation[] anns = param.getAnnotations();
return (anns.length > 0 ?
Arrays.stream(anns).map(this::formatAnnotation).collect(joining(",", "[", "]")) + " " + param :
param.toString());
}
private String formatAnnotation(Annotation annotation) {
@@ -536,9 +536,9 @@ public class ResolvableMethod {
@SafeVarargs
public final ArgResolver annotNotPresent(Class<? extends Annotation>... annotationTypes) {
this.filters.add(param ->
(annotationTypes.length != 0) ?
(annotationTypes.length > 0 ?
Arrays.stream(annotationTypes).noneMatch(param::hasParameterAnnotation) :
param.getParameterAnnotations().length == 0);
param.getParameterAnnotations().length == 0));
return this;
}