类 ProtobufHttpMessageConverter
- 所有已实现的接口:
HttpMessageConverter<com.google.protobuf.Message>
HttpMessageConverter that reads and writes
com.google.protobuf.Messages using
Google Protocol Buffers.
To generate Message Java classes, you need to install the protoc binary.
This converter supports by default "application/x-protobuf" and "text/plain"
with the official "com.google.protobuf:protobuf-java" library. Other formats can be
supported with one of the following additional libraries on the classpath:
"application/json","application/xml", and"text/html"(write-only) with the"com.googlecode.protobuf-java-format:protobuf-java-format"third-party library"application/json"with the official"com.google.protobuf:protobuf-java-util"for Protobuf 3 (seeProtobufJsonFormatHttpMessageConverterfor a configurable variant)
Requires Protobuf 2.6 or higher (and Protobuf Java Format 1.4 or higher for formatting).
This converter will auto-adapt to Protobuf 3 and its default protobuf-java-util JSON
format if the Protobuf 2 based protobuf-java-format isn't present; however, for more
explicit JSON setup on Protobuf 3, consider ProtobufJsonFormatHttpMessageConverter.
- 从以下版本开始:
- 4.0
- 作者:
- Alex Antonov, Brian Clozel, Juergen Hoeller, Sebastien Deleuze
- 另请参阅:
-
FormatFactoryJsonFormatProtobufJsonFormatHttpMessageConverter
-
嵌套类概要
嵌套类修饰符和类型类说明(专用程序包) static interfaceProtobuf format support.(专用程序包) static classProtobufHttpMessageConverter.ProtobufFormatSupportimplementation used whencom.googlecode.protobuf.format.FormatFactoryis available.(专用程序包) static classProtobufHttpMessageConverter.ProtobufFormatSupportimplementation used whencom.google.protobuf.util.JsonFormatis available. -
字段概要
字段修饰符和类型字段说明static final CharsetThe default charset used by the converter.(专用程序包) final com.google.protobuf.ExtensionRegistrystatic final MediaTypeThe media-type for protobufapplication/x-protobuf.private final ProtobufHttpMessageConverter.ProtobufFormatSupportstatic final StringThe HTTP header containing the protobuf message.static final StringThe HTTP header containing the protobuf schema.从类继承的字段 cn.taketoday.http.converter.AbstractHttpMessageConverter
logger -
构造器概要
构造器构造器说明Construct a newProtobufHttpMessageConverter.ProtobufHttpMessageConverter(ProtobufHttpMessageConverter.ProtobufFormatSupport formatSupport, com.google.protobuf.ExtensionRegistry extensionRegistry) ProtobufHttpMessageConverter(com.google.protobuf.ExtensionRegistry extensionRegistry) Construct a newProtobufHttpMessageConverterwith a registry that specifies protocol message extensions. -
方法概要
修饰符和类型方法说明protected booleanReturnstrueif the given media type includes any of the supported media types.protected MediaTypegetDefaultContentType(com.google.protobuf.Message message) Returns the default content type for the given type.private com.google.protobuf.Message.BuildergetMessageBuilder(Class<? extends com.google.protobuf.Message> clazz) Create a newMessage.Builderinstance for the given class.protected com.google.protobuf.MessagereadInternal(Class<? extends com.google.protobuf.Message> clazz, HttpInputMessage inputMessage) Abstract template method that reads the actual object.private voidsetProtoHeader(HttpOutputMessage response, com.google.protobuf.Message message) Set the "X-Protobuf-*" HTTP headers when responding with a message of content type "application/x-protobuf"protected booleanIndicates whether the given class is supported by this converter.protected voidwriteInternal(com.google.protobuf.Message message, HttpOutputMessage outputMessage) Abstract template method that writes the actual body.从类继承的方法 cn.taketoday.http.converter.AbstractHttpMessageConverter
addDefaultHeaders, canRead, canRead, canWrite, getContentLength, getDefaultCharset, getSupportedMediaTypes, read, setDefaultCharset, setSupportedMediaTypes, write从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait从接口继承的方法 cn.taketoday.http.converter.HttpMessageConverter
getSupportedMediaTypes
-
字段详细资料
-
DEFAULT_CHARSET
The default charset used by the converter. -
PROTOBUF
The media-type for protobufapplication/x-protobuf. -
X_PROTOBUF_SCHEMA_HEADER
The HTTP header containing the protobuf schema.- 另请参阅:
-
X_PROTOBUF_MESSAGE_HEADER
The HTTP header containing the protobuf message.- 另请参阅:
-
methodCache
-
extensionRegistry
final com.google.protobuf.ExtensionRegistry extensionRegistry -
protobufFormatSupport
-
-
构造器详细资料
-
ProtobufHttpMessageConverter
public ProtobufHttpMessageConverter()Construct a newProtobufHttpMessageConverter. -
ProtobufHttpMessageConverter
public ProtobufHttpMessageConverter(com.google.protobuf.ExtensionRegistry extensionRegistry) Construct a newProtobufHttpMessageConverterwith a registry that specifies protocol message extensions.- 参数:
extensionRegistry- the registry to populate
-
ProtobufHttpMessageConverter
ProtobufHttpMessageConverter(@Nullable ProtobufHttpMessageConverter.ProtobufFormatSupport formatSupport, @Nullable com.google.protobuf.ExtensionRegistry extensionRegistry)
-
-
方法详细资料
-
supports
从类复制的说明:AbstractHttpMessageConverterIndicates whether the given class is supported by this converter.- 指定者:
supports在类中AbstractHttpMessageConverter<com.google.protobuf.Message>- 参数:
clazz- the class to test for support- 返回:
trueif supported;falseotherwise
-
getDefaultContentType
从类复制的说明:AbstractHttpMessageConverterReturns the default content type for the given type. Called whenAbstractHttpMessageConverter.write(T, cn.taketoday.http.MediaType, cn.taketoday.http.HttpOutputMessage)is invoked without a specified content type parameter.By default, this returns the first element of the
supportedMediaTypesproperty, if any. Can be overridden in subclasses.- 覆盖:
getDefaultContentType在类中AbstractHttpMessageConverter<com.google.protobuf.Message>- 参数:
message- the type to return the content type for- 返回:
- the content type, or
nullif not known
-
readInternal
protected com.google.protobuf.Message readInternal(Class<? extends com.google.protobuf.Message> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException 从类复制的说明:AbstractHttpMessageConverterAbstract template method that reads the actual object. Invoked fromAbstractHttpMessageConverter.read(java.lang.Class<? extends T>, cn.taketoday.http.HttpInputMessage).- 指定者:
readInternal在类中AbstractHttpMessageConverter<com.google.protobuf.Message>- 参数:
clazz- the type of object to returninputMessage- the HTTP input message to read from- 返回:
- the converted object
- 抛出:
IOException- in case of I/O errorsHttpMessageNotReadableException- in case of conversion errors
-
getMessageBuilder
private com.google.protobuf.Message.Builder getMessageBuilder(Class<? extends com.google.protobuf.Message> clazz) Create a newMessage.Builderinstance for the given class.This method uses a ConcurrentReferenceHashMap for caching method lookups.
-
canWrite
从类复制的说明:AbstractHttpMessageConverterReturnstrueif the given media type includes any of the supported media types.- 覆盖:
canWrite在类中AbstractHttpMessageConverter<com.google.protobuf.Message>- 参数:
mediaType- the media type to write, can benullif not specified. Typically the value of anAcceptheader.- 返回:
trueif the supported media types are compatible with the media type, or if the media type isnull
-
writeInternal
protected void writeInternal(com.google.protobuf.Message message, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException 从类复制的说明:AbstractHttpMessageConverterAbstract template method that writes the actual body. Invoked fromAbstractHttpMessageConverter.write(T, cn.taketoday.http.MediaType, cn.taketoday.http.HttpOutputMessage).- 指定者:
writeInternal在类中AbstractHttpMessageConverter<com.google.protobuf.Message>- 参数:
message- the object to write to the output messageoutputMessage- the HTTP output message to write to- 抛出:
IOException- in case of I/O errorsHttpMessageNotWritableException- in case of conversion errors
-
setProtoHeader
Set the "X-Protobuf-*" HTTP headers when responding with a message of content type "application/x-protobuf"Note:
outputMessage.getBody()should not have been called before because it writes HTTP headers (making them read only).
-