Polishing
This commit is contained in:
parent
110d9d7cd9
commit
d3e5d9dd03
|
@ -19,6 +19,7 @@ package org.springframework.reactive.codec.decoder;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBElement;
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
@ -34,8 +35,6 @@ import org.xml.sax.InputSource;
|
|||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
import reactor.io.buffer.Buffer;
|
||||
import reactor.rx.Stream;
|
||||
import reactor.rx.Streams;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
|
@ -55,7 +54,6 @@ public class Jaxb2Decoder implements ByteToMessageDecoder<Object> {
|
|||
|
||||
private final ConcurrentMap<Class<?>, JAXBContext> jaxbContexts = new ConcurrentHashMap<Class<?>, JAXBContext>(64);
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canDecode(ResolvableType type, MediaType mediaType, Object... hints) {
|
||||
return mediaType.isCompatibleWith(MediaType.APPLICATION_XML) || mediaType.isCompatibleWith(MediaType.TEXT_XML);
|
||||
|
@ -127,5 +125,4 @@ public class Jaxb2Decoder implements ByteToMessageDecoder<Object> {
|
|||
}
|
||||
return jaxbContext;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,7 +41,6 @@ public class JacksonJsonEncoder implements MessageToByteEncoder<Object> {
|
|||
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
|
||||
public JacksonJsonEncoder() {
|
||||
this(new ObjectMapper());
|
||||
}
|
||||
|
@ -50,7 +49,6 @@ public class JacksonJsonEncoder implements MessageToByteEncoder<Object> {
|
|||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canEncode(ResolvableType type, MediaType mediaType, Object... hints) {
|
||||
return mediaType.isCompatibleWith(MediaType.APPLICATION_JSON);
|
||||
|
@ -58,7 +56,7 @@ public class JacksonJsonEncoder implements MessageToByteEncoder<Object> {
|
|||
|
||||
@Override
|
||||
public Publisher<ByteBuffer> encode(Publisher<? extends Object> messageStream, ResolvableType type, MediaType mediaType, Object... hints) {
|
||||
Stream<ByteBuffer> stream = Streams.wrap(messageStream).map(value -> {
|
||||
Stream<ByteBuffer> stream = Streams.wrap(messageStream).map(value -> {
|
||||
Buffer buffer = new Buffer();
|
||||
BufferOutputStream outputStream = new BufferOutputStream(buffer);
|
||||
try {
|
||||
|
|
|
@ -20,6 +20,7 @@ import java.nio.ByteBuffer;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.MarshalException;
|
||||
|
@ -47,7 +48,6 @@ public class Jaxb2Encoder implements MessageToByteEncoder<Object> {
|
|||
|
||||
private final ConcurrentMap<Class<?>, JAXBContext> jaxbContexts = new ConcurrentHashMap<Class<?>, JAXBContext>(64);
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canEncode(ResolvableType type, MediaType mediaType, Object... hints) {
|
||||
return mediaType.isCompatibleWith(MediaType.APPLICATION_XML) || mediaType.isCompatibleWith(MediaType.TEXT_XML);
|
||||
|
@ -106,3 +106,4 @@ public class Jaxb2Encoder implements MessageToByteEncoder<Object> {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ package org.springframework.reactive.codec.encoder;
|
|||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.RxReactiveStreams;
|
||||
|
||||
|
@ -37,7 +36,9 @@ import org.springframework.reactive.codec.decoder.JsonObjectDecoder;
|
|||
public class JsonObjectEncoder implements MessageToByteEncoder<ByteBuffer> {
|
||||
|
||||
private final ByteBuffer START_ARRAY = ByteBuffer.wrap("[".getBytes());
|
||||
|
||||
private final ByteBuffer END_ARRAY = ByteBuffer.wrap("]".getBytes());
|
||||
|
||||
private final ByteBuffer COMMA = ByteBuffer.wrap(",".getBytes());
|
||||
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ import org.springframework.reactive.codec.encoder.MessageToByteEncoder;
|
|||
* Utility methods for dealing with codec hints.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @see Hints
|
||||
* @see MessageToByteEncoder
|
||||
* @see ByteToMessageDecoder
|
||||
*/
|
||||
|
@ -36,7 +35,7 @@ public abstract class HintUtils {
|
|||
public static <T> T getHintByClass(Class<T> clazz, Object[] hints, T defaultValue) {
|
||||
for (Object hint : hints) {
|
||||
if (hint.getClass().isAssignableFrom(clazz)) {
|
||||
return (T)hint;
|
||||
return (T) hint;
|
||||
}
|
||||
}
|
||||
return defaultValue;
|
||||
|
|
|
@ -22,24 +22,29 @@ import java.io.OutputStream;
|
|||
import reactor.io.buffer.Buffer;
|
||||
|
||||
/**
|
||||
* Simple extension of {@link OutputStream} that uses {@link Buffer} to stream
|
||||
* the content
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
public class BufferOutputStream extends OutputStream {
|
||||
|
||||
private Buffer buffer;
|
||||
private Buffer buffer;
|
||||
|
||||
public BufferOutputStream(Buffer buffer) {
|
||||
this.buffer = buffer;
|
||||
}
|
||||
this.buffer = buffer;
|
||||
}
|
||||
|
||||
public void write(int b) throws IOException {
|
||||
buffer.append(b);
|
||||
}
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
buffer.append(b);
|
||||
}
|
||||
|
||||
public void write(byte[] bytes, int off, int len)
|
||||
throws IOException {
|
||||
buffer.append(bytes, off, len);
|
||||
}
|
||||
@Override
|
||||
public void write(byte[] bytes, int off, int len)
|
||||
throws IOException {
|
||||
buffer.append(bytes, off, len);
|
||||
}
|
||||
|
||||
public Buffer getBuffer() {
|
||||
return buffer;
|
||||
|
|
|
@ -26,16 +26,23 @@ import java.nio.ByteBuffer;
|
|||
*
|
||||
* From Jackson <a href="https://github.com/FasterXML/jackson-databind/blob/master/src/main/java/com/fasterxml/jackson/databind/util/ByteBufferBackedInputStream.java">ByteBufferBackedInputStream</a>
|
||||
*/
|
||||
public class ByteBufferInputStream extends InputStream {
|
||||
public class ByteBufferInputStream extends InputStream {
|
||||
|
||||
protected final ByteBuffer b;
|
||||
|
||||
public ByteBufferInputStream(ByteBuffer buf) { b = buf; }
|
||||
|
||||
@Override public int available() { return b.remaining(); }
|
||||
public ByteBufferInputStream(ByteBuffer buf) {
|
||||
b = buf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException { return b.hasRemaining() ? (b.get() & 0xFF) : -1; }
|
||||
public int available() {
|
||||
return b.remaining();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
return b.hasRemaining() ? (b.get() & 0xFF) : -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] bytes, int off, int len) throws IOException {
|
||||
|
|
|
@ -16,11 +16,13 @@
|
|||
|
||||
package org.springframework.reactive.util;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Represents a signal value object, useful for wrapping signals as published by a {@link
|
||||
* #Publisher()}. Mostly used to store signals in buffers.
|
||||
* Publisher}. Mostly used to store signals in buffers.
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public abstract class PublisherSignal<T> {
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.springframework.reactive.web.http.servlet;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.servlet.AsyncContext;
|
||||
import javax.servlet.ServletInputStream;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.reactive.web.http.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.AsyncContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
|
@ -36,7 +37,7 @@ import org.springframework.reactive.web.http.HttpHandler;
|
|||
* @author Arjen Poutsma
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
@WebServlet(asyncSupported = true )
|
||||
@WebServlet(asyncSupported = true)
|
||||
public class HttpHandlerServlet extends HttpServlet {
|
||||
|
||||
private static final int BUFFER_SIZE = 8192;
|
||||
|
|
|
@ -20,6 +20,7 @@ import java.io.IOException;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.servlet.ReadListener;
|
||||
import javax.servlet.ServletInputStream;
|
||||
|
||||
|
@ -36,8 +37,6 @@ import org.springframework.reactive.util.DemandCounter;
|
|||
*/
|
||||
public class RequestBodyPublisher implements ReadListener, Publisher<ByteBuffer> {
|
||||
|
||||
private final Charset UTF_8 = Charset.forName("UTF-8");
|
||||
|
||||
private static final Log logger = LogFactory.getLog(RequestBodyPublisher.class);
|
||||
|
||||
private final AsyncContextSynchronizer synchronizer;
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.nio.ByteBuffer;
|
|||
import java.nio.charset.Charset;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
|
@ -73,10 +74,10 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
|
|||
public HttpHeaders getHeaders() {
|
||||
if (this.headers == null) {
|
||||
this.headers = new HttpHeaders();
|
||||
for (Enumeration<?> headerNames = this.servletRequest.getHeaderNames(); headerNames.hasMoreElements();) {
|
||||
for (Enumeration<?> headerNames = this.servletRequest.getHeaderNames(); headerNames.hasMoreElements(); ) {
|
||||
String headerName = (String) headerNames.nextElement();
|
||||
for (Enumeration<?> headerValues = this.servletRequest.getHeaders(headerName);
|
||||
headerValues.hasMoreElements();) {
|
||||
headerValues.hasMoreElements(); ) {
|
||||
String headerValue = (String) headerValues.nextElement();
|
||||
this.headers.add(headerName, headerValue);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.springframework.reactive.web.http.servlet;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
|
|
|
@ -19,7 +19,6 @@ package org.springframework.reactive.web.http;
|
|||
import java.net.URI;
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.http.RequestEntity;
|
||||
|
|
|
@ -45,8 +45,6 @@ public class XmlHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTe
|
|||
johnDoe);
|
||||
ResponseEntity<Person> response = restTemplate.exchange(request, Person.class);
|
||||
System.out.println(response.getBody());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@XmlRootElement
|
||||
|
|
Loading…
Reference in New Issue