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
|
* names. Encoding is based on the encoded-word syntax defined in RFC 2047
|
||||||
* and relies on {@code MimeUtility} from "javax.mail".
|
* and relies on {@code MimeUtility} from "javax.mail".
|
||||||
* <p>If not set file names will be encoded as US-ASCII.
|
* <p>If not set file names will be encoded as US-ASCII.
|
||||||
* @param multipartCharset the charset to use
|
|
||||||
* @since 4.1.1
|
* @since 4.1.1
|
||||||
* @see <a href="http://en.wikipedia.org/wiki/MIME#Encoded-Word">Encoded-Word</a>
|
* @see <a href="http://en.wikipedia.org/wiki/MIME#Encoded-Word">Encoded-Word</a>
|
||||||
*/
|
*/
|
||||||
public void setMultipartCharset(Charset multipartCharset) {
|
public void setMultipartCharset(Charset charset) {
|
||||||
this.multipartCharset = multipartCharset;
|
this.multipartCharset = charset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -115,37 +115,16 @@ public class ServletHttpHandlerAdapter implements Servlet {
|
||||||
this.httpHandler.handle(httpRequest, httpResponse).subscribe(subscriber);
|
this.httpHandler.handle(httpRequest, httpResponse).subscribe(subscriber);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ServerHttpRequest createRequest(HttpServletRequest request,
|
protected ServerHttpRequest createRequest(HttpServletRequest request, AsyncContext context) throws IOException {
|
||||||
AsyncContext context) throws IOException {
|
|
||||||
|
|
||||||
return new ServletServerHttpRequest(
|
return new ServletServerHttpRequest(
|
||||||
request, context, getDataBufferFactory(), getBufferSize());
|
request, context, getDataBufferFactory(), getBufferSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ServerHttpResponse createResponse(HttpServletResponse response,
|
protected ServerHttpResponse createResponse(HttpServletResponse response, AsyncContext context) throws IOException {
|
||||||
AsyncContext context) throws IOException {
|
|
||||||
|
|
||||||
return new ServletServerHttpResponse(
|
return new ServletServerHttpResponse(
|
||||||
response, context, getDataBufferFactory(), getBufferSize());
|
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...
|
// 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() {
|
private final static AsyncListener ERROR_LISTENER = new AsyncListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -193,16 +189,15 @@ public class ServletHttpHandlerAdapter implements Servlet {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
private class HandlerResultSubscriber implements Subscriber<Void> {
|
private class HandlerResultSubscriber implements Subscriber<Void> {
|
||||||
|
|
||||||
private final AsyncContext asyncContext;
|
private final AsyncContext asyncContext;
|
||||||
|
|
||||||
|
|
||||||
HandlerResultSubscriber(AsyncContext asyncContext) {
|
HandlerResultSubscriber(AsyncContext asyncContext) {
|
||||||
this.asyncContext = asyncContext;
|
this.asyncContext = asyncContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSubscribe(Subscription subscription) {
|
public void onSubscribe(Subscription subscription) {
|
||||||
subscription.request(Long.MAX_VALUE);
|
subscription.request(Long.MAX_VALUE);
|
||||||
|
|
|
@ -21,13 +21,7 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
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 org.junit.Test;
|
||||||
|
|
||||||
import static org.springframework.core.ResolvableType.forClassWithGenerics;
|
|
||||||
import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
|
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
import org.springframework.core.ResolvableType;
|
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.LinkedMultiValueMap;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Sebastien Deleuze
|
* @author Sebastien Deleuze
|
||||||
*/
|
*/
|
||||||
public class MultipartHttpMessageWriterTests {
|
public class MultipartHttpMessageWriterTests {
|
||||||
|
|
||||||
private final MultipartHttpMessageWriter writer = new MultipartHttpMessageWriter(
|
private final MultipartHttpMessageWriter writer = new MultipartHttpMessageWriter(Arrays.asList(
|
||||||
Arrays.asList(
|
new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly()),
|
||||||
new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly()),
|
new ResourceHttpMessageWriter(),
|
||||||
new ResourceHttpMessageWriter(),
|
new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder())
|
||||||
new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder())
|
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canWrite() {
|
public void canWrite() {
|
||||||
|
assertTrue(this.writer.canWrite(
|
||||||
assertTrue(this.writer.canWrite(forClassWithGenerics(MultiValueMap.class, String.class, Object.class),
|
ResolvableType.forClassWithGenerics(MultiValueMap.class, String.class, Object.class),
|
||||||
MediaType.MULTIPART_FORM_DATA));
|
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));
|
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));
|
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));
|
MediaType.APPLICATION_FORM_URLENCODED));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,14 +104,13 @@ public class MultipartHttpMessageWriterTests {
|
||||||
// see if Synchronoss NIO Multipart can read what we wrote
|
// see if Synchronoss NIO Multipart can read what we wrote
|
||||||
SynchronossMultipartHttpMessageReader reader = new SynchronossMultipartHttpMessageReader();
|
SynchronossMultipartHttpMessageReader reader = new SynchronossMultipartHttpMessageReader();
|
||||||
MockServerHttpRequest request = MockServerHttpRequest.post("/foo")
|
MockServerHttpRequest request = MockServerHttpRequest.post("/foo")
|
||||||
.header(CONTENT_TYPE, contentType.toString())
|
.header(HttpHeaders.CONTENT_TYPE, contentType.toString())
|
||||||
.body(response.getBody());
|
.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();
|
MultiValueMap<String, Part> requestParts = reader.readMono(elementType, request, hints).block();
|
||||||
assertEquals(5, requestParts.size());
|
assertEquals(5, requestParts.size());
|
||||||
|
|
||||||
|
|
||||||
Part part = requestParts.getFirst("name 1");
|
Part part = requestParts.getFirst("name 1");
|
||||||
assertEquals("name 1", part.getName());
|
assertEquals("name 1", part.getName());
|
||||||
assertEquals("value 1", part.getContentAsString().block());
|
assertEquals("value 1", part.getContentAsString().block());
|
||||||
|
@ -147,6 +145,7 @@ public class MultipartHttpMessageWriterTests {
|
||||||
assertEquals("{\"bar\":\"bar\"}", part.getContentAsString().block());
|
assertEquals("{\"bar\":\"bar\"}", part.getContentAsString().block());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private class Foo {
|
private class Foo {
|
||||||
|
|
||||||
private String bar;
|
private String bar;
|
||||||
|
|
|
@ -75,11 +75,11 @@ import static org.springframework.http.MediaType.TEXT_PLAIN;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link WebFluxConfigurationSupport}.
|
* Unit tests for {@link WebFluxConfigurationSupport}.
|
||||||
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class WebFluxConfigurationSupportTests {
|
public class WebFluxConfigurationSupportTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestMappingHandlerMapping() throws Exception {
|
public void requestMappingHandlerMapping() throws Exception {
|
||||||
ApplicationContext context = loadConfig(WebFluxConfig.class);
|
ApplicationContext context = loadConfig(WebFluxConfig.class);
|
||||||
|
|
Loading…
Reference in New Issue