本文整理汇总了Java中org.springframework.messaging.converter.StringMessageConverter类的典型用法代码示例。如果您正苦于以下问题:Java StringMessageConverter类的具体用法?Java StringMessageConverter怎么用?Java StringMessageConverter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringMessageConverter类属于org.springframework.messaging.converter包,在下文中一共展示了StringMessageConverter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.springframework.messaging.converter.StringMessageConverter; //导入依赖的package包/类
public static void main(String[] args) {
DefaultSetting.setDefaultNetwork();
if(args.length==0){
OutputMessage.error("please enter parameter");
return;
}
Map<String, String> params = parseParamsToMap(args);
if(params==null){
return;
}
// set host, port and websocket port
DefaultSetting.setHostAndPort(params.get("host"), params.get("port"), params.get("wsPort"));
final String address = params.get("address");
final String WS_URI = DefaultSetting.getWsUri();
// create WebSocket client
List<Transport> transports = new ArrayList<Transport>(1);
transports.add(new WebSocketTransport(new StandardWebSocketClient()));
WebSocketClient transport = new SockJsClient(transports);
WebSocketStompClient stompClient = new WebSocketStompClient(transport);
stompClient.setMessageConverter(new StringMessageConverter());
StompSessionHandler handler = new WsMonitorMultisigHandler(address);
stompClient.connect(WS_URI, handler);
//block and monitor exit action
ScannerUtil.monitorExit();
}
示例2: main
import org.springframework.messaging.converter.StringMessageConverter; //导入依赖的package包/类
public static void main(String[] args) {
DefaultSetting.setDefaultNetwork();
if(args.length==0){
OutputMessage.error("please enter parameter");
return;
}
Map<String, String> params = parseParamsToMap(args);
if(params==null){
return;
}
// set host, port and websocket port
DefaultSetting.setHostAndPort(params.get("host"), params.get("port"), params.get("wsPort"));
final String address = params.get("address");
final String WS_URI = DefaultSetting.getWsUri();
// create WebSocket client
List<Transport> transports = new ArrayList<Transport>(1);
transports.add(new WebSocketTransport(new StandardWebSocketClient()));
WebSocketClient transport = new SockJsClient(transports);
WebSocketStompClient stompClient = new WebSocketStompClient(transport);
stompClient.setMessageConverter(new StringMessageConverter());
StompSessionHandler handler = new WsMonitorImcomingHandler(address);
stompClient.connect(WS_URI, handler);
//block and monitor exit action
ScannerUtil.monitorExit();
}
示例3: SimpAnnotationMethodMessageHandler
import org.springframework.messaging.converter.StringMessageConverter; //导入依赖的package包/类
/**
* 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);
}
示例4: setup
import org.springframework.messaging.converter.StringMessageConverter; //导入依赖的package包/类
@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);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:SubscriptionMethodReturnValueHandlerTests.java
示例5: configureMessageConvertersCustomAndDefault
import org.springframework.messaging.converter.StringMessageConverter; //导入依赖的package包/类
@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));
}
示例6: setUp
import org.springframework.messaging.converter.StringMessageConverter; //导入依赖的package包/类
@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());
}
示例7: initMessageConverter
import org.springframework.messaging.converter.StringMessageConverter; //导入依赖的package包/类
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 if (JACKSON_2_PRESENT) {
MappingJackson2MessageConverter mappingJackson2MessageConverter = new MappingJackson2MessageConverter();
mappingJackson2MessageConverter.setObjectMapper(Jackson2ObjectMapperBuilder.json().build());
mappingJackson2MessageConverter.setSerializedPayloadClass(String.class);
messageConverters.add(mappingJackson2MessageConverter);
}
setMessageConverter(new CompositeMessageConverter(messageConverters));
}
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:20,代码来源:AbstractMessageChannelMessagingSendingTemplate.java
示例8: fromMessage_withMessageAndSubject_shouldReturnMessage
import org.springframework.messaging.converter.StringMessageConverter; //导入依赖的package包/类
@Test
public 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
assertTrue(NotificationRequestConverter.NotificationRequest.class.isInstance(notificationRequest));
assertEquals("Hello", ((NotificationRequestConverter.NotificationRequest) notificationRequest).getSubject());
assertEquals("World", ((NotificationRequestConverter.NotificationRequest) notificationRequest).getMessage());
}
示例9: resolveArgument_withValidMessagePayload_shouldReturnNotificationMessage
import org.springframework.messaging.converter.StringMessageConverter; //导入依赖的package包/类
@Test
public 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
assertTrue(String.class.isInstance(result));
assertEquals("Hello World!", result);
}
示例10: PubSubInboundChannelAdapter
import org.springframework.messaging.converter.StringMessageConverter; //导入依赖的package包/类
public PubSubInboundChannelAdapter(PubSubOperations pubSubTemplate, String subscriptionName) {
this.pubSubTemplate = pubSubTemplate;
this.subscriptionName = subscriptionName;
StringMessageConverter stringMessageConverter = new StringMessageConverter();
stringMessageConverter.setSerializedPayloadClass(String.class);
this.messageConverter = stringMessageConverter;
}
示例11: brokerMessageConverter
import org.springframework.messaging.converter.StringMessageConverter; //导入依赖的package包/类
@Bean
public CompositeMessageConverter brokerMessageConverter() {
List<MessageConverter> converters = new ArrayList<MessageConverter>();
boolean registerDefaults = configureMessageConverters(converters);
if (registerDefaults) {
converters.add(new StringMessageConverter());
converters.add(new ByteArrayMessageConverter());
if (jackson2Present) {
converters.add(createJacksonConverter());
}
}
return new CompositeMessageConverter(converters);
}
示例12: setup
import org.springframework.messaging.converter.StringMessageConverter; //导入依赖的package包/类
@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
SimpMessagingTemplate messagingTemplate = new SimpMessagingTemplate(this.messageChannel);
messagingTemplate.setMessageConverter(new StringMessageConverter());
this.handler = new SendToMethodReturnValueHandler(messagingTemplate, true);
this.handlerAnnotationNotRequired = new SendToMethodReturnValueHandler(messagingTemplate, false);
SimpMessagingTemplate jsonMessagingTemplate = new SimpMessagingTemplate(this.messageChannel);
jsonMessagingTemplate.setMessageConverter(new MappingJackson2MessageConverter());
this.jsonHandler = new SendToMethodReturnValueHandler(jsonMessagingTemplate, true);
Method method = this.getClass().getDeclaredMethod("handleNoAnnotations");
this.noAnnotationsReturnType = new SynthesizingMethodParameter(method, -1);
method = this.getClass().getDeclaredMethod("handleAndSendToDefaultDestination");
this.sendToDefaultDestReturnType = new SynthesizingMethodParameter(method, -1);
method = this.getClass().getDeclaredMethod("handleAndSendTo");
this.sendToReturnType = new SynthesizingMethodParameter(method, -1);
method = this.getClass().getDeclaredMethod("handleAndSendToWithPlaceholders");
this.sendToWithPlaceholdersReturnType = new SynthesizingMethodParameter(method, -1);
method = this.getClass().getDeclaredMethod("handleAndSendToUser");
this.sendToUserReturnType = new SynthesizingMethodParameter(method, -1);
method = this.getClass().getDeclaredMethod("handleAndSendToUserSingleSession");
this.sendToUserSingleSessionReturnType = new SynthesizingMethodParameter(method, -1);
method = this.getClass().getDeclaredMethod("handleAndSendToUserDefaultDestination");
this.sendToUserDefaultDestReturnType = new SynthesizingMethodParameter(method, -1);
method = this.getClass().getDeclaredMethod("handleAndSendToUserDefaultDestinationSingleSession");
this.sendToUserSingleSessionDefaultDestReturnType = new SynthesizingMethodParameter(method, -1);
method = this.getClass().getDeclaredMethod("handleAndSendToJsonView");
this.jsonViewReturnType = new SynthesizingMethodParameter(method, -1);
}
示例13: setUp
import org.springframework.messaging.converter.StringMessageConverter; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
this.sessionHandler = mock(StompSessionHandler.class);
this.connectHeaders = new StompHeaders();
this.session = new DefaultStompSession(this.sessionHandler, this.connectHeaders);
this.session.setMessageConverter(new StringMessageConverter());
SettableListenableFuture<Void> future = new SettableListenableFuture<>();
future.set(null);
when(this.connection.send(this.messageCaptor.capture())).thenReturn(future);
}
示例14: configureMessageConvertersDefault
import org.springframework.messaging.converter.StringMessageConverter; //导入依赖的package包/类
@Test
public void configureMessageConvertersDefault() {
AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig();
CompositeMessageConverter compositeConverter = config.brokerMessageConverter();
List<MessageConverter> converters = compositeConverter.getConverters();
assertThat(converters.size(), Matchers.is(3));
assertThat(converters.get(0), Matchers.instanceOf(StringMessageConverter.class));
assertThat(converters.get(1), Matchers.instanceOf(ByteArrayMessageConverter.class));
assertThat(converters.get(2), Matchers.instanceOf(MappingJackson2MessageConverter.class));
ContentTypeResolver resolver = ((MappingJackson2MessageConverter) converters.get(2)).getContentTypeResolver();
assertEquals(MimeTypeUtils.APPLICATION_JSON, ((DefaultContentTypeResolver) resolver).getDefaultMimeType());
}
示例15: setup
import org.springframework.messaging.converter.StringMessageConverter; //导入依赖的package包/类
@Before
public void setup() throws Exception {
this.resolver = new PayloadArgumentResolver(new StringMessageConverter(), testValidator());
this.payloadMethod = PayloadArgumentResolverTests.class.getDeclaredMethod("handleMessage",
String.class, String.class, Locale.class, String.class, String.class, String.class, String.class);
this.paramAnnotated = new SynthesizingMethodParameter(this.payloadMethod, 0);
this.paramAnnotatedNotRequired = new SynthesizingMethodParameter(this.payloadMethod, 1);
this.paramAnnotatedRequired = new SynthesizingMethodParameter(payloadMethod, 2);
this.paramWithSpelExpression = new SynthesizingMethodParameter(payloadMethod, 3);
this.paramValidated = new SynthesizingMethodParameter(this.payloadMethod, 4);
this.paramValidated.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
this.paramValidatedNotAnnotated = new SynthesizingMethodParameter(this.payloadMethod, 5);
this.paramNotAnnotated = new SynthesizingMethodParameter(this.payloadMethod, 6);
}