当前位置: 首页>>代码示例>>Java>>正文


Java MappingJackson2MessageConverter类代码示例

本文整理汇总了Java中org.springframework.messaging.converter.MappingJackson2MessageConverter的典型用法代码示例。如果您正苦于以下问题:Java MappingJackson2MessageConverter类的具体用法?Java MappingJackson2MessageConverter怎么用?Java MappingJackson2MessageConverter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MappingJackson2MessageConverter类属于org.springframework.messaging.converter包,在下文中一共展示了MappingJackson2MessageConverter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.springframework.messaging.converter.MappingJackson2MessageConverter; //导入依赖的package包/类
public static void main(String... argv) {
    WebSocketClient webSocketClient = new StandardWebSocketClient();
    WebSocketStompClient stompClient = new WebSocketStompClient(webSocketClient);
    stompClient.setMessageConverter(new MappingJackson2MessageConverter());
    stompClient.setTaskScheduler(new ConcurrentTaskScheduler());

    String url = "ws://127.0.0.1:8080/hello";
    StompSessionHandler sessionHandler = new MySessionHandler();
    stompClient.connect(url, sessionHandler);

    new Scanner(System.in).nextLine(); //Don't close immediately.
}
 
开发者ID:nielsutrecht,项目名称:spring-boot-websocket-client,代码行数:13,代码来源:ServiceClient.java

示例2: testTracedWebsocketSession

import org.springframework.messaging.converter.MappingJackson2MessageConverter; //导入依赖的package包/类
@Test
public void testTracedWebsocketSession()
    throws URISyntaxException, InterruptedException, ExecutionException, TimeoutException {
  WebSocketStompClient stompClient = new WebSocketStompClient(
      new SockJsClient(createTransportClient()));
  stompClient.setMessageConverter(new MappingJackson2MessageConverter());

  StompSession stompSession = stompClient.connect(url, new StompSessionHandlerAdapter() {
  }).get(1, TimeUnit.SECONDS);

  stompSession.subscribe(SUBSCRIBE_GREETINGS_ENDPOINT, new GreetingStompFrameHandler());
  stompSession.send(SEND_HELLO_MESSAGE_ENDPOINT, new HelloMessage("Hi"));

  // Three spans related to the websocket session, and two related to websocket connect
  await().until(() -> mockTracer.finishedSpans().size() == 5);

  assertTrue(mockTracer.finishedSpans().stream().filter(s ->
      s.operationName().equals(SEND_HELLO_MESSAGE_ENDPOINT)).toArray().length == 1);
  assertTrue(mockTracer.finishedSpans().stream().filter(s ->
      s.operationName().equals(SUBSCRIBE_GREETINGS_ENDPOINT)).toArray().length == 1);
  assertTrue(mockTracer.finishedSpans().stream().filter(s ->
      s.operationName().equals(GreetingController.DOING_WORK)).toArray().length == 1);
}
 
开发者ID:opentracing-contrib,项目名称:java-spring-cloud,代码行数:24,代码来源:SpringWebsocketTracingTest.java

示例3: setup

import org.springframework.messaging.converter.MappingJackson2MessageConverter; //导入依赖的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

示例4: setUp

import org.springframework.messaging.converter.MappingJackson2MessageConverter; //导入依赖的package包/类
@Before
public void setUp() throws Exception {

	MockitoAnnotations.initMocks(this);

	when(this.brokerChannel.send(any())).thenReturn(true);
	this.converter = new MappingJackson2MessageConverter();

	SimpMessagingTemplate brokerTemplate = new SimpMessagingTemplate(this.brokerChannel);
	brokerTemplate.setMessageConverter(this.converter);

	this.localRegistry = mock(SimpUserRegistry.class);
	this.multiServerRegistry = new MultiServerUserRegistry(this.localRegistry);

	this.handler = new UserRegistryMessageHandler(this.multiServerRegistry, brokerTemplate,
			"/topic/simp-user-registry", this.taskScheduler);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:UserRegistryMessageHandlerTests.java

示例5: configureMessageConvertersCustomAndDefault

import org.springframework.messaging.converter.MappingJackson2MessageConverter; //导入依赖的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));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:MessageBrokerConfigurationTests.java

示例6: sqsMessageHandler

import org.springframework.messaging.converter.MappingJackson2MessageConverter; //导入依赖的package包/类
@Bean
public QueueMessageHandler sqsMessageHandler() {
  Collection<MessageConverter> converters = new ArrayList<>();
  MappingJackson2MessageConverter jacksonConverter = new MappingJackson2MessageConverter();
  jacksonConverter.setSerializedPayloadClass(String.class);
  jacksonConverter.setStrictContentTypeMatch(false);
  converters.add(jacksonConverter);

  List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>();
  CompositeMessageConverter compositeMessageConverter = new CompositeMessageConverter(converters);
  resolvers.add(new NotificationMessageArgumentResolver(compositeMessageConverter));
  resolvers.add(new PayloadArgumentResolver(compositeMessageConverter));

  QueueMessageHandler handler = sqsMessageHandlerFactory().createQueueMessageHandler();
  handler.setArgumentResolvers(resolvers);
  return handler;
}
 
开发者ID:kalnee,项目名称:trivor,代码行数:18,代码来源:AWSConfig.java

示例7: setup

import org.springframework.messaging.converter.MappingJackson2MessageConverter; //导入依赖的package包/类
@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    this.deviceRegistry = new DeviceRegistry();

    this.brokerTemplateChannel = new TestMessageChannel();

    this.template = new SimpMessagingTemplate(this.brokerTemplateChannel);
    CompositeController controller = new CompositeController(sessionService,
            template, deviceRegistry);

    this.annotationMethodMessageHandler = new TestSimpAnnotationMethodMessageHandler(
            new TestMessageChannel(), new TestMessageChannel(), this.template);

    this.annotationMethodMessageHandler.registerHandler(controller);
    this.annotationMethodMessageHandler.setDestinationPrefixes(Arrays.asList("/app"));
    this.annotationMethodMessageHandler.setMessageConverter(new MappingJackson2MessageConverter());
    this.annotationMethodMessageHandler.setApplicationContext(new StaticApplicationContext());
    this.annotationMethodMessageHandler.afterPropertiesSet();

}
 
开发者ID:wieden-kennedy,项目名称:composite-framework,代码行数:22,代码来源:StandaloneCompositeTests.java

示例8: createPayloadArgumentCompositeConverter

import org.springframework.messaging.converter.MappingJackson2MessageConverter; //导入依赖的package包/类
private CompositeMessageConverter createPayloadArgumentCompositeConverter() {
    List<MessageConverter> payloadArgumentConverters = new ArrayList<>();

    if (JACKSON_2_PRESENT) {
        MappingJackson2MessageConverter jacksonMessageConverter = new MappingJackson2MessageConverter();
        jacksonMessageConverter.setObjectMapper(Jackson2ObjectMapperBuilder.json().build());
        jacksonMessageConverter.setSerializedPayloadClass(String.class);
        jacksonMessageConverter.setStrictContentTypeMatch(true);
        payloadArgumentConverters.add(jacksonMessageConverter);
    }

    ObjectMessageConverter objectMessageConverter = new ObjectMessageConverter();
    objectMessageConverter.setStrictContentTypeMatch(true);
    payloadArgumentConverters.add(objectMessageConverter);

    payloadArgumentConverters.add(new SimpleMessageConverter());

    return new CompositeMessageConverter(payloadArgumentConverters);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:20,代码来源:QueueMessageHandler.java

示例9: initMessageConverter

import org.springframework.messaging.converter.MappingJackson2MessageConverter; //导入依赖的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

示例10: receiveMessage_methodWithCustomObjectAsParameter_parameterIsConverted

import org.springframework.messaging.converter.MappingJackson2MessageConverter; //导入依赖的package包/类
@Test
public void receiveMessage_methodWithCustomObjectAsParameter_parameterIsConverted() {
    StaticApplicationContext applicationContext = new StaticApplicationContext();
    applicationContext.registerSingleton("incomingMessageHandler", IncomingMessageHandlerWithCustomParameter.class);
    applicationContext.registerSingleton("queueMessageHandler", QueueMessageHandler.class);
    applicationContext.refresh();

    MessageHandler messageHandler = applicationContext.getBean(MessageHandler.class);
    DummyKeyValueHolder messagePayload = new DummyKeyValueHolder("myKey", "A value");
    MappingJackson2MessageConverter jsonMapper = new MappingJackson2MessageConverter();
    Message<?> message = jsonMapper.toMessage(messagePayload, new MessageHeaders(Collections.singletonMap(QueueMessageHandler.LOGICAL_RESOURCE_ID, "testQueue")));
    messageHandler.handleMessage(message);

    IncomingMessageHandlerWithCustomParameter messageListener = applicationContext.getBean(IncomingMessageHandlerWithCustomParameter.class);
    assertNotNull(messageListener.getLastReceivedMessage());
    assertEquals("myKey", messageListener.getLastReceivedMessage().getKey());
    assertEquals("A value", messageListener.getLastReceivedMessage().getValue());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:19,代码来源:QueueMessageHandlerTest.java

示例11: instantiation_WithCustomJacksonConverterThatSupportsJava8Types_shouldConvertMessageToString

import org.springframework.messaging.converter.MappingJackson2MessageConverter; //导入依赖的package包/类
@Test
public void instantiation_WithCustomJacksonConverterThatSupportsJava8Types_shouldConvertMessageToString() throws IOException {

    // Arrange
    AmazonSQSAsync amazonSqs = createAmazonSqs();

    ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();

    MappingJackson2MessageConverter simpleMessageConverter = new MappingJackson2MessageConverter();
    simpleMessageConverter.setSerializedPayloadClass(String.class);
    simpleMessageConverter.setObjectMapper(objectMapper);

    QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate(amazonSqs, (ResourceIdResolver) null, simpleMessageConverter);

    // Act
    queueMessagingTemplate.convertAndSend("test", new TestPerson("Agim", "Emruli", LocalDate.of(2017, 1, 1)));

    // Assert
    ArgumentCaptor<SendMessageRequest> sendMessageRequestArgumentCaptor = ArgumentCaptor.forClass(SendMessageRequest.class);
    verify(amazonSqs).sendMessage(sendMessageRequestArgumentCaptor.capture());
    TestPerson testPerson = objectMapper.readValue(sendMessageRequestArgumentCaptor.getValue().getMessageBody(), TestPerson.class);

    assertEquals("Agim", testPerson.getFirstName());
    assertEquals("Emruli", testPerson.getLastName());
    assertEquals(LocalDate.of(2017, 1, 1), testPerson.getActiveSince());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:27,代码来源:QueueMessagingTemplateTest.java

示例12: setup

import org.springframework.messaging.converter.MappingJackson2MessageConverter; //导入依赖的package包/类
@Before
public void setup() {
    List<Transport> transports = new ArrayList<>();
    transports.add(new WebSocketTransport(new StandardWebSocketClient()));
    this.sockJsClient = new SockJsClient(transports);

    this.stompClient = new WebSocketStompClient(sockJsClient);
    this.stompClient.setMessageConverter(new MappingJackson2MessageConverter());
}
 
开发者ID:sweetca,项目名称:logger,代码行数:10,代码来源:LogIntegrationTests.java

示例13: main

import org.springframework.messaging.converter.MappingJackson2MessageConverter; //导入依赖的package包/类
public static void main(String args[]) throws Exception
   {
WebSocketClient simpleWebSocketClient =
    new StandardWebSocketClient();
List<Transport> transports = new ArrayList<>(1);
transports.add(new WebSocketTransport(simpleWebSocketClient));

SockJsClient sockJsClient = new SockJsClient(transports);
WebSocketStompClient stompClient =
    new WebSocketStompClient(sockJsClient);
stompClient.setMessageConverter(new MappingJackson2MessageConverter());

String url = "ws://localhost:9090/chat";
String userId = "spring-" +
    ThreadLocalRandom.current().nextInt(1, 99);
StompSessionHandler sessionHandler = new MyStompSessionHandler(userId);
StompSession session = stompClient.connect(url, sessionHandler)
    .get();
BufferedReader in =
    new BufferedReader(new InputStreamReader(System.in));
for (;;) {
    System.out.print(userId + " >> ");
    System.out.flush();
    String line = in.readLine();
    if ( line == null ) break;
    if ( line.length() == 0 ) continue;
    ClientMessage msg = new ClientMessage(userId, line);
    session.send("/app/chat/java", msg);
}
   }
 
开发者ID:jaysridhar,项目名称:spring-websocket-client,代码行数:31,代码来源:Application.java

示例14: setup

import org.springframework.messaging.converter.MappingJackson2MessageConverter; //导入依赖的package包/类
@Before
public void setup() {
	List<Transport> transports = new ArrayList<>();
	transports.add(new WebSocketTransport(new StandardWebSocketClient()));
	this.sockJsClient = new SockJsClient(transports);

	this.stompClient = new WebSocketStompClient(sockJsClient);
	this.stompClient.setMessageConverter(new MappingJackson2MessageConverter());
}
 
开发者ID:WASdev,项目名称:sample.SpringBootWebsocket,代码行数:10,代码来源:GreetingIntegrationTestIT.java

示例15: jackson2Converter

import org.springframework.messaging.converter.MappingJackson2MessageConverter; //导入依赖的package包/类
@Bean
public MappingJackson2MessageConverter jackson2Converter() {
   ObjectMapper mapper = new ObjectMapper();

   mapper.registerModule(new JavaTimeModule());
   mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);

   return new MappingJackson2MessageConverter();
}
 
开发者ID:HumanCellAtlas,项目名称:ingest-core,代码行数:10,代码来源:QueueConfig.java


注:本文中的org.springframework.messaging.converter.MappingJackson2MessageConverter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。