Coverage Report - org.apache.camel.component.jms.JmsComponent
 
Classes in this File Line Coverage Branch Coverage Complexity
JmsComponent
29% 
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 java.util.Map;
 20  
 
 21  
 import javax.jms.ConnectionFactory;
 22  
 import javax.jms.ExceptionListener;
 23  
 import javax.jms.Session;
 24  
 
 25  
 import org.apache.camel.CamelContext;
 26  
 import org.apache.camel.Endpoint;
 27  
 import org.apache.camel.impl.DefaultComponent;
 28  
 import org.apache.camel.util.IntrospectionSupport;
 29  
 
 30  
 import org.springframework.core.task.TaskExecutor;
 31  
 import org.springframework.jms.listener.serversession.ServerSessionFactory;
 32  
 import org.springframework.jms.support.converter.MessageConverter;
 33  
 import org.springframework.transaction.PlatformTransactionManager;
 34  
 
 35  
 import static org.apache.camel.util.ObjectHelper.removeStartingCharacters;
 36  
 
 37  
 /**
 38  
  * A <a href="http://activemq.apache.org/jms.html">JMS Component</a>
 39  
  * 
 40  
  * @version $Revision:520964 $
 41  
  */
 42  
 public class JmsComponent extends DefaultComponent<JmsExchange> {
 43  
     public static final String QUEUE_PREFIX = "queue:";
 44  
     public static final String TOPIC_PREFIX = "topic:";
 45  
 
 46  
     private JmsConfiguration configuration;
 47  
 
 48  4
     public JmsComponent() {
 49  4
     }
 50  
 
 51  9
     public JmsComponent(JmsConfiguration configuration) {
 52  9
         this.configuration = configuration;
 53  9
     }
 54  
 
 55  
     public JmsComponent(CamelContext context) {
 56  0
         super(context);
 57  0
     }
 58  
     
 59  
     /**
 60  
      * Static builder method
 61  
      */
 62  
     public static JmsComponent jmsComponent() {
 63  0
         return new JmsComponent();
 64  
     }
 65  
 
 66  
     /**
 67  
      * Static builder method
 68  
      */
 69  
     public static JmsComponent jmsComponent(JmsConfiguration configuration) {
 70  9
         return new JmsComponent(configuration);
 71  
     }
 72  
 
 73  
     /**
 74  
      * Static builder method
 75  
      */
 76  
     public static JmsComponent jmsComponent(ConnectionFactory connectionFactory) {
 77  0
         return jmsComponent(new JmsConfiguration(connectionFactory));
 78  
     }
 79  
 
 80  
     /**
 81  
      * Static builder method
 82  
      */
 83  
     public static JmsComponent jmsComponentClientAcknowledge(ConnectionFactory connectionFactory) {
 84  4
         JmsConfiguration template = new JmsConfiguration(connectionFactory);
 85  4
         template.setAcknowledgementMode(Session.CLIENT_ACKNOWLEDGE);
 86  4
         return jmsComponent(template);
 87  
     }
 88  
 
 89  
     /**
 90  
      * Static builder method
 91  
      */
 92  
     public static JmsComponent jmsComponentAutoAcknowledge(ConnectionFactory connectionFactory) {
 93  0
         JmsConfiguration template = new JmsConfiguration(connectionFactory);
 94  0
         template.setAcknowledgementMode(Session.AUTO_ACKNOWLEDGE);
 95  0
         return jmsComponent(template);
 96  
     }
 97  
 
 98  
     public static JmsComponent jmsComponentTransacted(ConnectionFactory connectionFactory) {
 99  0
         JmsConfiguration template = new JmsConfiguration(connectionFactory);
 100  0
         template.setTransacted(true);
 101  0
         return jmsComponent(template);
 102  
     }
 103  
 
 104  
     public static JmsComponent jmsComponentTransacted(ConnectionFactory connectionFactory, PlatformTransactionManager transactionManager) {
 105  5
         JmsConfiguration template = new JmsConfiguration(connectionFactory);
 106  5
         template.setTransactionManager(transactionManager);
 107  5
         template.setTransacted(true);
 108  5
         return jmsComponent(template);
 109  
     }
 110  
 
 111  
     @Override
 112  
     protected Endpoint<JmsExchange> createEndpoint(String uri, String remaining, Map parameters) throws Exception {
 113  
 
 114  133
         boolean pubSubDomain = false;
 115  133
         if (remaining.startsWith(QUEUE_PREFIX)) {
 116  109
             pubSubDomain = false;
 117  109
             remaining = removeStartingCharacters(remaining.substring(QUEUE_PREFIX.length()), '/');
 118  109
         } else if (remaining.startsWith(TOPIC_PREFIX)) {
 119  24
             pubSubDomain = true;
 120  24
             remaining = removeStartingCharacters(remaining.substring(TOPIC_PREFIX.length()), '/');
 121  
         }
 122  
 
 123  133
         final String subject = convertPathToActualDestination(remaining);
 124  
 
 125  
         // lets make sure we copy the configuration as each endpoint can
 126  
         // customize its own version
 127  133
         JmsEndpoint endpoint = new JmsEndpoint(uri, this, subject, pubSubDomain, getConfiguration().copy());
 128  
 
 129  133
         String selector = (String)parameters.remove("selector");
 130  133
         if (selector != null) {
 131  0
             endpoint.setSelector(selector);
 132  
         }
 133  133
         IntrospectionSupport.setProperties(endpoint.getConfiguration(), parameters);
 134  133
         return endpoint;
 135  
     }
 136  
 
 137  
     public JmsConfiguration getConfiguration() {
 138  142
         if (configuration == null) {
 139  4
             configuration = createConfiguration();
 140  
         }
 141  142
         return configuration;
 142  
     }
 143  
 
 144  
     /**
 145  
      * Sets the JMS configuration
 146  
      * 
 147  
      * @param configuration the configuration to use by default for endpoints
 148  
      */
 149  
     public void setConfiguration(JmsConfiguration configuration) {
 150  0
         this.configuration = configuration;
 151  0
     }
 152  
 
 153  
     public void setAcceptMessagesWhileStopping(boolean acceptMessagesWhileStopping) {
 154  0
         getConfiguration().setAcceptMessagesWhileStopping(acceptMessagesWhileStopping);
 155  0
     }
 156  
 
 157  
     public void setAcknowledgementMode(int consumerAcknowledgementMode) {
 158  0
         getConfiguration().setAcknowledgementMode(consumerAcknowledgementMode);
 159  0
     }
 160  
 
 161  
     public void setAcknowledgementModeName(String consumerAcknowledgementMode) {
 162  0
         getConfiguration().setAcknowledgementModeName(consumerAcknowledgementMode);
 163  0
     }
 164  
 
 165  
     public void setAutoStartup(boolean autoStartup) {
 166  0
         getConfiguration().setAutoStartup(autoStartup);
 167  0
     }
 168  
 
 169  
     public void setCacheLevel(int cacheLevel) {
 170  0
         getConfiguration().setCacheLevel(cacheLevel);
 171  0
     }
 172  
 
 173  
     public void setCacheLevelName(String cacheName) {
 174  0
         getConfiguration().setCacheLevelName(cacheName);
 175  0
     }
 176  
 
 177  
     public void setClientId(String consumerClientId) {
 178  0
         getConfiguration().setClientId(consumerClientId);
 179  0
     }
 180  
 
 181  
     public void setConcurrentConsumers(int concurrentConsumers) {
 182  0
         getConfiguration().setConcurrentConsumers(concurrentConsumers);
 183  0
     }
 184  
 
 185  
     public void setConnectionFactory(ConnectionFactory connectionFactory) {
 186  4
         getConfiguration().setConnectionFactory(connectionFactory);
 187  4
     }
 188  
 
 189  
     public void setConsumerType(ConsumerType consumerType) {
 190  0
         getConfiguration().setConsumerType(consumerType);
 191  0
     }
 192  
 
 193  
     public void setDeliveryPersistent(boolean deliveryPersistent) {
 194  0
         getConfiguration().setDeliveryPersistent(deliveryPersistent);
 195  0
     }
 196  
 
 197  
     public void setDurableSubscriptionName(String durableSubscriptionName) {
 198  0
         getConfiguration().setDurableSubscriptionName(durableSubscriptionName);
 199  0
     }
 200  
 
 201  
     public void setExceptionListener(ExceptionListener exceptionListener) {
 202  0
         getConfiguration().setExceptionListener(exceptionListener);
 203  0
     }
 204  
 
 205  
     public void setExplicitQosEnabled(boolean explicitQosEnabled) {
 206  0
         getConfiguration().setExplicitQosEnabled(explicitQosEnabled);
 207  0
     }
 208  
 
 209  
     public void setExposeListenerSession(boolean exposeListenerSession) {
 210  0
         getConfiguration().setExposeListenerSession(exposeListenerSession);
 211  0
     }
 212  
 
 213  
     public void setIdleTaskExecutionLimit(int idleTaskExecutionLimit) {
 214  0
         getConfiguration().setIdleTaskExecutionLimit(idleTaskExecutionLimit);
 215  0
     }
 216  
 
 217  
     public void setMaxConcurrentConsumers(int maxConcurrentConsumers) {
 218  0
         getConfiguration().setMaxConcurrentConsumers(maxConcurrentConsumers);
 219  0
     }
 220  
 
 221  
     public void setMaxMessagesPerTask(int maxMessagesPerTask) {
 222  0
         getConfiguration().setMaxMessagesPerTask(maxMessagesPerTask);
 223  0
     }
 224  
 
 225  
     public void setMessageConverter(MessageConverter messageConverter) {
 226  0
         getConfiguration().setMessageConverter(messageConverter);
 227  0
     }
 228  
 
 229  
     public void setMessageIdEnabled(boolean messageIdEnabled) {
 230  0
         getConfiguration().setMessageIdEnabled(messageIdEnabled);
 231  0
     }
 232  
 
 233  
     public void setMessageTimestampEnabled(boolean messageTimestampEnabled) {
 234  0
         getConfiguration().setMessageTimestampEnabled(messageTimestampEnabled);
 235  0
     }
 236  
 
 237  
     public void setPriority(int priority) {
 238  0
         getConfiguration().setPriority(priority);
 239  0
     }
 240  
 
 241  
     public void setPubSubNoLocal(boolean pubSubNoLocal) {
 242  0
         getConfiguration().setPubSubNoLocal(pubSubNoLocal);
 243  0
     }
 244  
 
 245  
     public void setReceiveTimeout(long receiveTimeout) {
 246  0
         getConfiguration().setReceiveTimeout(receiveTimeout);
 247  0
     }
 248  
 
 249  
     public void setRecoveryInterval(long recoveryInterval) {
 250  0
         getConfiguration().setRecoveryInterval(recoveryInterval);
 251  0
     }
 252  
 
 253  
     public void setServerSessionFactory(ServerSessionFactory serverSessionFactory) {
 254  0
         getConfiguration().setServerSessionFactory(serverSessionFactory);
 255  0
     }
 256  
 
 257  
     public void setSubscriptionDurable(boolean subscriptionDurable) {
 258  0
         getConfiguration().setSubscriptionDurable(subscriptionDurable);
 259  0
     }
 260  
 
 261  
     public void setTaskExecutor(TaskExecutor taskExecutor) {
 262  0
         getConfiguration().setTaskExecutor(taskExecutor);
 263  0
     }
 264  
 
 265  
     public void setTimeToLive(long timeToLive) {
 266  0
         getConfiguration().setTimeToLive(timeToLive);
 267  0
     }
 268  
 
 269  
     public void setTransacted(boolean consumerTransacted) {
 270  0
         getConfiguration().setTransacted(consumerTransacted);
 271  0
     }
 272  
 
 273  
     public void setTransactionManager(PlatformTransactionManager transactionManager) {
 274  0
         getConfiguration().setTransactionManager(transactionManager);
 275  0
     }
 276  
 
 277  
     public void setTransactionName(String transactionName) {
 278  0
         getConfiguration().setTransactionName(transactionName);
 279  0
     }
 280  
 
 281  
     public void setTransactionTimeout(int transactionTimeout) {
 282  0
         getConfiguration().setTransactionTimeout(transactionTimeout);
 283  0
     }
 284  
 
 285  
     public void setUseVersion102(boolean useVersion102) {
 286  0
         getConfiguration().setUseVersion102(useVersion102);
 287  0
     }
 288  
 
 289  
     /**
 290  
      * A strategy method allowing the URI destination to be translated into the
 291  
      * actual JMS destination name (say by looking up in JNDI or something)
 292  
      */
 293  
     protected String convertPathToActualDestination(String path) {
 294  133
         return path;
 295  
     }
 296  
 
 297  
     /**
 298  
      * Factory method to create the default configuration instance
 299  
      * 
 300  
      * @return a newly created configuration object which can then be further
 301  
      *         customized
 302  
      */
 303  
     protected JmsConfiguration createConfiguration() {
 304  4
         return new JmsConfiguration();
 305  
     }
 306  
 
 307  
 }