Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Content-Type header for JMS message

Tags:

jms

ibm-mq

mq

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?

like image 509
pkid169 Avatar asked May 04 '15 04:05

pkid169


People also ask

What are JMS headers?

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.

What is JMS message type?

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.


2 Answers

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".

like image 138
Shashi Avatar answered Oct 22 '22 20:10

Shashi


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.

like image 1
user3714601 Avatar answered Oct 22 '22 19:10

user3714601