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