How to customize the Content-Type header for a JMS message

We have a Java application that sends a JMS message through IBM WebSphere MQ. The consumer application requires the message content type to be set to "application / json". How can i do this?

I've checked several links and it seems that I can set an additional header using the setStringProperty (headerKey, headerName) "method, for example.

Message jmsMsg = session.createTextMessage(msgStr);
jmsMsg.setStringProperty("Content-Type", "application/json");

      

Then the "Content-Type" problem is not a valid property key because it contains a "-" character.

Is this something that can be done in code? Or is it really configured in the queue settings?

+3


source to share


2 answers


The property name "Content-Type" has a "-" character. According to the JMS specifications, the property name can contain any character for which the Java method Character.isJavaIdentifierPart

returns true

. For a method, '-' isJavaIdentifierPart

returns false

. Therefore, the method call setStringProperty("Content-Type", "application/json")

fails with a subsequent 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 you can change the destination application, you can select "Content_Type"

(Use underscore) as the property name instead "Content-Type"

.

+2


source


As an example for the SOAP format, w3c requires the use of a JMS property named SOAPJMS_contentType ( http://www.w3.org/TR/soapjms/ ). It looks like there is nothing in the JSON format standards, but you can use that name. This name will be handled correctly by the IBM JMS libraries.



0


source







All Articles