title: Apache Camel - warning when sending a JMS message
body: <p>I want to send a message into a JMS queue with Camel. The body is byte array and I would expect that Camel converts it to <code>javax.jms.BytesMessage</code> and sends it without a problem, but I get the following warning.</p>
  
  <p><code>Warning</code></p>
  
  <pre><code>[org.apache.camel.component.jms.JmsBinding] (Camel (camel) thread #0 -
  JmsConsumer[devrechTransactionsQueue@z4smq_4001) 
  Cannot determine specific JmsMessage type to use from body class. 
  Will use generic JmsMessage. Body class: org.apache.camel.impl.DefaultMessage.  
  If you want to send a POJO then your class might need to implement java.io.Serializable,
  or you can force a specific type by setting the jmsMessageType option on the JMS endpoint.
  </code></pre>
  
  <p>If I try to set the type manually (<code>exchange.getIn().setHeader("CamelJmsMessageType", JmsMessageType.Bytes);</code>), I get the NullPointerException.</p>
  
  <p><code>Exception</code></p>
  
  <pre><code>[org.apache.camel.processor.DefaultErrorHandler] (Camel (camel) thread #0 - JmsConsumer[devrechTransactionsQueue@z4smq_4001) Failed delivery for exchangeId: ID-madansportapp02-5
  1560-1313509081079-0-1. Exhausted after delivery attempt: 1 caught: java.lang.NullPointerException
  java.lang.NullPointerException
      at com.swiftmq.tools.util.DataByteArrayOutputStream.write(Unknown Source)
      at com.swiftmq.jms.BytesMessageImpl.writeBytes(Unknown Source)
      at org.apache.camel.component.jms.JmsBinding.createJmsMessageForType(JmsBinding.java:506)
      at org.apache.camel.component.jms.JmsBinding.createJmsMessage(JmsBinding.java:443)
      at org.apache.camel.component.jms.JmsBinding.makeJmsMessage(JmsBinding.java:267)
      at org.apache.camel.component.jms.JmsProducer$2.createMessage(JmsProducer.java:225)
      at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate.doSendToDestination(JmsConfiguration.java:198)
      at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate.access$100(JmsConfiguration.java:141)
      at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate$3.doInJms(JmsConfiguration.java:175)
      at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:466)
      at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate.send(JmsConfiguration.java:172)
      at org.apache.camel.component.jms.JmsProducer.doSend(JmsProducer.java:347)
      at org.apache.camel.component.jms.JmsProducer.processInOnly(JmsProducer.java:303)
      at org.apache.camel.component.jms.JmsProducer.process(JmsProducer.java:101)
      at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)
      at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:114)
      at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:286)
      at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:109)
      at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)
      at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)
      at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89)
      at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:69)
      at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)
      at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)
      at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89)
      at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:99)
      at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)
      at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:318)
      at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:209)
      at org.apache.camel.processor.DefaultChannel.process(DefaultChannel.java:305)
      at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)
      at org.apache.camel.processor.Pipeline.process(Pipeline.java:116)
      at org.apache.camel.processor.Pipeline.process(Pipeline.java:79)
      at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:102)
      at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)
      at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)
      at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89)
      at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:69)
      at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:104)
      at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:85)
      at org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:91)
      at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:560)
  ...
  </code></pre>
  
  <p><code>Code</code></p>
  
  <pre><code>public class MessageTranslator implements Processor {
  
  @Override
  public void process(Exchange exchange) throws Exception {
      RechargeType transaction = (RechargeType) exchange.getIn().getBody();
      exchange.getIn().setBody(createMessage(transaction));
  }
  
  private Message createMessage(RechargeType transaction) throws DataException, IOException {
      Message message = new DefaultMessage(); // camel message
      Request request = new Request(transaction); // our request
  
      final byte[] serializedPayload = RequestSerializationHelper.getSerializedPayload(request); // serialized request
      message.setBody(serializedPayload);
  
      return message;
  }
  }
  </code></pre>