Author: davsclaus Date: Sun Mar 3 07:29:23 2013 New Revision: 1452013 URL: http://svn.apache.org/r1452013 Log: CAMEL-6105: Direct component will throw specific exception if no direct consumer is available to process the Exchange. Thanks to Aaron Whiteside for the patch.
Added: camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectConsumerNotAvailableException.java Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectProducer.java camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/SendToNonExistingDirectEndpointTest.java Added: camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectConsumerNotAvailableException.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectConsumerNotAvailableException.java?rev=1452013&view=auto ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectConsumerNotAvailableException.java (added) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectConsumerNotAvailableException.java Sun Mar 3 07:29:23 2013 @@ -0,0 +1,32 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.direct; + +import org.apache.camel.CamelExchangeException; +import org.apache.camel.Exchange; + +/** + * Exception thrown when no consumers are available. + * + * @version + */ +public class DirectConsumerNotAvailableException extends CamelExchangeException { + + public DirectConsumerNotAvailableException(String message, Exchange exchange) { + super(message, exchange); + } +} \ No newline at end of file Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectProducer.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectProducer.java?rev=1452013&r1=1452012&r2=1452013&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectProducer.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectProducer.java Sun Mar 3 07:29:23 2013 @@ -18,7 +18,6 @@ package org.apache.camel.component.direc import org.apache.camel.AsyncCallback; import org.apache.camel.AsyncProcessor; -import org.apache.camel.CamelExchangeException; import org.apache.camel.Exchange; import org.apache.camel.impl.DefaultAsyncProducer; import org.apache.camel.util.AsyncProcessorConverterHelper; @@ -43,7 +42,7 @@ public class DirectProducer extends Defa public void process(Exchange exchange) throws Exception { if (endpoint.getConsumer() == null) { LOG.warn("No consumers available on endpoint: " + endpoint + " to process: " + exchange); - throw new CamelExchangeException("No consumers available on endpoint: " + endpoint, exchange); + throw new DirectConsumerNotAvailableException("No consumers available on endpoint: " + endpoint, exchange); } else { endpoint.getConsumer().getProcessor().process(exchange); } @@ -53,7 +52,7 @@ public class DirectProducer extends Defa if (endpoint.getConsumer() == null) { LOG.warn("No consumers available on endpoint: " + endpoint + " to process: " + exchange); // indicate its done synchronously - exchange.setException(new CamelExchangeException("No consumers available on endpoint: " + endpoint, exchange)); + exchange.setException(new DirectConsumerNotAvailableException("No consumers available on endpoint: " + endpoint, exchange)); callback.done(true); return true; } else { Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/SendToNonExistingDirectEndpointTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/SendToNonExistingDirectEndpointTest.java?rev=1452013&r1=1452012&r2=1452013&view=diff ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/SendToNonExistingDirectEndpointTest.java (original) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/SendToNonExistingDirectEndpointTest.java Sun Mar 3 07:29:23 2013 @@ -35,7 +35,8 @@ public class SendToNonExistingDirectEndp template.sendBody("direct:foo", "Hello World"); fail("Should have thrown exception"); } catch (CamelExecutionException e) { - CamelExchangeException cause = assertIsInstanceOf(CamelExchangeException.class, e.getCause()); + DirectConsumerNotAvailableException cause = assertIsInstanceOf(DirectConsumerNotAvailableException.class, e.getCause()); + assertIsInstanceOf(CamelExchangeException.class, cause); // ensure backwards compatibility assertEquals("No consumers available on endpoint: Endpoint[direct://foo]. Exchange[Message: Hello World]", cause.getMessage()); assertNotNull(cause.getExchange()); }