We have a Java application that sends JMS message via IBM WebSphere MQ. The consumer application requires the message content type to be set to "application/json". How can I go about doing it?
I've checked through a few references and it seems I can set extra header via method "setStringProperty(headerKey, headerName)", E.g.
Message jmsMsg = session.createTextMessage(msgStr);
jmsMsg.setStringProperty("Content-Type", "application/json");
The problem then is "Content-Type" is not a valid property key since it contains the "-" character.
Is this something that can be done in code? Or is it actually configured in the queue settings?
JMS headers are predefined named values that are present in all messages (although the value might be null). The following is a list of JMS header names this Connector supports: JMSCorrelationID. (String) This header is set by the application for use by other applications. JMSDeliveryMode.
JMS defines six message interface types; a base message type and five subtypes. The message types are defined according to the type of the message payload , where the payload is the body of a message that holds the content. JMS specifies only the interface and does not specify the implementation.
The property name "Content-Type" has a '-' character. According to JMS specifications a property name can contain any character for which the Java Character.isJavaIdentifierPart
method returns a true
. For '-' character isJavaIdentifierPart
method returns false
. Hence the setStringProperty("Content-Type", "application/json")
method call fails with the following exception.
com.ibm.msg.client.jms.DetailedMessageFormatException: JMSCC0049: The property name 'Content-Type' is not a valid Java(tm) identifier.
The supplied property name does not conform to the allowed format described in the JMS specification.
Check the characters used in the property name and modify as necessary.
If it's possible to change the receiving application, you could opt for "Content_Type"
(Use an underscore) as property name instead of "Content-Type"
.
As an example for SOAP format, w3c requires using JMS property named "SOAPJMS_contentType" (http://www.w3.org/TR/soapjms/). It looks that there is nothing about JSON format in the standards, but you can use name like that. Such name will be processed correctly by IBM JMS libraries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With