1

code partial:

@MessageMapping("/string")
@SendTo("topic/test2")
public String hello2(String a) throws Exception{
 System.out.println(a);
 Thread.sleep(2000);
//simpMessagingTemplate.convertAndSend("/topic/test2","Send From backend");
 return "This is message 2";
}
<websocket:message-broker application-destination-prefix="/app" user-destination-prefix="/user">
<websocket:stomp-endpoint path="/websocket">
 <websocket:sockjs/>
</websocket:stomp-endpoint>
<websocket:simple-broker prefix="/topic"/>

I send a message use sockJS and stomp.js.

var websocket = new SockJS('http://localhost:8080/todo/websocket');
var client = Stomp.over(websocket);
 client.connect('benjamin','benjamin',function(msg){
 client.send('/app/string',{},'string');
}

I recive message on server side but throw a exception:

org.springframework.messaging.converter.MessageConversionException: Could not read JSON: Unrecognized token 'string': was expecting ('true', 'false' or 'null')
at [Source: [B@31e018db; line: 1, column: 13]

Spring version 4.0.6-RELEASE

I read the code ,find spring has 3 message Converters, but when spring use

MappingJackson2MessageConverter.convertFromInternal 

covert message throw this exception.should spring catch this exception and try use other coverters covert message? Is it a bug?

How can resolve it,someone can help me?

asked Aug 24, 2014 at 4:45
1
  • spring will inject the raw message Object as an Annotated Method parameter.I can get what I need from the raw message object such as byte[]. Commented Sep 1, 2014 at 3:28

1 Answer 1

1

I got de the question too. And I solve it by a bad method.

public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
.......
@Override
public boolean configureMessageConverters(List<MessageConverter> messageConverters) {
 messageConverters.add(new StringMessageConverter());
 messageConverters.add(new ByteArrayMessageConverter());
 return false;
}
}

disable JsonConvertor

answered Dec 6, 2014 at 2:11
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.