Fixing. Logging and throw. Do not log and throw error, just throw error. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a7f8c12e Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a7f8c12e Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a7f8c12e
Branch: refs/heads/master Commit: a7f8c12ef1aa43284dc8c5da397c19a5e33d7b5d Parents: a17572e Author: oalles <oal...@neivi.es> Authored: Mon Mar 21 12:45:35 2016 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Wed Mar 23 18:46:10 2016 +0100 ---------------------------------------------------------------------- .../apache/camel/component/cm/CMComponent.java | 213 ++++++++++--------- 1 file changed, 109 insertions(+), 104 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/a7f8c12e/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 ccd701f..8dd3b58 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 @@ -1,104 +1,109 @@ -/** - * 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; - -import java.util.Map; -import java.util.Set; - -import javax.validation.ConstraintViolation; -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.impl.UriEndpointComponent; -import org.apache.camel.util.URISupport; -import org.apache.commons.validator.routines.UrlValidator; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Represents the component that manages {@link CMEndpoint}s. - */ -public class CMComponent extends UriEndpointComponent { - - private static final Logger LOG = LoggerFactory.getLogger(CMComponent.class); - - @BeanInject - private Validator validator; - - // public CMComponent() { - // super(CMEndpoint.class); - // } - - public CMComponent(final CamelContext context) { - super(context, CMEndpoint.class); - } - - /** - * Endpoints factory - */ - @Override - protected Endpoint createEndpoint(final String uri, final String remaining, final Map<String, Object> parameters) throws Exception { - - LOG.info("Creating CM Endpoint ... "); - - final String url = CMConstants.DEFAULT_SCHEME + remaining; - if (!UrlValidator.getInstance().isValid(url)) { - final String errorMessage = String.format("HOST provided: %s seem to be invalid. Remember SCHEME has to be excluded.", url); - final Exception t = new InvalidURLException(errorMessage); - LOG.error(errorMessage, t); - throw t; - } - - LOG.info("Uri=[{}], path=[{}], parameters=[{}]", new Object[] {URISupport.sanitizeUri(uri), URISupport.sanitizePath(remaining), parameters }); - - // Set configuration based on uri parameters - final CMConfiguration config = new CMConfiguration(); - setProperties(config, parameters); - - // Validate configuration - LOG.info("Validating uri based configuration"); - final Set<ConstraintViolation<CMConfiguration>> constraintViolations = validator.validate(config); - if (constraintViolations.size() > 0) { - final StringBuffer msg = new StringBuffer(); - for (final ConstraintViolation<CMConfiguration> cv : constraintViolations) { - msg.append(String.format("- Invalid value for %s: %s", cv.getPropertyPath().toString(), cv.getMessage())); - } - LOG.error(msg.toString()); - throw new InvalidUriEndpointException(msg.toString()); - } - LOG.info("CMConfiguration - OK!"); - - // Component is an Endpoint factory. So far, just one Endpoint type. - // Endpoint construction and configuration. - - LOG.info("Creating CMEndpoint"); - final CMEndpoint endpoint = new CMEndpoint(uri, this); - endpoint.setConfiguration(config); - endpoint.setHost(remaining); - - return endpoint; - } - - public Validator getValidator() { - return validator; - } - -} +/** + * 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; + +import java.util.Map; +import java.util.Set; + +import javax.validation.ConstraintViolation; +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.impl.UriEndpointComponent; +import org.apache.camel.util.URISupport; +import org.apache.commons.validator.routines.UrlValidator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Represents the component that manages {@link CMEndpoint}s. + */ +public class CMComponent extends UriEndpointComponent { + + private static final Logger LOG = LoggerFactory + .getLogger(CMComponent.class); + + @BeanInject + private Validator validator; + + // public CMComponent() { + // super(CMEndpoint.class); + // } + + public CMComponent(final CamelContext context) { + super(context, CMEndpoint.class); + } + + /** + * Endpoints factory + */ + @Override + protected Endpoint createEndpoint(final String uri, final String remaining, + final Map<String, Object> parameters) throws Exception { + + LOG.info("Creating CM Endpoint ... "); + + 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)); + } + + LOG.info("Uri=[{}], path=[{}], parameters=[{}]", + new Object[] { URISupport.sanitizeUri(uri), + URISupport.sanitizePath(remaining), parameters }); + + // Set configuration based on uri parameters + final CMConfiguration config = new CMConfiguration(); + setProperties(config, parameters); + + // Validate configuration + LOG.info("Validating uri based configuration"); + final Set<ConstraintViolation<CMConfiguration>> constraintViolations = validator + .validate(config); + if (constraintViolations.size() > 0) { + final StringBuffer msg = new StringBuffer(); + for (final ConstraintViolation<CMConfiguration> cv : constraintViolations) { + msg.append(String.format("- Invalid value for %s: %s", + cv.getPropertyPath().toString(), cv.getMessage())); + } + LOG.error(msg.toString()); + throw new InvalidUriEndpointException(msg.toString()); + } + LOG.info("CMConfiguration - OK!"); + + // Component is an Endpoint factory. So far, just one Endpoint type. + // Endpoint construction and configuration. + + LOG.info("Creating CMEndpoint"); + final CMEndpoint endpoint = new CMEndpoint(uri, this); + endpoint.setConfiguration(config); + endpoint.setHost(remaining); + + return endpoint; + } + + public Validator getValidator() { + return validator; + } + +}