Coverage Report - org.apache.camel.component.jms.EndpointMessageListener
 
Classes in this File Line Coverage Branch Coverage Complexity
EndpointMessageListener
79% 
100% 
0
 
 1  
 /**
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.camel.component.jms;
 18  
 
 19  
 import javax.jms.Message;
 20  
 import javax.jms.MessageListener;
 21  
 
 22  
 import org.apache.camel.Endpoint;
 23  
 import org.apache.camel.Exchange;
 24  
 import org.apache.camel.Processor;
 25  
 import org.apache.camel.RuntimeCamelException;
 26  
 import org.apache.commons.logging.Log;
 27  
 import org.apache.commons.logging.LogFactory;
 28  
 
 29  
 /**
 30  
  * A JMS {@link MessageListener} which can be used to delegate processing to a
 31  
  * Camel endpoint.
 32  
  * 
 33  
  * @version $Revision: 563665 $
 34  
  */
 35  
 public class EndpointMessageListener<E extends Exchange> implements MessageListener {
 36  1
     private static final transient Log LOG = LogFactory.getLog(EndpointMessageListener.class);
 37  
     private Endpoint<E> endpoint;
 38  
     private Processor processor;
 39  
     private JmsBinding binding;
 40  
 
 41  81
     public EndpointMessageListener(Endpoint<E> endpoint, Processor processor) {
 42  81
         this.endpoint = endpoint;
 43  81
         this.processor = processor;
 44  81
     }
 45  
 
 46  
     public void onMessage(Message message) {
 47  
         try {
 48  
 
 49  19
             if (LOG.isDebugEnabled()) {
 50  0
                 LOG.debug(endpoint + " receiving JMS message: " + message);
 51  
             }
 52  19
             JmsExchange exchange = createExchange(message);
 53  19
             processor.process((E)exchange);
 54  
 
 55  0
         } catch (Exception e) {
 56  0
             throw new RuntimeCamelException(e);
 57  19
         }
 58  19
     }
 59  
 
 60  
     public JmsExchange createExchange(Message message) {
 61  19
         return new JmsExchange(endpoint.getContext(), getBinding(), message);
 62  
     }
 63  
 
 64  
     // Properties
 65  
     // -------------------------------------------------------------------------
 66  
     public JmsBinding getBinding() {
 67  19
         if (binding == null) {
 68  0
             binding = new JmsBinding();
 69  
         }
 70  19
         return binding;
 71  
     }
 72  
 
 73  
     /**
 74  
      * Sets the binding used to convert from a Camel message to and from a JMS
 75  
      * message
 76  
      * 
 77  
      * @param binding the binding to use
 78  
      */
 79  
     public void setBinding(JmsBinding binding) {
 80  81
         this.binding = binding;
 81  81
     }
 82  
 }