Polishing
This commit is contained in:
parent
b709c77329
commit
7f19e57d9d
|
@ -180,12 +180,11 @@ public class FormHttpMessageConverter implements HttpMessageConverter<MultiValue
|
|||
* names. Encoding is based on the encoded-word syntax defined in RFC 2047
|
||||
* and relies on {@code MimeUtility} from "javax.mail".
|
||||
* <p>If not set file names will be encoded as US-ASCII.
|
||||
* @param multipartCharset the charset to use
|
||||
* @since 4.1.1
|
||||
* @see <a href="http://en.wikipedia.org/wiki/MIME#Encoded-Word">Encoded-Word</a>
|
||||
*/
|
||||
public void setMultipartCharset(Charset multipartCharset) {
|
||||
this.multipartCharset = multipartCharset;
|
||||
public void setMultipartCharset(Charset charset) {
|
||||
this.multipartCharset = charset;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -115,37 +115,16 @@ public class ServletHttpHandlerAdapter implements Servlet {
|
|||
this.httpHandler.handle(httpRequest, httpResponse).subscribe(subscriber);
|
||||
}
|
||||
|
||||
protected ServerHttpRequest createRequest(HttpServletRequest request,
|
||||
AsyncContext context) throws IOException {
|
||||
|
||||
protected ServerHttpRequest createRequest(HttpServletRequest request, AsyncContext context) throws IOException {
|
||||
return new ServletServerHttpRequest(
|
||||
request, context, getDataBufferFactory(), getBufferSize());
|
||||
}
|
||||
|
||||
protected ServerHttpResponse createResponse(HttpServletResponse response,
|
||||
AsyncContext context) throws IOException {
|
||||
|
||||
protected ServerHttpResponse createResponse(HttpServletResponse response, AsyncContext context) throws IOException {
|
||||
return new ServletServerHttpResponse(
|
||||
response, context, getDataBufferFactory(), getBufferSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* We cannot combine ERROR_LISTENER and HandlerResultSubscriber due to:
|
||||
* https://issues.jboss.org/browse/WFLY-8515
|
||||
*/
|
||||
private static void runIfAsyncNotComplete(AsyncContext asyncContext, Runnable task) {
|
||||
try {
|
||||
if (asyncContext.getRequest().isAsyncStarted()) {
|
||||
task.run();
|
||||
}
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
// Ignore:
|
||||
// AsyncContext recycled and should not be used
|
||||
// e.g. TIMEOUT_LISTENER (above) may have completed the AsyncContext
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Other Servlet methods...
|
||||
|
||||
|
@ -168,6 +147,23 @@ public class ServletHttpHandlerAdapter implements Servlet {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* We cannot combine ERROR_LISTENER and HandlerResultSubscriber due to:
|
||||
* https://issues.jboss.org/browse/WFLY-8515
|
||||
*/
|
||||
private static void runIfAsyncNotComplete(AsyncContext asyncContext, Runnable task) {
|
||||
try {
|
||||
if (asyncContext.getRequest().isAsyncStarted()) {
|
||||
task.run();
|
||||
}
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
// Ignore: AsyncContext recycled and should not be used
|
||||
// e.g. TIMEOUT_LISTENER (above) may have completed the AsyncContext
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private final static AsyncListener ERROR_LISTENER = new AsyncListener() {
|
||||
|
||||
@Override
|
||||
|
@ -193,16 +189,15 @@ public class ServletHttpHandlerAdapter implements Servlet {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
private class HandlerResultSubscriber implements Subscriber<Void> {
|
||||
|
||||
private final AsyncContext asyncContext;
|
||||
|
||||
|
||||
HandlerResultSubscriber(AsyncContext asyncContext) {
|
||||
this.asyncContext = asyncContext;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onSubscribe(Subscription subscription) {
|
||||
subscription.request(Long.MAX_VALUE);
|
||||
|
|
|
@ -21,13 +21,7 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.springframework.core.ResolvableType.forClassWithGenerics;
|
||||
import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
|
@ -45,29 +39,34 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse
|
|||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
public class MultipartHttpMessageWriterTests {
|
||||
|
||||
private final MultipartHttpMessageWriter writer = new MultipartHttpMessageWriter(
|
||||
Arrays.asList(
|
||||
new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly()),
|
||||
new ResourceHttpMessageWriter(),
|
||||
new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder())
|
||||
private final MultipartHttpMessageWriter writer = new MultipartHttpMessageWriter(Arrays.asList(
|
||||
new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly()),
|
||||
new ResourceHttpMessageWriter(),
|
||||
new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder())
|
||||
));
|
||||
|
||||
|
||||
@Test
|
||||
public void canWrite() {
|
||||
|
||||
assertTrue(this.writer.canWrite(forClassWithGenerics(MultiValueMap.class, String.class, Object.class),
|
||||
assertTrue(this.writer.canWrite(
|
||||
ResolvableType.forClassWithGenerics(MultiValueMap.class, String.class, Object.class),
|
||||
MediaType.MULTIPART_FORM_DATA));
|
||||
assertTrue(this.writer.canWrite(forClassWithGenerics(MultiValueMap.class, String.class, String.class),
|
||||
assertTrue(this.writer.canWrite(
|
||||
ResolvableType.forClassWithGenerics(MultiValueMap.class, String.class, String.class),
|
||||
MediaType.MULTIPART_FORM_DATA));
|
||||
|
||||
assertFalse(this.writer.canWrite(forClassWithGenerics(Map.class, String.class, Object.class),
|
||||
assertFalse(this.writer.canWrite(
|
||||
ResolvableType.forClassWithGenerics(Map.class, String.class, Object.class),
|
||||
MediaType.MULTIPART_FORM_DATA));
|
||||
assertFalse(this.writer.canWrite(forClassWithGenerics(MultiValueMap.class, String.class, Object.class),
|
||||
assertFalse(this.writer.canWrite(
|
||||
ResolvableType.forClassWithGenerics(MultiValueMap.class, String.class, Object.class),
|
||||
MediaType.APPLICATION_FORM_URLENCODED));
|
||||
}
|
||||
|
||||
|
@ -105,14 +104,13 @@ public class MultipartHttpMessageWriterTests {
|
|||
// see if Synchronoss NIO Multipart can read what we wrote
|
||||
SynchronossMultipartHttpMessageReader reader = new SynchronossMultipartHttpMessageReader();
|
||||
MockServerHttpRequest request = MockServerHttpRequest.post("/foo")
|
||||
.header(CONTENT_TYPE, contentType.toString())
|
||||
.header(HttpHeaders.CONTENT_TYPE, contentType.toString())
|
||||
.body(response.getBody());
|
||||
|
||||
ResolvableType elementType = forClassWithGenerics(MultiValueMap.class, String.class, Part.class);
|
||||
ResolvableType elementType = ResolvableType.forClassWithGenerics(MultiValueMap.class, String.class, Part.class);
|
||||
MultiValueMap<String, Part> requestParts = reader.readMono(elementType, request, hints).block();
|
||||
assertEquals(5, requestParts.size());
|
||||
|
||||
|
||||
Part part = requestParts.getFirst("name 1");
|
||||
assertEquals("name 1", part.getName());
|
||||
assertEquals("value 1", part.getContentAsString().block());
|
||||
|
@ -147,6 +145,7 @@ public class MultipartHttpMessageWriterTests {
|
|||
assertEquals("{\"bar\":\"bar\"}", part.getContentAsString().block());
|
||||
}
|
||||
|
||||
|
||||
private class Foo {
|
||||
|
||||
private String bar;
|
||||
|
|
|
@ -75,11 +75,11 @@ import static org.springframework.http.MediaType.TEXT_PLAIN;
|
|||
|
||||
/**
|
||||
* Unit tests for {@link WebFluxConfigurationSupport}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class WebFluxConfigurationSupportTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void requestMappingHandlerMapping() throws Exception {
|
||||
ApplicationContext context = loadConfig(WebFluxConfig.class);
|
||||
|
|
Loading…
Reference in New Issue