0

I'm working on some project where I'm building some JMS messages that I want to send using JmsTemplate, which is initialized in a Spring Boot app, via JNDI naming.

As my Broker is IBM MQ Series, I need to change the encoding value in the outgoing XML message, so I'm sure the broker will understand the message.

I haven't seen anywhere on the JmsTemplatesettings, or the ConnectionFactory JmsTemplate need to be initialized, where to put some outgoing interceptors.

If anyone got some ideas, or any workaround or some framework/library that could help, feel free to give me some hint.

Thanks

DamCx
  • 1,047
  • 1
  • 11
  • 25

1 Answers1

2

I assume you are using JAXB to create the XML message.

Configure your JmsTemplate with a MarshallingMessageConverter that uses a Jaxb2Marshaller where you can set the marshaller property JAXB_ENCODING:

Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller(); 
Map properties = new HashMap<String, String>();
properties.put(javax.xml.bind.Marshaller.JAXB_ENCODING, "YOUR-ENCODING");
jaxb2Marshaller.setMarshallerProperties(properties);
jaxb2Marshaller.setPackagesToScan("your.package");

JmsTemplate jms = new JmsTemplate(connectionFactory);
jms.setMessageConverter(new MarshallingMessageConverter(jaxb2Marshaller));
...
jms.convertAndSend(yourObject);
...
Daniel Steinmann
  • 2,119
  • 2
  • 15
  • 25
  • Thanks for your answer at it fits my need. Yet, I didn't want to use JAXB to convert my message as JMS Template can do it by itself. – DamCx Jul 11 '19 at 13:25
  • As far as I know the `JmsTemplate` uses as default the [SimpleMessageConverter](https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/jms/support/converter/SimpleMessageConverter.html). How did you create your XML without configuring the `MarshallingMessageConverter`? – Daniel Steinmann Jul 11 '19 at 18:45