Exception hierarchy is being revised. Invalid[URIEndpoint/URL]Exception are removed. Camel 's ResolveEndpointException is used instead.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/cf97b6da Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/cf97b6da Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/cf97b6da Branch: refs/heads/master Commit: cf97b6da4102683a3ba4350f49b077700c387f6f Parents: 32308ca Author: oalles <oal...@neivi.es> Authored: Tue Mar 22 12:53:17 2016 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Wed Mar 23 18:46:10 2016 +0100 ---------------------------------------------------------------------- .../apache/camel/component/cm/CMComponent.java | 7 +- .../cm/exceptions/CMValidationException.java | 40 ------- .../cm/exceptions/InvalidURLException.java | 30 ----- .../exceptions/InvalidUriEndpointException.java | 33 ------ .../apache/camel/component/cm/test/CMTest.java | 109 ++++++------------- 5 files changed, 36 insertions(+), 183 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/cf97b6da/components/camel-cm/src/main/java/org/apache/camel/component/cm/CMComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-cm/src/main/java/org/apache/camel/component/cm/CMComponent.java b/components/camel-cm/src/main/java/org/apache/camel/component/cm/CMComponent.java index fc7b9b5..ab26e14 100644 --- a/components/camel-cm/src/main/java/org/apache/camel/component/cm/CMComponent.java +++ b/components/camel-cm/src/main/java/org/apache/camel/component/cm/CMComponent.java @@ -25,8 +25,7 @@ import javax.validation.Validator; import org.apache.camel.BeanInject; import org.apache.camel.CamelContext; import org.apache.camel.Endpoint; -import org.apache.camel.component.cm.exceptions.InvalidURLException; -import org.apache.camel.component.cm.exceptions.InvalidUriEndpointException; +import org.apache.camel.ResolveEndpointFailedException; import org.apache.camel.impl.UriEndpointComponent; import org.apache.camel.util.URISupport; import org.apache.commons.validator.routines.UrlValidator; @@ -61,7 +60,7 @@ public class CMComponent extends UriEndpointComponent { final String url = CMConstants.DEFAULT_SCHEME + remaining; if (!UrlValidator.getInstance().isValid(url)) { - throw new InvalidURLException(String.format("HOST provided: %s seem to be invalid. Remember SCHEME has to be excluded.", url)); + throw new ResolveEndpointFailedException(uri, String.format("HOST provided: %s seem to be invalid. Remember SCHEME has to be excluded.", url)); } LOG.debug("Uri=[{}], path=[{}], parameters=[{}]", new Object[] {URISupport.sanitizeUri(uri), URISupport.sanitizePath(remaining), parameters }); @@ -78,7 +77,7 @@ public class CMComponent extends UriEndpointComponent { for (final ConstraintViolation<CMConfiguration> cv : constraintViolations) { msg.append(String.format("- Invalid value for %s: %s", cv.getPropertyPath().toString(), cv.getMessage())); } - throw new InvalidUriEndpointException(msg.toString()); + throw new ResolveEndpointFailedException(uri, msg.toString()); } LOG.debug("CMConfiguration - OK!"); http://git-wip-us.apache.org/repos/asf/camel/blob/cf97b6da/components/camel-cm/src/main/java/org/apache/camel/component/cm/exceptions/CMValidationException.java ---------------------------------------------------------------------- diff --git a/components/camel-cm/src/main/java/org/apache/camel/component/cm/exceptions/CMValidationException.java b/components/camel-cm/src/main/java/org/apache/camel/component/cm/exceptions/CMValidationException.java deleted file mode 100644 index 65cfaff..0000000 --- a/components/camel-cm/src/main/java/org/apache/camel/component/cm/exceptions/CMValidationException.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * 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.cm.exceptions; - -public class CMValidationException extends CMDirectException { - - public CMValidationException() { - } - - public CMValidationException(final String message) { - super(message); - } - - public CMValidationException(final Throwable cause) { - super(cause); - } - - public CMValidationException(final String message, final Throwable cause) { - super(message, cause); - } - - public CMValidationException(final String message, final Throwable cause, - final boolean enableSuppression, final boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/cf97b6da/components/camel-cm/src/main/java/org/apache/camel/component/cm/exceptions/InvalidURLException.java ---------------------------------------------------------------------- diff --git a/components/camel-cm/src/main/java/org/apache/camel/component/cm/exceptions/InvalidURLException.java b/components/camel-cm/src/main/java/org/apache/camel/component/cm/exceptions/InvalidURLException.java deleted file mode 100644 index 9f26a5b..0000000 --- a/components/camel-cm/src/main/java/org/apache/camel/component/cm/exceptions/InvalidURLException.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * 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.cm.exceptions; - -/** - * Invalid Resource URL - CM Hosts - */ -public class InvalidURLException extends InvalidUriEndpointException { - - public InvalidURLException() { - } - - public InvalidURLException(final String message) { - super(message); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/cf97b6da/components/camel-cm/src/main/java/org/apache/camel/component/cm/exceptions/InvalidUriEndpointException.java ---------------------------------------------------------------------- diff --git a/components/camel-cm/src/main/java/org/apache/camel/component/cm/exceptions/InvalidUriEndpointException.java b/components/camel-cm/src/main/java/org/apache/camel/component/cm/exceptions/InvalidUriEndpointException.java deleted file mode 100644 index 449df1b..0000000 --- a/components/camel-cm/src/main/java/org/apache/camel/component/cm/exceptions/InvalidUriEndpointException.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * 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.cm.exceptions; - -/** - * CM Camel component s configuration is based on URI. This exception is raised - * when the uri provided for configuration is wrong - * - */ -public class InvalidUriEndpointException extends CMValidationException { - - public InvalidUriEndpointException() { - super(); - } - - public InvalidUriEndpointException(final String message) { - super(message); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/cf97b6da/components/camel-cm/src/test/java/org/apache/camel/component/cm/test/CMTest.java ---------------------------------------------------------------------- diff --git a/components/camel-cm/src/test/java/org/apache/camel/component/cm/test/CMTest.java b/components/camel-cm/src/test/java/org/apache/camel/component/cm/test/CMTest.java index 9fac037..b6e9f1a 100644 --- a/components/camel-cm/src/test/java/org/apache/camel/component/cm/test/CMTest.java +++ b/components/camel-cm/src/test/java/org/apache/camel/component/cm/test/CMTest.java @@ -31,8 +31,6 @@ import org.apache.camel.Service; import org.apache.camel.component.cm.CMEndpoint; import org.apache.camel.component.cm.client.SMSMessage; import org.apache.camel.component.cm.exceptions.HostUnavailableException; -import org.apache.camel.component.cm.exceptions.InvalidURLException; -import org.apache.camel.component.cm.exceptions.InvalidUriEndpointException; import org.apache.camel.component.cm.exceptions.cmresponse.CMResponseException; import org.apache.camel.component.cm.exceptions.cmresponse.InsufficientBalanceException; import org.apache.camel.component.cm.exceptions.cmresponse.InvalidMSISDNException; @@ -64,8 +62,7 @@ import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; import org.springframework.util.Assert; @RunWith(CamelSpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { - CamelTestConfiguration.class }, loader = CamelSpringDelegatingTestContextLoader.class) +@ContextConfiguration(classes = {CamelTestConfiguration.class }, loader = CamelSpringDelegatingTestContextLoader.class) // @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) // @DisableJmx(false) // @MockEndpoints @@ -94,8 +91,7 @@ public class CMTest extends AbstractJUnit4SpringContextTests { public void beforeTest() throws Exception { mock.reset(); camelContext.startRoute(CamelTestConfiguration.SIMPLE_ROUTE_ID); - validNumber = pnu.format(pnu.getExampleNumber("ES"), - PhoneNumberFormat.E164); + validNumber = pnu.format(pnu.getExampleNumber("ES"), PhoneNumberFormat.E164); } @After @@ -121,7 +117,7 @@ public class CMTest extends AbstractJUnit4SpringContextTests { * 1. Invalid URI */ - @Test(expected = InvalidUriEndpointException.class) + @Test(expected = ResolveEndpointFailedException.class) public void testNotRequiredProductToken() throws Throwable { try { String schemedUri = "cm://sgw01.cm.nl/gateway.ashx?defaultFrom=MyBusiness&defaultMaxNumberOfParts=8&testConnectionOnStartup=true"; @@ -132,7 +128,7 @@ public class CMTest extends AbstractJUnit4SpringContextTests { } - @Test(expected = InvalidUriEndpointException.class) + @Test(expected = ResolveEndpointFailedException.class) public void testNotRequiredDefaultFrom() throws Throwable { try { String schemedUri = "cm://sgw01.cm.nl/gateway.ashx?defaultFrom=MyBusiness&defaultMaxNumberOfParts=8&testConnectionOnStartup=true"; @@ -151,7 +147,7 @@ public class CMTest extends AbstractJUnit4SpringContextTests { service.start(); } - @Test(expected = InvalidURLException.class) + @Test(expected = ResolveEndpointFailedException.class) public void testInvalidHostDuplicateScheme() throws Throwable { // cm://sgw01.cm.nl/gateway.ashx?defaultFrom=MyBusiness&defaultMaxNumberOfParts=8&productToken=ea723fd7-da81-4826-89bc-fa7144e71c40&testConnectionOnStartup=true try { @@ -183,8 +179,7 @@ public class CMTest extends AbstractJUnit4SpringContextTests { public void testAsPartOfARoute() throws Exception { // Body - final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), - generateUnicodeMessage(), validNumber, null); + final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), generateUnicodeMessage(), validNumber, null); cmProxy.send(smsMessage); } @@ -192,15 +187,11 @@ public class CMTest extends AbstractJUnit4SpringContextTests { public void testNoAccountFoundForProductTokenException() throws Exception { // Change sending strategy - CMEndpoint endpoint = (CMEndpoint) camelContext - .getEndpoint(applicationContext - .getBean(CamelTestConfiguration.class).getUri()); - endpoint.getProducer() - .setSender(new NoAccountFoundForProductTokenExceptionSender()); + CMEndpoint endpoint = (CMEndpoint) camelContext.getEndpoint(applicationContext.getBean(CamelTestConfiguration.class).getUri()); + endpoint.getProducer().setSender(new NoAccountFoundForProductTokenExceptionSender()); // Body - final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), - generateGSM0338Message(), validNumber, null); + final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), generateGSM0338Message(), validNumber, null); cmProxy.send(smsMessage); } @@ -212,14 +203,11 @@ public class CMTest extends AbstractJUnit4SpringContextTests { public void testCMResponseException() throws Exception { // Change sending strategy - CMEndpoint endpoint = (CMEndpoint) camelContext - .getEndpoint(applicationContext - .getBean(CamelTestConfiguration.class).getUri()); + CMEndpoint endpoint = (CMEndpoint) camelContext.getEndpoint(applicationContext.getBean(CamelTestConfiguration.class).getUri()); endpoint.getProducer().setSender(new CMResponseExceptionSender()); // Body - final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), - generateUnicodeMessage(), validNumber, null); + final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), generateUnicodeMessage(), validNumber, null); cmProxy.send(smsMessage); } @@ -227,15 +215,11 @@ public class CMTest extends AbstractJUnit4SpringContextTests { public void testInsufficientBalanceException() throws Exception { // Change sending strategy - CMEndpoint endpoint = (CMEndpoint) camelContext - .getEndpoint(applicationContext - .getBean(CamelTestConfiguration.class).getUri()); - endpoint.getProducer() - .setSender(new InsufficientBalanceExceptionSender()); + CMEndpoint endpoint = (CMEndpoint) camelContext.getEndpoint(applicationContext.getBean(CamelTestConfiguration.class).getUri()); + endpoint.getProducer().setSender(new InsufficientBalanceExceptionSender()); // Body - final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), - generateGSM0338Message(), validNumber, null); + final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), generateGSM0338Message(), validNumber, null); cmProxy.send(smsMessage); } @@ -243,14 +227,11 @@ public class CMTest extends AbstractJUnit4SpringContextTests { public void testInvalidMSISDNException() throws Exception { // Change sending strategy - CMEndpoint endpoint = (CMEndpoint) camelContext - .getEndpoint(applicationContext - .getBean(CamelTestConfiguration.class).getUri()); + CMEndpoint endpoint = (CMEndpoint) camelContext.getEndpoint(applicationContext.getBean(CamelTestConfiguration.class).getUri()); endpoint.getProducer().setSender(new InvalidMSISDNExceptionSender()); // Body - final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), - generateUnicodeMessage(), validNumber, null); + final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), generateUnicodeMessage(), validNumber, null); cmProxy.send(smsMessage); } @@ -258,15 +239,11 @@ public class CMTest extends AbstractJUnit4SpringContextTests { public void testInvalidProductTokenException() throws Exception { // Change sending strategy - CMEndpoint endpoint = (CMEndpoint) camelContext - .getEndpoint(applicationContext - .getBean(CamelTestConfiguration.class).getUri()); - endpoint.getProducer() - .setSender(new InvalidProductTokenExceptionSender()); + CMEndpoint endpoint = (CMEndpoint) camelContext.getEndpoint(applicationContext.getBean(CamelTestConfiguration.class).getUri()); + endpoint.getProducer().setSender(new InvalidProductTokenExceptionSender()); // Body - final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), - generateUnicodeMessage(), validNumber, null); + final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), generateUnicodeMessage(), validNumber, null); cmProxy.send(smsMessage); } @@ -274,14 +251,11 @@ public class CMTest extends AbstractJUnit4SpringContextTests { public void testNoMessageException() throws Exception { // Change sending strategy - CMEndpoint endpoint = (CMEndpoint) camelContext - .getEndpoint(applicationContext - .getBean(CamelTestConfiguration.class).getUri()); + CMEndpoint endpoint = (CMEndpoint) camelContext.getEndpoint(applicationContext.getBean(CamelTestConfiguration.class).getUri()); endpoint.getProducer().setSender(new NoMessageExceptionSender()); // Body - final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), - generateGSM0338Message(), validNumber, null); + final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), generateGSM0338Message(), validNumber, null); cmProxy.send(smsMessage); } @@ -289,15 +263,11 @@ public class CMTest extends AbstractJUnit4SpringContextTests { public void testNotPhoneNumberFoundException() throws Exception { // Change sending strategy - CMEndpoint endpoint = (CMEndpoint) camelContext - .getEndpoint(applicationContext - .getBean(CamelTestConfiguration.class).getUri()); - endpoint.getProducer() - .setSender(new NotPhoneNumberFoundExceptionSender()); + CMEndpoint endpoint = (CMEndpoint) camelContext.getEndpoint(applicationContext.getBean(CamelTestConfiguration.class).getUri()); + endpoint.getProducer().setSender(new NotPhoneNumberFoundExceptionSender()); // Body - final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), - generateUnicodeMessage(), validNumber, null); + final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), generateUnicodeMessage(), validNumber, null); cmProxy.send(smsMessage); } @@ -305,14 +275,11 @@ public class CMTest extends AbstractJUnit4SpringContextTests { public void testUnknownErrorException() throws Exception { // Change sending strategy - CMEndpoint endpoint = (CMEndpoint) camelContext - .getEndpoint(applicationContext - .getBean(CamelTestConfiguration.class).getUri()); + CMEndpoint endpoint = (CMEndpoint) camelContext.getEndpoint(applicationContext.getBean(CamelTestConfiguration.class).getUri()); endpoint.getProducer().setSender(new UnknownErrorExceptionSender()); // Body - final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), - generateGSM0338Message(), validNumber, null); + final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), generateGSM0338Message(), validNumber, null); cmProxy.send(smsMessage); } @@ -320,15 +287,11 @@ public class CMTest extends AbstractJUnit4SpringContextTests { public void testUnroutableMessageException() throws Exception { // Change sending strategy - CMEndpoint endpoint = (CMEndpoint) camelContext - .getEndpoint(applicationContext - .getBean(CamelTestConfiguration.class).getUri()); - endpoint.getProducer() - .setSender(new UnroutableMessageExceptionSender()); + CMEndpoint endpoint = (CMEndpoint) camelContext.getEndpoint(applicationContext.getBean(CamelTestConfiguration.class).getUri()); + endpoint.getProducer().setSender(new UnroutableMessageExceptionSender()); // Body - final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), - generateUnicodeMessage(), validNumber, null); + final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), generateUnicodeMessage(), validNumber, null); cmProxy.send(smsMessage); } @@ -336,9 +299,7 @@ public class CMTest extends AbstractJUnit4SpringContextTests { public void testCMEndpointIsForProducing() throws Exception { // Change sending strategy - CMEndpoint endpoint = (CMEndpoint) camelContext - .getEndpoint(applicationContext - .getBean(CamelTestConfiguration.class).getUri()); + CMEndpoint endpoint = (CMEndpoint) camelContext.getEndpoint(applicationContext.getBean(CamelTestConfiguration.class).getUri()); endpoint.createConsumer(null); } @@ -346,19 +307,15 @@ public class CMTest extends AbstractJUnit4SpringContextTests { public void testCMEndpointGetHost() throws Exception { // Change sending strategy - CMEndpoint endpoint = (CMEndpoint) camelContext - .getEndpoint(applicationContext - .getBean(CamelTestConfiguration.class).getUri()); - Assert.isTrue(endpoint.getHost().equals(applicationContext - .getEnvironment().getRequiredProperty("cm.url"))); + CMEndpoint endpoint = (CMEndpoint) camelContext.getEndpoint(applicationContext.getBean(CamelTestConfiguration.class).getUri()); + Assert.isTrue(endpoint.getHost().equals(applicationContext.getEnvironment().getRequiredProperty("cm.url"))); } @Test(expected = InvalidPayloadRuntimeException.class) public void testSendInvalidPayload() throws Exception { // Body - final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), - generateGSM0338Message(), null, null); + final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), generateGSM0338Message(), null, null); cmProxy.send(smsMessage); }