Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MessageHeaderAccessor.getContentType() should get deal with String value too, rather than rely only casting to MimeType [SPR-12730] #17327

Closed
spring-issuemaster opened this issue Feb 18, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Feb 18, 2015

Artem Bilan opened SPR-12730 and commented

See the issue in the linked SO question.

Spring Integration AMQP populates content-type headers from AMQP Message headers as String. There are other components in Spring Integration which do the same, e.g. ObjectToJsonTransformer.

From other side AmqpMessageHeaderAccessor has this code:

@Override
public MimeType getContentType() {
	Object value = getHeader(AmqpHeaders.CONTENT_TYPE);
	if (value != null && value instanceof String) {
	return MimeType.valueOf((String) value);
	}
	else {
	return super.getContentType();
        }
}

Looks like would be better to move this code to the core MessageHeaderAccessor and allow for end-application to avoid this transformation:

.setHeader(MessageHeaders.CONTENT_TYPE, amqpMessageHeaderAccessor.getContentType())

Or manual MimeType.valueOf() invocation.

For me this is minor change, so can be backported.


Affects: 4.1.4

Reference URL: http://stackoverflow.com/questions/28587286/having-trouble-with-contenttype-going-from-amqp-to-stomp-message

Referenced from: commits dbd353b, 55a14eb

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 18, 2015

Juergen Hoeller commented

I've added defensive code to getId(), getTimestamp() and getContentType(), all doing instanceof checks now and being able to convert a String value if necessary (or even any holder object with a toString() result which happens to be parseable to the desired type).

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 18, 2015

Juergen Hoeller commented

Artem Bilan, this is available in the latest 4.1.5 snapshot now. Please give it a try and let me know whether it does the job for you...

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 19, 2015

Artem Bilan commented

Juergen Hoeller, I confirm that it works as expected. My test-case looks like:

@Bean                                                                                                                    
@Transformer(inputChannel = "input", outputChannel = "webSocketOutputChannel")                                           
public ObjectToJsonTransformer transformer() {                                                                           
	return new ObjectToJsonTransformer();                                                                                
}                                                                                                                        
                                                                                                                         
@Bean                                                                                                                    
@ServiceActivator(inputChannel = "webSocketOutputChannel")                                                               
public MessageHandler webSocketOutboundMessageHandler() {                                                                
	return new WebSocketOutboundMessageHandler(clientWebSocketContainer(),                                               
			new SubProtocolHandlerRegistry(stompSubProtocolHandler()));                                                  
}         
.....
this.input.send(
          new GenericMessage<Map<String, String>>(Collections.<String, String>singletonMap("foo", Spring")));                                                                                                               

Where ObjectToJsonTransformer populates contentType header as application/json String.

I've tested that with SF 4.2.0-BUILD-SNAPSHOT, but I see that 4.1.5 has the same code change.

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.