public class ProtobufHttpMessageWriter extends EncoderHttpMessageWriter<Message>
HttpMessageWriter
that can write a protobuf Message
and adds
X-Protobuf-Schema
, X-Protobuf-Message
headers and a
delimited=true
parameter is added to the content type if a flux is serialized.
For HttpMessageReader
, just use
new DecoderHttpMessageReader(new ProtobufDecoder())
.
ProtobufEncoder
Modifier and Type | Field and Description |
---|---|
private static java.util.concurrent.ConcurrentMap<java.lang.Class<?>,java.lang.reflect.Method> |
methodCache |
private static java.lang.String |
X_PROTOBUF_MESSAGE_HEADER |
private static java.lang.String |
X_PROTOBUF_SCHEMA_HEADER |
Constructor and Description |
---|
ProtobufHttpMessageWriter()
Create a new
ProtobufHttpMessageWriter with a default ProtobufEncoder . |
ProtobufHttpMessageWriter(Encoder<Message> encoder)
Create a new
ProtobufHttpMessageWriter with the given encoder. |
Modifier and Type | Method and Description |
---|---|
private static Message.Builder |
getMessageBuilder(java.lang.Class<?> clazz)
Create a new
Message.Builder instance for the given class. |
<any> |
write(<any> inputStream,
ResolvableType elementType,
MediaType mediaType,
ReactiveHttpOutputMessage message,
java.util.Map<java.lang.String,java.lang.Object> hints)
Write an given stream of object to the output message.
|
canWrite, getEncoder, getWritableMediaTypes, getWriteHints, write
private static final java.lang.String X_PROTOBUF_SCHEMA_HEADER
private static final java.lang.String X_PROTOBUF_MESSAGE_HEADER
private static final java.util.concurrent.ConcurrentMap<java.lang.Class<?>,java.lang.reflect.Method> methodCache
public ProtobufHttpMessageWriter()
ProtobufHttpMessageWriter
with a default ProtobufEncoder
.public ProtobufHttpMessageWriter(Encoder<Message> encoder)
ProtobufHttpMessageWriter
with the given encoder.encoder
- the Protobuf message encoder to usepublic <any> write(<any> inputStream, ResolvableType elementType, @Nullable MediaType mediaType, ReactiveHttpOutputMessage message, java.util.Map<java.lang.String,java.lang.Object> hints)
HttpMessageWriter
write
in interface HttpMessageWriter<Message>
write
in class EncoderHttpMessageWriter<Message>
inputStream
- the objects to writeelementType
- the type of objects in the stream which must have been
previously checked via HttpMessageWriter.canWrite(ResolvableType, MediaType)
mediaType
- the content type for the write (possibly null
to
indicate that the default content type of the writer must be used)message
- the message to write tohints
- additional information about how to encode and writeprivate static Message.Builder getMessageBuilder(java.lang.Class<?> clazz) throws java.lang.Exception
Message.Builder
instance for the given class.
This method uses a ConcurrentHashMap for caching method lookups.
java.lang.Exception