org.springframework.messaging.converter.StringMessageConverter Java Examples
The following examples show how to use
org.springframework.messaging.converter.StringMessageConverter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReactorNettyTcpStompClientTests.java From spring-analysis-note with MIT License | 7 votes |
@Before public void setUp() throws Exception { logger.debug("Setting up before '" + this.testName.getMethodName() + "'"); int port = SocketUtils.findAvailableTcpPort(61613); this.activeMQBroker = new BrokerService(); this.activeMQBroker.addConnector("stomp://127.0.0.1:" + port); this.activeMQBroker.setStartAsync(false); this.activeMQBroker.setPersistent(false); this.activeMQBroker.setUseJmx(false); this.activeMQBroker.getSystemUsage().getMemoryUsage().setLimit(1024 * 1024 * 5); this.activeMQBroker.getSystemUsage().getTempUsage().setLimit(1024 * 1024 * 5); this.activeMQBroker.start(); ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); taskScheduler.afterPropertiesSet(); this.client = new ReactorNettyTcpStompClient("127.0.0.1", port); this.client.setMessageConverter(new StringMessageConverter()); this.client.setTaskScheduler(taskScheduler); }
Example #2
Source File: NotificationMessageArgumentResolverTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void resolveArgument_withValidMessagePayload_shouldReturnNotificationMessage() throws Exception { // Arrange NotificationMessageArgumentResolver notificationMessageArgumentResolver = new NotificationMessageArgumentResolver( new StringMessageConverter()); Method methodWithNotificationMessageArgument = this.getClass() .getDeclaredMethod("methodWithNotificationMessageArgument", String.class); MethodParameter methodParameter = new MethodParameter( methodWithNotificationMessageArgument, 0); ObjectNode jsonObject = JsonNodeFactory.instance.objectNode(); jsonObject.put("Type", "Notification"); jsonObject.put("Message", "Hello World!"); String payload = jsonObject.toString(); Message<String> message = MessageBuilder.withPayload(payload).build(); // Act Object result = notificationMessageArgumentResolver .resolveArgument(methodParameter, message); // Assert assertThat(String.class.isInstance(result)).isTrue(); assertThat(result).isEqualTo("Hello World!"); }
Example #3
Source File: SubscriptionMethodReturnValueHandlerTests.java From java-technology-stack with MIT License | 6 votes |
@Before public void setup() throws Exception { MockitoAnnotations.initMocks(this); SimpMessagingTemplate messagingTemplate = new SimpMessagingTemplate(this.messageChannel); messagingTemplate.setMessageConverter(new StringMessageConverter()); this.handler = new SubscriptionMethodReturnValueHandler(messagingTemplate); SimpMessagingTemplate jsonMessagingTemplate = new SimpMessagingTemplate(this.messageChannel); jsonMessagingTemplate.setMessageConverter(new MappingJackson2MessageConverter()); this.jsonHandler = new SubscriptionMethodReturnValueHandler(jsonMessagingTemplate); Method method = this.getClass().getDeclaredMethod("getData"); this.subscribeEventReturnType = new MethodParameter(method, -1); method = this.getClass().getDeclaredMethod("getDataAndSendTo"); this.subscribeEventSendToReturnType = new MethodParameter(method, -1); method = this.getClass().getDeclaredMethod("handle"); this.messageMappingReturnType = new MethodParameter(method, -1); method = this.getClass().getDeclaredMethod("getJsonView"); this.subscribeEventJsonViewReturnType = new MethodParameter(method, -1); }
Example #4
Source File: StompTest.java From WeEvent with Apache License 2.0 | 6 votes |
@Before public void before() throws Exception { log.info("=============================={}.{}==============================", this.getClass().getSimpleName(), this.testName.getMethodName()); String brokerStomp = "ws://localhost:" + this.listenPort + "/weevent-broker/stomp"; ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); taskScheduler.initialize(); this.stompClient = new WebSocketStompClient(new StandardWebSocketClient()); // MappingJackson2MessageConverter stompClient.setMessageConverter(new StringMessageConverter()); stompClient.setTaskScheduler(taskScheduler); // for heartbeats this.header.setDestination(topic); this.header.set("eventId", WeEvent.OFFSET_LAST); this.header.set("groupId", WeEvent.DEFAULT_GROUP_ID); this.failure = new AtomicReference<>(); CountDownLatch latch = new CountDownLatch(1); this.stompSession = this.stompClient.connect(brokerStomp, new MyStompSessionHandler(latch, this.failure)).get(); latch.await(); this.stompSession.setAutoReceipt(true); }
Example #5
Source File: SimpAnnotationMethodMessageHandler.java From java-technology-stack with MIT License | 6 votes |
/** * Create an instance of SimpAnnotationMethodMessageHandler with the given * message channels and broker messaging template. * @param clientInboundChannel the channel for receiving messages from clients (e.g. WebSocket clients) * @param clientOutboundChannel the channel for messages to clients (e.g. WebSocket clients) * @param brokerTemplate a messaging template to send application messages to the broker */ public SimpAnnotationMethodMessageHandler(SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel, SimpMessageSendingOperations brokerTemplate) { Assert.notNull(clientInboundChannel, "clientInboundChannel must not be null"); Assert.notNull(clientOutboundChannel, "clientOutboundChannel must not be null"); Assert.notNull(brokerTemplate, "brokerTemplate must not be null"); this.clientInboundChannel = clientInboundChannel; this.clientMessagingTemplate = new SimpMessagingTemplate(clientOutboundChannel); this.brokerTemplate = brokerTemplate; Collection<MessageConverter> converters = new ArrayList<>(); converters.add(new StringMessageConverter()); converters.add(new ByteArrayMessageConverter()); this.messageConverter = new CompositeMessageConverter(converters); }
Example #6
Source File: PayloadMethodArgumentResolverTests.java From spring-analysis-note with MIT License | 6 votes |
@Before public void setup() throws Exception { this.resolver = new PayloadMethodArgumentResolver(new StringMessageConverter(), testValidator()); Method payloadMethod = PayloadMethodArgumentResolverTests.class.getDeclaredMethod( "handleMessage", String.class, String.class, Locale.class, String.class, String.class, String.class, String.class); this.paramAnnotated = new SynthesizingMethodParameter(payloadMethod, 0); this.paramAnnotatedNotRequired = new SynthesizingMethodParameter(payloadMethod, 1); this.paramAnnotatedRequired = new SynthesizingMethodParameter(payloadMethod, 2); this.paramWithSpelExpression = new SynthesizingMethodParameter(payloadMethod, 3); this.paramValidated = new SynthesizingMethodParameter(payloadMethod, 4); this.paramValidated.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer()); this.paramValidatedNotAnnotated = new SynthesizingMethodParameter(payloadMethod, 5); this.paramNotAnnotated = new SynthesizingMethodParameter(payloadMethod, 6); }
Example #7
Source File: MessageBrokerConfigurationTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void configureMessageConvertersCustomAndDefault() { final MessageConverter testConverter = mock(MessageConverter.class); AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() { @Override protected boolean configureMessageConverters(List<MessageConverter> messageConverters) { messageConverters.add(testConverter); return true; } }; CompositeMessageConverter compositeConverter = config.brokerMessageConverter(); assertThat(compositeConverter.getConverters().size(), Matchers.is(4)); Iterator<MessageConverter> iterator = compositeConverter.getConverters().iterator(); assertThat(iterator.next(), Matchers.is(testConverter)); assertThat(iterator.next(), Matchers.instanceOf(StringMessageConverter.class)); assertThat(iterator.next(), Matchers.instanceOf(ByteArrayMessageConverter.class)); assertThat(iterator.next(), Matchers.instanceOf(MappingJackson2MessageConverter.class)); }
Example #8
Source File: WebSocketStompClientIntegrationTests.java From spring-analysis-note with MIT License | 6 votes |
@Before public void setUp() throws Exception { logger.debug("Setting up before '" + this.testName.getMethodName() + "'"); this.wac = new AnnotationConfigWebApplicationContext(); this.wac.register(TestConfig.class); this.wac.refresh(); this.server = new TomcatWebSocketTestServer(); this.server.setup(); this.server.deployConfig(this.wac); this.server.start(); WebSocketClient webSocketClient = new StandardWebSocketClient(); this.stompClient = new WebSocketStompClient(webSocketClient); this.stompClient.setMessageConverter(new StringMessageConverter()); }
Example #9
Source File: SubscriptionMethodReturnValueHandlerTests.java From spring-analysis-note with MIT License | 6 votes |
@Before public void setup() throws Exception { MockitoAnnotations.initMocks(this); SimpMessagingTemplate messagingTemplate = new SimpMessagingTemplate(this.messageChannel); messagingTemplate.setMessageConverter(new StringMessageConverter()); this.handler = new SubscriptionMethodReturnValueHandler(messagingTemplate); SimpMessagingTemplate jsonMessagingTemplate = new SimpMessagingTemplate(this.messageChannel); jsonMessagingTemplate.setMessageConverter(new MappingJackson2MessageConverter()); this.jsonHandler = new SubscriptionMethodReturnValueHandler(jsonMessagingTemplate); Method method = this.getClass().getDeclaredMethod("getData"); this.subscribeEventReturnType = new MethodParameter(method, -1); method = this.getClass().getDeclaredMethod("getDataAndSendTo"); this.subscribeEventSendToReturnType = new MethodParameter(method, -1); method = this.getClass().getDeclaredMethod("handle"); this.messageMappingReturnType = new MethodParameter(method, -1); method = this.getClass().getDeclaredMethod("getJsonView"); this.subscribeEventJsonViewReturnType = new MethodParameter(method, -1); }
Example #10
Source File: ReactorNettyTcpStompClientTests.java From java-technology-stack with MIT License | 6 votes |
@Before public void setUp() throws Exception { logger.debug("Setting up before '" + this.testName.getMethodName() + "'"); int port = SocketUtils.findAvailableTcpPort(61613); this.activeMQBroker = new BrokerService(); this.activeMQBroker.addConnector("stomp://127.0.0.1:" + port); this.activeMQBroker.setStartAsync(false); this.activeMQBroker.setPersistent(false); this.activeMQBroker.setUseJmx(false); this.activeMQBroker.getSystemUsage().getMemoryUsage().setLimit(1024 * 1024 * 5); this.activeMQBroker.getSystemUsage().getTempUsage().setLimit(1024 * 1024 * 5); this.activeMQBroker.start(); ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); taskScheduler.afterPropertiesSet(); this.client = new ReactorNettyTcpStompClient("127.0.0.1", port); this.client.setMessageConverter(new StringMessageConverter()); this.client.setTaskScheduler(taskScheduler); }
Example #11
Source File: MessageBrokerConfigurationTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void configureMessageConvertersCustomAndDefault() { final MessageConverter testConverter = mock(MessageConverter.class); AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() { @Override protected boolean configureMessageConverters(List<MessageConverter> messageConverters) { messageConverters.add(testConverter); return true; } }; CompositeMessageConverter compositeConverter = config.brokerMessageConverter(); assertThat(compositeConverter.getConverters().size(), Matchers.is(4)); Iterator<MessageConverter> iterator = compositeConverter.getConverters().iterator(); assertThat(iterator.next(), Matchers.is(testConverter)); assertThat(iterator.next(), Matchers.instanceOf(StringMessageConverter.class)); assertThat(iterator.next(), Matchers.instanceOf(ByteArrayMessageConverter.class)); assertThat(iterator.next(), Matchers.instanceOf(MappingJackson2MessageConverter.class)); }
Example #12
Source File: PayloadArgumentResolverTests.java From java-technology-stack with MIT License | 6 votes |
@Before public void setup() throws Exception { this.resolver = new PayloadArgumentResolver(new StringMessageConverter(), testValidator()); Method payloadMethod = PayloadArgumentResolverTests.class.getDeclaredMethod( "handleMessage", String.class, String.class, Locale.class, String.class, String.class, String.class, String.class); this.paramAnnotated = new SynthesizingMethodParameter(payloadMethod, 0); this.paramAnnotatedNotRequired = new SynthesizingMethodParameter(payloadMethod, 1); this.paramAnnotatedRequired = new SynthesizingMethodParameter(payloadMethod, 2); this.paramWithSpelExpression = new SynthesizingMethodParameter(payloadMethod, 3); this.paramValidated = new SynthesizingMethodParameter(payloadMethod, 4); this.paramValidated.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer()); this.paramValidatedNotAnnotated = new SynthesizingMethodParameter(payloadMethod, 5); this.paramNotAnnotated = new SynthesizingMethodParameter(payloadMethod, 6); }
Example #13
Source File: WebSocketStompClientIntegrationTests.java From java-technology-stack with MIT License | 6 votes |
@Before public void setUp() throws Exception { logger.debug("Setting up before '" + this.testName.getMethodName() + "'"); this.wac = new AnnotationConfigWebApplicationContext(); this.wac.register(TestConfig.class); this.wac.refresh(); this.server = new TomcatWebSocketTestServer(); this.server.setup(); this.server.deployConfig(this.wac); this.server.start(); WebSocketClient webSocketClient = new StandardWebSocketClient(); this.stompClient = new WebSocketStompClient(webSocketClient); this.stompClient.setMessageConverter(new StringMessageConverter()); }
Example #14
Source File: SimpAnnotationMethodMessageHandler.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Create an instance of SimpAnnotationMethodMessageHandler with the given * message channels and broker messaging template. * @param clientInboundChannel the channel for receiving messages from clients (e.g. WebSocket clients) * @param clientOutboundChannel the channel for messages to clients (e.g. WebSocket clients) * @param brokerTemplate a messaging template to send application messages to the broker */ public SimpAnnotationMethodMessageHandler(SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel, SimpMessageSendingOperations brokerTemplate) { Assert.notNull(clientInboundChannel, "clientInboundChannel must not be null"); Assert.notNull(clientOutboundChannel, "clientOutboundChannel must not be null"); Assert.notNull(brokerTemplate, "brokerTemplate must not be null"); this.clientInboundChannel = clientInboundChannel; this.clientMessagingTemplate = new SimpMessagingTemplate(clientOutboundChannel); this.brokerTemplate = brokerTemplate; Collection<MessageConverter> converters = new ArrayList<MessageConverter>(); converters.add(new StringMessageConverter()); converters.add(new ByteArrayMessageConverter()); this.messageConverter = new CompositeMessageConverter(converters); }
Example #15
Source File: SubscriptionMethodReturnValueHandlerTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Before public void setup() throws Exception { MockitoAnnotations.initMocks(this); SimpMessagingTemplate messagingTemplate = new SimpMessagingTemplate(this.messageChannel); messagingTemplate.setMessageConverter(new StringMessageConverter()); this.handler = new SubscriptionMethodReturnValueHandler(messagingTemplate); SimpMessagingTemplate jsonMessagingTemplate = new SimpMessagingTemplate(this.messageChannel); jsonMessagingTemplate.setMessageConverter(new MappingJackson2MessageConverter()); this.jsonHandler = new SubscriptionMethodReturnValueHandler(jsonMessagingTemplate); Method method = this.getClass().getDeclaredMethod("getData"); this.subscribeEventReturnType = new MethodParameter(method, -1); method = this.getClass().getDeclaredMethod("getDataAndSendTo"); this.subscribeEventSendToReturnType = new MethodParameter(method, -1); method = this.getClass().getDeclaredMethod("handle"); this.messageMappingReturnType = new MethodParameter(method, -1); method = this.getClass().getDeclaredMethod("getJsonView"); this.subscribeEventJsonViewReturnType = new MethodParameter(method, -1); }
Example #16
Source File: Reactor2TcpStompClientTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { logger.debug("Setting up before '" + this.testName.getMethodName() + "'"); int port = SocketUtils.findAvailableTcpPort(61613); this.activeMQBroker = new BrokerService(); this.activeMQBroker.addConnector("stomp://127.0.0.1:" + port); this.activeMQBroker.setStartAsync(false); this.activeMQBroker.setPersistent(false); this.activeMQBroker.setUseJmx(false); this.activeMQBroker.getSystemUsage().getMemoryUsage().setLimit(1024 * 1024 * 5); this.activeMQBroker.getSystemUsage().getTempUsage().setLimit(1024 * 1024 * 5); this.activeMQBroker.start(); ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); taskScheduler.afterPropertiesSet(); this.client = new Reactor2TcpStompClient("127.0.0.1", port); this.client.setMessageConverter(new StringMessageConverter()); this.client.setTaskScheduler(taskScheduler); }
Example #17
Source File: MessageBrokerConfigurationTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void configureMessageConvertersCustomAndDefault() { final MessageConverter testConverter = mock(MessageConverter.class); AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() { @Override protected boolean configureMessageConverters(List<MessageConverter> messageConverters) { messageConverters.add(testConverter); return true; } }; CompositeMessageConverter compositeConverter = config.brokerMessageConverter(); assertThat(compositeConverter.getConverters().size(), Matchers.is(4)); Iterator<MessageConverter> iterator = compositeConverter.getConverters().iterator(); assertThat(iterator.next(), Matchers.is(testConverter)); assertThat(iterator.next(), Matchers.instanceOf(StringMessageConverter.class)); assertThat(iterator.next(), Matchers.instanceOf(ByteArrayMessageConverter.class)); assertThat(iterator.next(), Matchers.instanceOf(MappingJackson2MessageConverter.class)); }
Example #18
Source File: WebSocketStompClientIntegrationTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { logger.debug("Setting up before '" + this.testName.getMethodName() + "'"); this.wac = new AnnotationConfigWebApplicationContext(); this.wac.register(TestConfig.class); this.wac.refresh(); this.server = new TomcatWebSocketTestServer(); this.server.setup(); this.server.deployConfig(this.wac); this.server.start(); WebSocketClient webSocketClient = new StandardWebSocketClient(); this.stompClient = new WebSocketStompClient(webSocketClient); this.stompClient.setMessageConverter(new StringMessageConverter()); }
Example #19
Source File: QueueMessageHandler.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Override protected List<? extends HandlerMethodArgumentResolver> initArgumentResolvers() { List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>( getCustomArgumentResolvers()); resolvers.add(new HeaderMethodArgumentResolver(null, null)); resolvers.add(new SqsHeadersMethodArgumentResolver()); resolvers.add(new NotificationSubjectArgumentResolver()); resolvers.add(new AcknowledgmentHandlerMethodArgumentResolver(ACKNOWLEDGMENT)); resolvers.add(new VisibilityHandlerMethodArgumentResolver(VISIBILITY)); CompositeMessageConverter compositeMessageConverter = createPayloadArgumentCompositeConverter(); resolvers.add(new NotificationMessageArgumentResolver(compositeMessageConverter)); resolvers.add(new MessageMethodArgumentResolver( this.messageConverters.isEmpty() ? new StringMessageConverter() : new CompositeMessageConverter(this.messageConverters))); resolvers.add(new PayloadArgumentResolver(compositeMessageConverter, new NoOpValidator())); return resolvers; }
Example #20
Source File: AbstractMessageChannelMessagingSendingTemplate.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
protected void initMessageConverter(MessageConverter messageConverter) { StringMessageConverter stringMessageConverter = new StringMessageConverter(); stringMessageConverter.setSerializedPayloadClass(String.class); List<MessageConverter> messageConverters = new ArrayList<>(); messageConverters.add(stringMessageConverter); if (messageConverter != null) { messageConverters.add(messageConverter); } else { MappingJackson2MessageConverter mappingJackson2MessageConverter = new MappingJackson2MessageConverter(); mappingJackson2MessageConverter.setSerializedPayloadClass(String.class); messageConverters.add(mappingJackson2MessageConverter); } setMessageConverter(new CompositeMessageConverter(messageConverters)); }
Example #21
Source File: NotificationRequestConverterTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void fromMessage_withMessageAndSubject_shouldReturnMessage() throws Exception { // Arrange ObjectNode jsonObject = JsonNodeFactory.instance.objectNode(); jsonObject.put("Type", "Notification"); jsonObject.put("Subject", "Hello"); jsonObject.put("Message", "World"); String payload = jsonObject.toString(); // Act Object notificationRequest = new NotificationRequestConverter( new StringMessageConverter()).fromMessage( MessageBuilder.withPayload(payload).build(), String.class); // Assert assertThat(NotificationRequestConverter.NotificationRequest.class .isInstance(notificationRequest)).isTrue(); assertThat( ((NotificationRequestConverter.NotificationRequest) notificationRequest) .getSubject()).isEqualTo("Hello"); assertThat( ((NotificationRequestConverter.NotificationRequest) notificationRequest) .getMessage()).isEqualTo("World"); }
Example #22
Source File: NotificationRequestConverterTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void fromMessage_withMessageOnly_shouldReturnMessage() throws Exception { // Arrange ObjectNode jsonObject = JsonNodeFactory.instance.objectNode(); jsonObject.put("Type", "Notification"); jsonObject.put("Message", "World"); String payload = jsonObject.toString(); // Act Object notificationRequest = new NotificationRequestConverter( new StringMessageConverter()).fromMessage( MessageBuilder.withPayload(payload).build(), String.class); // Assert assertThat(NotificationRequestConverter.NotificationRequest.class .isInstance(notificationRequest)).isTrue(); assertThat( ((NotificationRequestConverter.NotificationRequest) notificationRequest) .getMessage()).isEqualTo("World"); }
Example #23
Source File: NotificationRequestConverterTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void fromMessage_withNumberAttribute_shouldReturnMessage() throws Exception { // Arrange ObjectNode jsonObject = JsonNodeFactory.instance.objectNode(); jsonObject.put("Type", "Notification"); jsonObject.put("Message", "World"); ObjectNode messageAttributes = JsonNodeFactory.instance.objectNode(); messageAttributes.set("number-attribute", JsonNodeFactory.instance.objectNode() .put("Value", "30").put("Type", "Number.long")); jsonObject.set("MessageAttributes", messageAttributes); String payload = jsonObject.toString(); // Act Object notificationRequest = new NotificationRequestConverter( new StringMessageConverter()).fromMessage( MessageBuilder.withPayload(payload).build(), String.class); // Assert assertThat(notificationRequest).isNotNull(); }
Example #24
Source File: NotificationRequestConverterTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void testWrongTypeSupplied() throws Exception { ObjectNode jsonObject = JsonNodeFactory.instance.objectNode(); jsonObject.put("Type", "Subscription"); jsonObject.put("Message", "Hello World!"); String payload = jsonObject.toString(); assertThatThrownBy( () -> new NotificationRequestConverter(new StringMessageConverter()) .fromMessage(MessageBuilder.withPayload(payload).build(), String.class)) .isInstanceOf(MessageConversionException.class) .hasMessageContaining( "is not a valid notification"); }
Example #25
Source File: NotificationMessageArgumentResolverTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void supportsParameter_withNotificationMessageMethodParameter_shouldReturnTrue() throws Exception { // Arrange NotificationMessageArgumentResolver notificationMessageArgumentResolver = new NotificationMessageArgumentResolver( new StringMessageConverter()); Method methodWithNotificationMessageArgument = this.getClass() .getDeclaredMethod("methodWithNotificationMessageArgument", String.class); MethodParameter methodParameter = new MethodParameter( methodWithNotificationMessageArgument, 0); // Act boolean result = notificationMessageArgumentResolver .supportsParameter(methodParameter); // Assert assertThat(result).isTrue(); }
Example #26
Source File: NotificationMessageArgumentResolverTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void supportsParameter_withWrongMethodParameter_shouldReturnFalse() throws Exception { // Arrange NotificationMessageArgumentResolver notificationMessageArgumentResolver = new NotificationMessageArgumentResolver( new StringMessageConverter()); Method methodWithMissingAnnotation = this.getClass() .getDeclaredMethod("methodWithMissingAnnotation", String.class); MethodParameter methodParameter = new MethodParameter(methodWithMissingAnnotation, 0); // Act boolean result = notificationMessageArgumentResolver .supportsParameter(methodParameter); // Assert assertThat(result).isFalse(); }
Example #27
Source File: NotificationMessageArgumentResolverTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void supportsParameter_withNonStringParameterType_shouldReturnTrue() throws Exception { // Arrange NotificationMessageArgumentResolver notificationMessageArgumentResolver = new NotificationMessageArgumentResolver( new StringMessageConverter()); Method methodWithWrongParameterType = this.getClass() .getDeclaredMethod("methodWithWrongParameterType", Long.class); MethodParameter methodParameter = new MethodParameter( methodWithWrongParameterType, 0); // Act boolean result = notificationMessageArgumentResolver .supportsParameter(methodParameter); // Assert assertThat(result).isTrue(); }
Example #28
Source File: RocketMQMessageConverter.java From rocketmq-spring with Apache License 2.0 | 6 votes |
public RocketMQMessageConverter() { List<MessageConverter> messageConverters = new ArrayList<>(); ByteArrayMessageConverter byteArrayMessageConverter = new ByteArrayMessageConverter(); byteArrayMessageConverter.setContentTypeResolver(null); messageConverters.add(byteArrayMessageConverter); messageConverters.add(new StringMessageConverter()); if (JACKSON_PRESENT) { messageConverters.add(new MappingJackson2MessageConverter()); } if (FASTJSON_PRESENT) { try { messageConverters.add( (MessageConverter)ClassUtils.forName( "com.alibaba.fastjson.support.spring.messaging.MappingFastJsonMessageConverter", ClassUtils.getDefaultClassLoader()).newInstance()); } catch (ClassNotFoundException | IllegalAccessException | InstantiationException ignored) { //ignore this exception } } messageConverter = new CompositeMessageConverter(messageConverters); }
Example #29
Source File: SimpleFunctionRegistryTests.java From spring-cloud-function with Apache License 2.0 | 5 votes |
@BeforeEach public void before() { List<MessageConverter> messageConverters = new ArrayList<>(); JsonMapper jsonMapper = new GsonMapper(new Gson()); messageConverters.add(NegotiatingMessageConverterWrapper.wrap(new JsonMessageConverter(jsonMapper))); messageConverters.add(NegotiatingMessageConverterWrapper.wrap(new ByteArrayMessageConverter())); messageConverters.add(NegotiatingMessageConverterWrapper.wrap(new StringMessageConverter())); this.messageConverter = new CompositeMessageConverter(messageConverters); this.conversionService = new DefaultConversionService(); }
Example #30
Source File: NotificationRequestConverterTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Test void testWriteMessageNotSupported() throws Exception { assertThatThrownBy( () -> new NotificationRequestConverter(new StringMessageConverter()) .toMessage("test", null)) .isInstanceOf(UnsupportedOperationException.class); }