Drop "get" prefix from Part accessor methods

This commit is contained in:
Rossen Stoyanchev 2017-05-04 09:27:59 -04:00
parent 4525c6a537
commit ac1db169a4
13 changed files with 73 additions and 73 deletions

View File

@ -29,10 +29,9 @@ import reactor.core.publisher.Mono;
public interface FilePart extends Part {
/**
* Return the name of the file selected by the user in a browser form.
* Return the original filename in the client's filesystem.
*/
String getFilename();
String filename();
/**
* Transfer the file in this part to the given file destination.

View File

@ -27,6 +27,6 @@ public interface FormFieldPart extends Part {
/**
* Return the form field value.
*/
String getValue();
String value();
}

View File

@ -85,7 +85,7 @@ public class MultipartHttpMessageReader implements HttpMessageReader<MultiValueM
ReactiveHttpInputMessage inputMessage, Map<String, Object> hints) {
return this.partReader.read(elementType, inputMessage, hints)
.collectMultimap(Part::getName).map(this::toMultiValueMap);
.collectMultimap(Part::name).map(this::toMultiValueMap);
}
private LinkedMultiValueMap<String, Part> toMultiValueMap(Map<String, Collection<Part>> map) {

View File

@ -43,16 +43,18 @@ public interface Part {
* Return the name of the part in the multipart form.
* @return the name of the part, never {@code null} or empty
*/
String getName();
String name();
/**
* Return the headers associated with the part.
*/
HttpHeaders getHeaders();
HttpHeaders headers();
/**
* Return the part raw content as a stream of DataBuffer's.
* Return the content for this part.
* <p>Note that for a {@link FormFieldPart} the content may be accessed
* more easily via {@link FormFieldPart#value()}.
*/
Flux<DataBuffer> getContent();
Flux<DataBuffer> content();
}

View File

@ -185,10 +185,14 @@ public class SynchronossPartHttpMessageReader implements HttpMessageReader<Part>
public void onPartFinished(StreamStorage storage, Map<String, List<String>> headers) {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.putAll(headers);
Part part = MultipartUtils.getFileName(httpHeaders) != null ?
new SynchronossFilePart(httpHeaders, storage, this.bufferFactory) :
this.sink.next(createPart(httpHeaders, storage));
}
private Part createPart(HttpHeaders httpHeaders, StreamStorage storage) {
String fileName = MultipartUtils.getFileName(httpHeaders);
return fileName != null ?
new SynchronossFilePart(httpHeaders, storage, fileName, this.bufferFactory) :
new DefaultSynchronossPart(httpHeaders, storage, this.bufferFactory);
this.sink.next(part);
}
@Override
@ -238,12 +242,12 @@ public class SynchronossPartHttpMessageReader implements HttpMessageReader<Part>
@Override
public String getName() {
public String name() {
return MultipartUtils.getFieldName(this.headers);
}
@Override
public HttpHeaders getHeaders() {
public HttpHeaders headers() {
return this.headers;
}
@ -265,7 +269,7 @@ public class SynchronossPartHttpMessageReader implements HttpMessageReader<Part>
@Override
public Flux<DataBuffer> getContent() {
public Flux<DataBuffer> content() {
InputStream inputStream = this.storage.getInputStream();
return DataBufferUtils.read(inputStream, getBufferFactory(), 4096);
}
@ -278,14 +282,14 @@ public class SynchronossPartHttpMessageReader implements HttpMessageReader<Part>
private static class SynchronossFilePart extends DefaultSynchronossPart implements FilePart {
public SynchronossFilePart(HttpHeaders headers, StreamStorage storage, DataBufferFactory factory) {
public SynchronossFilePart(HttpHeaders headers, StreamStorage storage, String fileName, DataBufferFactory factory) {
super(headers, storage, factory);
}
@Override
public String getFilename() {
return MultipartUtils.getFileName(getHeaders());
public String filename() {
return MultipartUtils.getFileName(headers());
}
@Override
@ -341,12 +345,12 @@ public class SynchronossPartHttpMessageReader implements HttpMessageReader<Part>
@Override
public String getValue() {
public String value() {
return this.content;
}
@Override
public Flux<DataBuffer> getContent() {
public Flux<DataBuffer> content() {
byte[] bytes = this.content.getBytes(getCharset());
DataBuffer buffer = getBufferFactory().allocateBuffer(bytes.length);
buffer.write(bytes);
@ -354,7 +358,7 @@ public class SynchronossPartHttpMessageReader implements HttpMessageReader<Part>
}
private Charset getCharset() {
return Optional.ofNullable(MultipartUtils.getCharEncoding(getHeaders()))
return Optional.ofNullable(MultipartUtils.getCharEncoding(headers()))
.map(Charset::forName).orElse(StandardCharsets.UTF_8);
}
}

View File

@ -108,7 +108,7 @@ public class WebExchangeDataBinder extends WebDataBinder {
private static void addBindValue(Map<String, Object> params, String key, List<?> values) {
if (!CollectionUtils.isEmpty(values)) {
values = values.stream()
.map(value -> value instanceof FormFieldPart ? ((FormFieldPart) value).getValue() : value)
.map(value -> value instanceof FormFieldPart ? ((FormFieldPart) value).value() : value)
.collect(Collectors.toList());
params.put(key, values.size() == 1 ? values.get(0) : values);
}

View File

@ -118,38 +118,38 @@ public class MultipartHttpMessageWriterTests {
Part part = requestParts.getFirst("name 1");
assertTrue(part instanceof FormFieldPart);
assertEquals("name 1", part.getName());
assertEquals("value 1", ((FormFieldPart) part).getValue());
assertEquals("name 1", part.name());
assertEquals("value 1", ((FormFieldPart) part).value());
List<Part> parts2 = requestParts.get("name 2");
assertEquals(2, parts2.size());
part = parts2.get(0);
assertTrue(part instanceof FormFieldPart);
assertEquals("name 2", part.getName());
assertEquals("value 2+1", ((FormFieldPart) part).getValue());
assertEquals("name 2", part.name());
assertEquals("value 2+1", ((FormFieldPart) part).value());
part = parts2.get(1);
assertTrue(part instanceof FormFieldPart);
assertEquals("name 2", part.getName());
assertEquals("value 2+2", ((FormFieldPart) part).getValue());
assertEquals("name 2", part.name());
assertEquals("value 2+2", ((FormFieldPart) part).value());
part = requestParts.getFirst("logo");
assertTrue(part instanceof FilePart);
assertEquals("logo", part.getName());
assertEquals("logo.jpg", ((FilePart) part).getFilename());
assertEquals(MediaType.IMAGE_JPEG, part.getHeaders().getContentType());
assertEquals(logo.getFile().length(), part.getHeaders().getContentLength());
assertEquals("logo", part.name());
assertEquals("logo.jpg", ((FilePart) part).filename());
assertEquals(MediaType.IMAGE_JPEG, part.headers().getContentType());
assertEquals(logo.getFile().length(), part.headers().getContentLength());
part = requestParts.getFirst("utf8");
assertTrue(part instanceof FilePart);
assertEquals("utf8", part.getName());
assertEquals("Hall\u00F6le.jpg", ((FilePart) part).getFilename());
assertEquals(MediaType.IMAGE_JPEG, part.getHeaders().getContentType());
assertEquals(utf8.getFile().length(), part.getHeaders().getContentLength());
assertEquals("utf8", part.name());
assertEquals("Hall\u00F6le.jpg", ((FilePart) part).filename());
assertEquals(MediaType.IMAGE_JPEG, part.headers().getContentType());
assertEquals(utf8.getFile().length(), part.headers().getContentLength());
part = requestParts.getFirst("json");
assertEquals("json", part.getName());
assertEquals(MediaType.APPLICATION_JSON_UTF8, part.getHeaders().getContentType());
assertEquals("{\"bar\":\"bar\"}", ((FormFieldPart) part).getValue());
assertEquals("json", part.name());
assertEquals(MediaType.APPLICATION_JSON_UTF8, part.headers().getContentType());
assertEquals("{\"bar\":\"bar\"}", ((FormFieldPart) part).value());
}

View File

@ -88,9 +88,9 @@ public class SynchronossPartHttpMessageReaderTests {
assertTrue(parts.containsKey("fooPart"));
Part part = parts.getFirst("fooPart");
assertTrue(part instanceof FilePart);
assertEquals("fooPart", part.getName());
assertEquals("foo.txt", ((FilePart) part).getFilename());
DataBuffer buffer = part.getContent().reduce(DataBuffer::write).block();
assertEquals("fooPart", part.name());
assertEquals("foo.txt", ((FilePart) part).filename());
DataBuffer buffer = part.content().reduce(DataBuffer::write).block();
assertEquals(12, buffer.readableByteCount());
byte[] byteContent = new byte[12];
buffer.read(byteContent);
@ -99,8 +99,8 @@ public class SynchronossPartHttpMessageReaderTests {
assertTrue(parts.containsKey("barPart"));
part = parts.getFirst("barPart");
assertTrue(part instanceof FormFieldPart);
assertEquals("barPart", part.getName());
assertEquals("bar", ((FormFieldPart) part).getValue());
assertEquals("barPart", part.name());
assertEquals("bar", ((FormFieldPart) part).value());
}
@Test

View File

@ -17,7 +17,6 @@
package org.springframework.http.server.reactive;
import java.net.URI;
import java.util.Optional;
import org.junit.Test;
import reactor.core.publisher.Mono;
@ -100,11 +99,11 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
}
private void assertFooPart(Part part) {
assertEquals("fooPart", part.getName());
assertEquals("fooPart", part.name());
assertTrue(part instanceof FilePart);
assertEquals("foo.txt", ((FilePart) part).getFilename());
assertEquals("foo.txt", ((FilePart) part).filename());
DataBuffer buffer = part
.getContent()
.content()
.reduce(DataBuffer::write)
.block();
assertEquals(12, buffer.readableByteCount());
@ -114,9 +113,9 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
}
private void assertBarPart(Part part) {
assertEquals("barPart", part.getName());
assertEquals("barPart", part.name());
assertTrue(part instanceof FormFieldPart);
assertEquals("bar", ((FormFieldPart) part).getValue());
assertEquals("bar", ((FormFieldPart) part).value());
}
}

View File

@ -207,10 +207,10 @@ public class WebExchangeDataBinderTests {
assertEquals("bar", bean.getName());
assertEquals(Arrays.asList("123", "abc"), bean.getSomeList());
assertArrayEquals(new String[] {"dec", "456"}, bean.getSomeArray());
assertEquals("foo.txt", bean.getPart().getFilename());
assertEquals("foo.txt", bean.getPart().filename());
assertEquals(2, bean.getSomePartList().size());
assertEquals("foo.txt", bean.getSomePartList().get(0).getFilename());
assertEquals("spring.png", bean.getSomePartList().get(1).getFilename());
assertEquals("foo.txt", bean.getSomePartList().get(0).filename());
assertEquals("spring.png", bean.getSomePartList().get(1).filename());
}

View File

@ -36,8 +36,6 @@ import reactor.test.StepVerifier;
import org.springframework.core.codec.ByteBufferDecoder;
import org.springframework.core.codec.StringDecoder;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DefaultDataBuffer;
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
@ -56,7 +54,6 @@ import org.springframework.http.codec.xml.Jaxb2XmlDecoder;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.util.FileCopyUtils;
import org.springframework.util.MultiValueMap;
import static org.junit.Assert.*;
@ -297,24 +294,24 @@ public class BodyExtractorsTests {
StepVerifier.create(result)
.consumeNextWith(part -> {
assertEquals("text", part.getName());
assertEquals("text", part.name());
assertTrue(part instanceof FormFieldPart);
FormFieldPart formFieldPart = (FormFieldPart) part;
assertEquals("text default", formFieldPart.getValue());
assertEquals("text default", formFieldPart.value());
})
.consumeNextWith(part -> {
assertEquals("file1", part.getName());
assertEquals("file1", part.name());
assertTrue(part instanceof FilePart);
FilePart filePart = (FilePart) part;
assertEquals("a.txt", filePart.getFilename());
assertEquals(MediaType.TEXT_PLAIN, filePart.getHeaders().getContentType());
assertEquals("a.txt", filePart.filename());
assertEquals(MediaType.TEXT_PLAIN, filePart.headers().getContentType());
})
.consumeNextWith(part -> {
assertEquals("file2", part.getName());
assertEquals("file2", part.name());
assertTrue(part instanceof FilePart);
FilePart filePart = (FilePart) part;
assertEquals("a.html", filePart.getFilename());
assertEquals(MediaType.TEXT_HTML, filePart.getHeaders().getContentType());
assertEquals("a.html", filePart.filename());
assertEquals(MediaType.TEXT_HTML, filePart.headers().getContentType());
})
.expectComplete()
.verify();

View File

@ -16,7 +16,6 @@
package org.springframework.web.reactive.function;
import java.util.List;
import java.util.Map;
import org.junit.Test;
@ -106,8 +105,8 @@ public class MultipartIntegrationTests extends AbstractRouterFunctionIntegration
Map<String, Part> parts = map.toSingleValueMap();
try {
assertEquals(2, parts.size());
assertEquals("foo.txt", ((FilePart) parts.get("fooPart")).getFilename());
assertEquals("bar", ((FormFieldPart) parts.get("barPart")).getValue());
assertEquals("foo.txt", ((FilePart) parts.get("fooPart")).filename());
assertEquals("bar", ((FormFieldPart) parts.get("barPart")).value());
}
catch(Exception e) {
return Mono.error(e);
@ -121,8 +120,8 @@ public class MultipartIntegrationTests extends AbstractRouterFunctionIntegration
.flatMap(parts -> {
try {
assertEquals(2, parts.size());
assertEquals("foo.txt", ((FilePart) parts.get(0)).getFilename());
assertEquals("bar", ((FormFieldPart) parts.get(1)).getValue());
assertEquals("foo.txt", ((FilePart) parts.get(0)).filename());
assertEquals("bar", ((FormFieldPart) parts.get(1)).value());
}
catch(Exception e) {
return Mono.error(e);

View File

@ -155,8 +155,8 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
@PostMapping("/requestPart")
void requestPart(@RequestPart FormFieldPart barPart, @RequestPart Mono<FilePart> fooPart) {
assertEquals("bar", barPart.getValue());
assertEquals("foo.txt", fooPart.block(Duration.ZERO).getFilename());
assertEquals("bar", barPart.value());
assertEquals("foo.txt", fooPart.block(Duration.ZERO).filename());
}
@PostMapping("/requestBodyMap")
@ -167,7 +167,7 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
@PostMapping("/requestBodyFlux")
Mono<String> requestBodyFlux(@RequestBody Flux<Part> parts) {
return parts.map(Part::getName).collectList()
return parts.map(Part::name).collectList()
.map(names -> names.stream().sorted().collect(Collectors.joining(",", "Flux[", "]")));
}
@ -202,7 +202,7 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
@Override
public String toString() {
return "TestBean[barPart=" + getBarPart() + ",fooPart=" + getFooPart().getFilename() + "]";
return "TestBean[barPart=" + getBarPart() + ",fooPart=" + getFooPart().filename() + "]";
}
}