我们有一个Java应用程序,它通过IBM WebSphere MQ发送JMS消息。使用者应用程序要求将消息内容类型设置为“ application / json”。我该怎么做呢?
我检查了一些引用,看来我可以通过方法“ setStringProperty(headerKey,headerName)”设置额外的标题,例如
Message jmsMsg = session.createTextMessage(msgStr);
jmsMsg.setStringProperty("Content-Type", "application/json");
然后问题是“ Content-Type”不是有效的属性键,因为它包含“-”字符。
这可以用代码完成吗?还是实际上是在队列设置中配置的?
属性名称“ Content-Type”具有“-”字符。根据JMS规范,属性名称可以包含JavaCharacter.isJavaIdentifierPart
方法为其返回的任何字符true
。对于'-'字符isJavaIdentifierPart
方法,返回false
。因此,setStringProperty("Content-Type", "application/json")
方法调用因以下异常而失败。
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.
如果可以更改接收的应用程序,则可以选择"Content_Type"
(使用下划线)作为属性名称,而不是"Content-Type"
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句