Class FromProtobufTransformer
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.transformer.AbstractTransformer
org.springframework.integration.transformer.FromProtobufTransformer
- All Implemented Interfaces:
Aware
,BeanClassLoaderAware
,BeanFactoryAware
,BeanNameAware
,InitializingBean
,ApplicationContextAware
,ExpressionCapable
,GenericTransformer<Message<?>,
,Message<?>> NamedComponent
,Transformer
A Protocol Buffer transformer to instantiate
Message
objects
from either byte[]
if content type is application/x-protobuf
or from String
in case of application/json
content type.- Since:
- 6.1
- Author:
- Christian Tzolov
-
Field Summary
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger
-
Constructor Summary
ConstructorDescriptionConstruct an instance with the supplied default type to create.FromProtobufTransformer
(ProtobufMessageConverter protobufMessageConverter) Construct an instance with the supplied default type and ProtobufMessageConverter instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected Object
doTransform
(Message<?> message) Subclasses must implement this method to provide the transformation logic.protected void
onInit()
Subclasses may implement this for initialization logic.void
setBeanClassLoader
(ClassLoader classLoader) setExpectedType
(Class<? extends com.google.protobuf.Message> expectedType) Set an expected protobuf class type.setExpectedTypeExpression
(Expression expression) Set an expression to evaluate against the message to determine the type.setExpectedTypeExpressionString
(String expression) Set an expression to evaluate against the message to determine the type id.Methods inherited from class org.springframework.integration.transformer.AbstractTransformer
transform
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getComponentType, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
-
Constructor Details
-
FromProtobufTransformer
public FromProtobufTransformer()Construct an instance with the supplied default type to create. -
FromProtobufTransformer
Construct an instance with the supplied default type and ProtobufMessageConverter instance.- Parameters:
protobufMessageConverter
- the message converter used.
-
-
Method Details
-
setBeanClassLoader
- Specified by:
setBeanClassLoader
in interfaceBeanClassLoaderAware
-
setExpectedType
public FromProtobufTransformer setExpectedType(Class<? extends com.google.protobuf.Message> expectedType) Set an expected protobuf class type. Mutually exclusive withsetExpectedTypeExpression(org.springframework.expression.Expression)
andsetExpectedTypeExpressionString(java.lang.String)
.- Parameters:
expectedType
- expected protobuf class type.- Returns:
- updated FromProtobufTransformer instance.
-
setExpectedTypeExpressionString
Set an expression to evaluate against the message to determine the type id. Defaults toheaders['proto_type']
. Mutually exclusive withsetExpectedType(java.lang.Class<? extends com.google.protobuf.Message>)
andsetExpectedTypeExpression(org.springframework.expression.Expression)
.- Parameters:
expression
- the expression.- Returns:
- updated FromProtobufTransformer instance.
-
setExpectedTypeExpression
Set an expression to evaluate against the message to determine the type. Defaultheaders['proto_type']
. Mutually exclusive withsetExpectedType(java.lang.Class<? extends com.google.protobuf.Message>)
andsetExpectedTypeExpressionString(java.lang.String)
.- Parameters:
expression
- the expression.- Returns:
- updated FromProtobufTransformer instance.
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupport
Subclasses may implement this for initialization logic.- Overrides:
onInit
in classIntegrationObjectSupport
-
doTransform
Description copied from class:AbstractTransformer
Subclasses must implement this method to provide the transformation logic. If the return value is itself a Message, it will be used as the result. Otherwise, any non-null return value will be used as the payload of the result Message.- Specified by:
doTransform
in classAbstractTransformer
- Parameters:
message
- The message.- Returns:
- The result of the transformation.
-