Coverage Report - org.apache.camel.component.jms.JmsEndpoint
 
Classes in this File Line Coverage Branch Coverage Complexity
JmsEndpoint
75% 
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  
 
 21  
 import org.apache.camel.PollingConsumer;
 22  
 import org.apache.camel.Processor;
 23  
 import org.apache.camel.impl.DefaultEndpoint;
 24  
 
 25  
 import org.springframework.jms.core.JmsOperations;
 26  
 import org.springframework.jms.core.JmsTemplate;
 27  
 import org.springframework.jms.listener.AbstractMessageListenerContainer;
 28  
 
 29  
 /**
 30  
  * A <a href="http://activemq.apache.org/jms.html">JMS Endpoint</a>
 31  
  * 
 32  
  * @version $Revision:520964 $
 33  
  */
 34  142
 public class JmsEndpoint extends DefaultEndpoint<JmsExchange> {
 35  
     private JmsBinding binding;
 36  
     private String destination;
 37  
     private final boolean pubSubDomain;
 38  
     private String selector;
 39  
     private JmsConfiguration configuration;
 40  
 
 41  
     public JmsEndpoint(String uri, JmsComponent component, String destination, boolean pubSubDomain, JmsConfiguration configuration) {
 42  133
         super(uri, component);
 43  133
         this.configuration = configuration;
 44  133
         this.destination = destination;
 45  133
         this.pubSubDomain = pubSubDomain;
 46  133
     }
 47  
 
 48  
     public JmsProducer createProducer() throws Exception {
 49  52
         JmsOperations template = createJmsOperations();
 50  52
         return createProducer(template);
 51  
     }
 52  
 
 53  
     /**
 54  
      * Creates a producer using the given template
 55  
      */
 56  
     public JmsProducer createProducer(JmsOperations template) throws Exception {
 57  52
         if (template instanceof JmsTemplate) {
 58  52
             JmsTemplate jmsTemplate = (JmsTemplate)template;
 59  52
             jmsTemplate.setPubSubDomain(pubSubDomain);
 60  52
             jmsTemplate.setDefaultDestinationName(destination);
 61  
         }
 62  52
         return new JmsProducer(this, template);
 63  
     }
 64  
 
 65  
     public JmsConsumer createConsumer(Processor processor) throws Exception {
 66  81
         AbstractMessageListenerContainer listenerContainer = configuration.createMessageListenerContainer();
 67  81
         return createConsumer(processor, listenerContainer);
 68  
     }
 69  
 
 70  
     /**
 71  
      * Creates a consumer using the given processor and listener container
 72  
      * 
 73  
      * @param processor the processor to use to process the messages
 74  
      * @param listenerContainer the listener container
 75  
      * @return a newly created consumer
 76  
      * @throws Exception if the consumer cannot be created
 77  
      */
 78  
     public JmsConsumer createConsumer(Processor processor, AbstractMessageListenerContainer listenerContainer) throws Exception {
 79  81
         listenerContainer.setDestinationName(destination);
 80  81
         listenerContainer.setPubSubDomain(pubSubDomain);
 81  81
         if (selector != null) {
 82  0
             listenerContainer.setMessageSelector(selector);
 83  
         }
 84  81
         return new JmsConsumer(this, processor, listenerContainer);
 85  
     }
 86  
 
 87  
     @Override
 88  
     public PollingConsumer<JmsExchange> createPollingConsumer() throws Exception {
 89  0
         JmsOperations template = createJmsOperations();
 90  0
         return new JmsPollingConsumer(this, template);
 91  
     }
 92  
 
 93  
     public JmsExchange createExchange() {
 94  11
         return new JmsExchange(getContext(), getBinding());
 95  
     }
 96  
 
 97  
     public JmsExchange createExchange(Message message) {
 98  0
         return new JmsExchange(getContext(), getBinding(), message);
 99  
     }
 100  
 
 101  
     // Properties
 102  
     // -------------------------------------------------------------------------
 103  
     public JmsBinding getBinding() {
 104  119
         if (binding == null) {
 105  103
             binding = new JmsBinding();
 106  
         }
 107  119
         return binding;
 108  
     }
 109  
 
 110  
     /**
 111  
      * Sets the binding used to convert from a Camel message to and from a JMS
 112  
      * message
 113  
      * 
 114  
      * @param binding the binding to use
 115  
      */
 116  
     public void setBinding(JmsBinding binding) {
 117  0
         this.binding = binding;
 118  0
     }
 119  
 
 120  
     public String getDestination() {
 121  27
         return destination;
 122  
     }
 123  
 
 124  
     public JmsConfiguration getConfiguration() {
 125  202
         return configuration;
 126  
     }
 127  
 
 128  
     public String getSelector() {
 129  0
         return selector;
 130  
     }
 131  
 
 132  
     /**
 133  
      * Sets the JMS selector to use
 134  
      */
 135  
     public void setSelector(String selector) {
 136  0
         this.selector = selector;
 137  0
     }
 138  
 
 139  
     public boolean isSingleton() {
 140  133
         return false;
 141  
     }
 142  
 
 143  
     protected JmsOperations createJmsOperations() {
 144  52
         return configuration.createJmsOperations(pubSubDomain, destination);
 145  
     }
 146  
 
 147  
 }