Repository: camel
Updated Branches:
  refs/heads/master 8eafcf906 -> e80ef2457


CMComponent must not rely on dependency injection as it should work out
of the box. 

README.md is updated in order to reflect new component name (
camel-cm-sms instead of camel-cm).

Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a818fa16
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a818fa16
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a818fa16

Branch: refs/heads/master
Commit: a818fa16eb2218d6590bc016a81b3224803ec2b2
Parents: 56fd413
Author: oalles <oal...@neivi.es>
Authored: Mon Mar 28 11:29:16 2016 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Tue Mar 29 08:20:15 2016 +0200

----------------------------------------------------------------------
 components/camel-cm-sms/README.md               | 12 +++-----
 .../apache/camel/component/cm/CMComponent.java  | 31 +++++++++++++++-----
 2 files changed, 27 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a818fa16/components/camel-cm-sms/README.md
----------------------------------------------------------------------
diff --git a/components/camel-cm-sms/README.md 
b/components/camel-cm-sms/README.md
index 63f9059..f587214 100644
--- a/components/camel-cm-sms/README.md
+++ b/components/camel-cm-sms/README.md
@@ -1,4 +1,4 @@
-# camel-cm
+# camel-cm-sms
 
 [Camel component](http://camel.apache.org/components.html) for the [CM SMS 
Gateway](https://www.cmtelecom.com). 
 
@@ -9,13 +9,13 @@ You must have a valid account.  More information are 
available at [CM Telecom](h
 ### URI Format
 
 ```
-cm://sgw01.cm.nl/gateway.ashx?defaultFrom=DefaultSender&defaultMaxNumberOfParts=8&productToken=2fb82162-754c-4c1b-806d-9cb7efd677f4
+cm-sms://sgw01.cm.nl/gateway.ashx?defaultFrom=DefaultSender&defaultMaxNumberOfParts=8&productToken=2fb82162-754c-4c1b-806d-9cb7efd677f4
 ```
 
 
 ### Endpoint Options
 
-CM endpoints act like a **producer** and support the following options.
+CM SMS endpoints act like a **producer** and support the following options.
 
 | Name  | Default Value | Description |
 | ------------- | ------------- | ------------- |
@@ -24,9 +24,5 @@ CM endpoints act like a **producer** and support the 
following options.
 | defaultMaxNumberOfParts  | 8 | If it is a [multipart 
message](https://dashboard.onlinesmsgateway.com/docs#send-a-message-multipart) 
forces the max number of parts to be sent. <p>The gateway will first check if a 
message is larger than 160 characters, if so, the message will be cut into 
multiple 153 characters parts limited by these parameters whether the message 
is [GSM 0038 encodeable](https://en.wikipedia.org/wiki/GSM_03.38). 
<p>Otherwise, The gateway will check if a message is larger than 70 characters, 
if so, the message will be cut into multiple 67 characters parts to a maximum 
of this parameter.|
 | testConnectionOnStartup | false | This ensures that Camel is not started 
with failed connections cause an exception is thrown on startup. | 
 
-### Tests
-
-Tests provided so far show a valid [Spring 
Configuration](https://github.com/oalles/camel-cm/blob/master/src/test/java/org/apache/camel/component/cm/test/TestConfiguration.java).
 Notice that CM Component URI is built from properties in a 
[file](https://github.com/oalles/camel-cm/blob/master/src/test/resources/cm-smsgw.properties).
 
-
 ### Sample of Usage
-You can try [this project](https://github.com/oalles/camel-cm-sample) to see 
how camel-cm can be integrated in a camel route. 
\ No newline at end of file
+You can try [this project](https://github.com/oalles/camel-cm-sample) to see 
how camel-cm-sms can be integrated in a camel route. 
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/a818fa16/components/camel-cm-sms/src/main/java/org/apache/camel/component/cm/CMComponent.java
----------------------------------------------------------------------
diff --git 
a/components/camel-cm-sms/src/main/java/org/apache/camel/component/cm/CMComponent.java
 
b/components/camel-cm-sms/src/main/java/org/apache/camel/component/cm/CMComponent.java
index 5844dc9..ec431c2 100644
--- 
a/components/camel-cm-sms/src/main/java/org/apache/camel/component/cm/CMComponent.java
+++ 
b/components/camel-cm-sms/src/main/java/org/apache/camel/component/cm/CMComponent.java
@@ -18,10 +18,12 @@ package org.apache.camel.component.cm;
 
 import java.util.Map;
 import java.util.Set;
+
 import javax.validation.ConstraintViolation;
+import javax.validation.Validation;
 import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
 
-import org.apache.camel.BeanInject;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.ResolveEndpointFailedException;
@@ -35,10 +37,9 @@ import org.slf4j.LoggerFactory;
  */
 public class CMComponent extends UriEndpointComponent {
 
-    private static final Logger LOG = 
LoggerFactory.getLogger(CMComponent.class);
+    private static final Logger LOG = LoggerFactory
+        .getLogger(CMComponent.class);
 
-    // TODO: Must not rely on dependency injection as it should work out of 
the box
-    @BeanInject
     private Validator validator;
 
     public CMComponent() {
@@ -53,11 +54,17 @@ public class CMComponent extends UriEndpointComponent {
      * Endpoints factory
      */
     @Override
-    protected Endpoint createEndpoint(final String uri, final String 
remaining, final Map<String, Object> parameters) throws Exception {
+    protected Endpoint createEndpoint(final String uri, final String remaining,
+                                      final Map<String, Object> parameters)
+        throws Exception {
 
         LOG.debug("Creating CM Endpoint ... ");
 
-        LOG.debug("Uri=[{}], path=[{}], parameters=[{}]", new Object[] 
{URISupport.sanitizeUri(uri), URISupport.sanitizePath(remaining), parameters });
+        LOG.debug("Uri=[{}], path=[{}], parameters=[{}]",
+                  new Object[] {URISupport.sanitizeUri(uri),
+                                URISupport
+                                    .sanitizePath(remaining),
+                                parameters});
 
         // Set configuration based on uri parameters
         final CMConfiguration config = new CMConfiguration();
@@ -65,11 +72,14 @@ public class CMComponent extends UriEndpointComponent {
 
         // Validate configuration
         LOG.debug("Validating uri based configuration");
-        final Set<ConstraintViolation<CMConfiguration>> constraintViolations = 
validator.validate(config);
+        final Set<ConstraintViolation<CMConfiguration>> constraintViolations = 
getValidator()
+            .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()));
+                msg.append(String.format("- Invalid value for %s: %s",
+                                         cv.getPropertyPath().toString(),
+                                         cv.getMessage()));
             }
             throw new ResolveEndpointFailedException(uri, msg.toString());
         }
@@ -87,6 +97,11 @@ public class CMComponent extends UriEndpointComponent {
     }
 
     public Validator getValidator() {
+        if (validator == null) {
+            ValidatorFactory factory = Validation
+                .buildDefaultValidatorFactory();
+            validator = factory.getValidator();
+        }
         return validator;
     }
 

Reply via email to