Class IntegrationUtils
java.lang.Object
org.springframework.integration.support.utils.IntegrationUtils
public final class IntegrationUtils extends Object
General utility methods.
- Since:
- 4.0
- Author:
- Gary Russell, Marius Bogoevici, Artem Bilan
-
Field Summary
Fields Modifier and Type Field Description static booleanFATAL_WHEN_NO_BEANFACTORYShould be set to TRUE on CI plans and framework developer systems.static StringINTEGRATION_CONVERSION_SERVICE_BEAN_NAMEstatic StringINTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME -
Method Summary
Modifier and Type Method Description static StringbytesToString(byte[] bytes, String encoding)Utility method for null-safe conversion from byte[] to String.static ConversionServicegetConversionService(BeanFactory beanFactory)static MessageBuilderFactorygetMessageBuilderFactory(BeanFactory beanFactory)Returns the context-wide `messageBuilderFactory` bean from the beanFactory, or aDefaultMessageBuilderFactoryif not found or the beanFactory is null.static StringobtainComponentName(NamedComponent component)Obtain a component name from the providedNamedComponent.static byte[]stringToBytes(String value, String encoding)Utility method for null-safe conversion from String to byte[].static RuntimeExceptionwrapInDeliveryExceptionIfNecessary(Message<?> message, Supplier<String> text, Throwable ex)If the exception is not aMessagingExceptionor does not have afailedMessage, wrap it in a newMessageDeliveryExceptionwith the message.static RuntimeExceptionwrapInHandlingExceptionIfNecessary(Message<?> message, Supplier<String> text, Throwable ex)If the exception is not aMessagingExceptionor does not have afailedMessage, wrap it in a newMessageHandlingExceptionwith the message.
-
Field Details
-
INTEGRATION_CONVERSION_SERVICE_BEAN_NAME
- See Also:
- Constant Field Values
-
INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME
- See Also:
- Constant Field Values
-
FATAL_WHEN_NO_BEANFACTORY
public static final boolean FATAL_WHEN_NO_BEANFACTORYShould be set to TRUE on CI plans and framework developer systems.
-
-
Method Details
-
getConversionService
- Parameters:
beanFactory- BeanFactory for lookup, must not be null.- Returns:
- The
ConversionServicebean whose name is "integrationConversionService" if available.
-
getMessageBuilderFactory
Returns the context-wide `messageBuilderFactory` bean from the beanFactory, or aDefaultMessageBuilderFactoryif not found or the beanFactory is null.- Parameters:
beanFactory- The bean factory.- Returns:
- The message builder factory.
-
stringToBytes
Utility method for null-safe conversion from String to byte[].- Parameters:
value- the String to be convertedencoding- the encoding- Returns:
- the byte[] corresponding to the given String and encoding, null if provided String argument was null
- Throws:
IllegalArgumentException- if the encoding is not supported
-
bytesToString
Utility method for null-safe conversion from byte[] to String.- Parameters:
bytes- the byte[] to be convertedencoding- the encoding- Returns:
- the String corresponding to the given byte[] and encoding, null if provided byte[] argument was null
- Throws:
IllegalArgumentException- if the encoding is not supported
-
wrapInDeliveryExceptionIfNecessary
public static RuntimeException wrapInDeliveryExceptionIfNecessary(Message<?> message, Supplier<String> text, Throwable ex)If the exception is not aMessagingExceptionor does not have afailedMessage, wrap it in a newMessageDeliveryExceptionwith the message.- Parameters:
message- the message.text- a Supplier for the new exception's message text.ex- the exception.- Returns:
- the wrapper, if necessary, or the original exception.
- Since:
- 5.0.4
-
wrapInHandlingExceptionIfNecessary
public static RuntimeException wrapInHandlingExceptionIfNecessary(Message<?> message, Supplier<String> text, Throwable ex)If the exception is not aMessagingExceptionor does not have afailedMessage, wrap it in a newMessageHandlingExceptionwith the message.- Parameters:
message- the message.text- a Supplier for the new exception's message text.ex- the exception.- Returns:
- the wrapper, if necessary, or the original exception.
- Since:
- 5.0.4
-
obtainComponentName
Obtain a component name from the providedNamedComponent.- Parameters:
component- theNamedComponentsource for component name.- Returns:
- the component name
- Since:
- 5.3
-