Author: davsclaus
Date: Mon Apr 23 05:32:44 2012
New Revision: 1329069

URL: http://svn.apache.org/viewvc?rev=1329069&view=rev
Log:
CAMEL-5177: getEndpointUri returns the exact uri the endpoint was given. Avoid 
reparsing as well. Polished EndpointConfiguration to avoid using 
PropertyEditorTypeConverter directly.

Modified:
    camel/branches/camel-2.9.x/   (props changed)
    
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/EndpointConfiguration.java
    
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/ConfigurationHelper.java
    
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
    
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
    
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpointConfiguration.java
    
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/MappedEndpointConfiguration.java
    
camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/impl/ConfigurationHelperTest.java
    
camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/impl/EndpointConfigurationTest.java

Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
  Merged /camel/trunk:r1329068

Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: 
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/EndpointConfiguration.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/EndpointConfiguration.java?rev=1329069&r1=1329068&r2=1329069&view=diff
==============================================================================
--- 
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/EndpointConfiguration.java
 (original)
+++ 
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/EndpointConfiguration.java
 Mon Apr 23 05:32:44 2012
@@ -53,16 +53,18 @@ public interface EndpointConfiguration {
      *
      * @param name the parameter name
      * @return the configuration URI.
+     * @throws RuntimeCamelException is thrown if error getting the parameter
      */
-    <T> T getParameter(String name);
+    <T> T getParameter(String name) throws RuntimeCamelException;
 
     /**
      * Sets the value of a particular parameter.
      *
      * @param name  the parameter name
      * @param value the parameter value
+     * @throws RuntimeCamelException is thrown if error setting the parameter
      */
-    <T> void setParameter(String name, T value);
+    <T> void setParameter(String name, T value) throws RuntimeCamelException;
 
     /**
      * Returns the formatted configuration string of an {@link Endpoint}.

Modified: 
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/ConfigurationHelper.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/ConfigurationHelper.java?rev=1329069&r1=1329068&r2=1329069&view=diff
==============================================================================
--- 
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/ConfigurationHelper.java
 (original)
+++ 
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/ConfigurationHelper.java
 Mon Apr 23 05:32:44 2012
@@ -17,19 +17,15 @@
 package org.apache.camel.impl;
 
 import java.lang.reflect.Field;
-import java.lang.reflect.Method;
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.util.Locale;
 import java.util.Map;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Component;
 import org.apache.camel.EndpointConfiguration;
 import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.TypeConverter;
 import org.apache.camel.URIField;
-import org.apache.camel.impl.converter.PropertyEditorTypeConverter;
 import org.apache.camel.util.IntrospectionSupport;
 import org.apache.camel.util.URISupport;
 import org.apache.camel.util.UnsafeUriCharactersEncoder;
@@ -43,14 +39,23 @@ import org.slf4j.LoggerFactory;
 public final class ConfigurationHelper {
 
     private static final Logger LOG = 
LoggerFactory.getLogger(ConfigurationHelper.class);
-    private static final TypeConverter TC = new PropertyEditorTypeConverter();
 
     private ConfigurationHelper() {
         //Utility Class
     }
 
     public interface ParameterSetter {
-        <T> void set(EndpointConfiguration config, String name, T value);
+
+        /**
+         * Sets the parameter on the configuration.
+         *
+         * @param camelContext  the camel context
+         * @param config        the configuration
+         * @param name          the name of the parameter
+         * @param value         the value to set
+         * @throws RuntimeCamelException is thrown if error setting the 
parameter
+         */
+        <T> void set(CamelContext camelContext, EndpointConfiguration config, 
String name, T value) throws RuntimeCamelException;
     }
 
     public static EndpointConfiguration createConfiguration(String uri, 
CamelContext context) throws Exception {
@@ -61,44 +66,41 @@ public final class ConfigurationHelper {
         }
         String scheme = uri.substring(0, schemeSeparator);
         
-        /* Temporary (maybe) workaround for unclear differentiation between 
URLs and URNs in Camel
-        String schemeSpecificPart = uri.substring(schemeSeparator + 1);
-        if (!schemeSpecificPart.startsWith("//")) {
-            uri = scheme + "://" + schemeSpecificPart;
-        } */
-
         Component component = context.getComponent(scheme);
-        LOG.trace("Lookup for Component handling \"{}:\" configuration 
returned {}", 
-            scheme, component != null ? component.getClass().getName() : 
"<null>");
-        DefaultEndpointConfiguration cfg = 
(DefaultEndpointConfiguration)component.createConfiguration(scheme);
-        // Should we be ok with URIs not properly encoded? (that method may 
need a bit of refactoring too)
-        cfg.setURI(new URI(UnsafeUriCharactersEncoder.encode(uri)));
-        return cfg;
-    }
-    
-    public static String formatConfigurationUri(EndpointConfiguration config, 
EndpointConfiguration.UriFormat format) {
-        return "TBD";
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("Lookup for Component handling \"{}:\" configuration 
returned {}",
+                new Object[]{scheme, component != null ? 
component.getClass().getName() : "<null>"});
+        }
+        if (component != null) {
+            DefaultEndpointConfiguration cfg = (DefaultEndpointConfiguration) 
component.createConfiguration(scheme);
+            // Should we be ok with URIs not properly encoded? (that method 
may need a bit of refactoring too)
+            cfg.setURI(new URI(UnsafeUriCharactersEncoder.encode(uri)));
+            return cfg;
+        } else {
+            // no component to create the configuration
+            return null;
+        }
     }
     
-    public static void populateFromURI(EndpointConfiguration config, 
ParameterSetter setter) {
+    public static void populateFromURI(CamelContext camelContext, 
EndpointConfiguration config, ParameterSetter setter) {
         URI uri = config.getURI();
         
-        setter.set(config, EndpointConfiguration.URI_SCHEME, uri.getScheme());
-        setter.set(config, EndpointConfiguration.URI_SCHEME_SPECIFIC_PART, 
uri.getSchemeSpecificPart());
-        setter.set(config, EndpointConfiguration.URI_AUTHORITY, 
uri.getAuthority());
-        setter.set(config, EndpointConfiguration.URI_USER_INFO, 
uri.getUserInfo());
-        setter.set(config, EndpointConfiguration.URI_HOST, uri.getHost());
-        setter.set(config, EndpointConfiguration.URI_PORT, 
Integer.toString(uri.getPort()));
-        setter.set(config, EndpointConfiguration.URI_PATH, uri.getPath());
-        setter.set(config, EndpointConfiguration.URI_QUERY, uri.getQuery());
-        setter.set(config, EndpointConfiguration.URI_FRAGMENT, 
uri.getFragment());
+        setter.set(camelContext, config, EndpointConfiguration.URI_SCHEME, 
uri.getScheme());
+        setter.set(camelContext, config, 
EndpointConfiguration.URI_SCHEME_SPECIFIC_PART, uri.getSchemeSpecificPart());
+        setter.set(camelContext, config, EndpointConfiguration.URI_AUTHORITY, 
uri.getAuthority());
+        setter.set(camelContext, config, EndpointConfiguration.URI_USER_INFO, 
uri.getUserInfo());
+        setter.set(camelContext, config, EndpointConfiguration.URI_HOST, 
uri.getHost());
+        setter.set(camelContext, config, EndpointConfiguration.URI_PORT, 
Integer.toString(uri.getPort()));
+        setter.set(camelContext, config, EndpointConfiguration.URI_PATH, 
uri.getPath());
+        setter.set(camelContext, config, EndpointConfiguration.URI_QUERY, 
uri.getQuery());
+        setter.set(camelContext, config, EndpointConfiguration.URI_FRAGMENT, 
uri.getFragment());
         
         // now parse query and set custom parameters
         Map<String, Object> parameters;
         try {
             parameters = URISupport.parseParameters(uri);
             for (Map.Entry<String, Object> pair : parameters.entrySet()) {
-                setter.set(config, pair.getKey(), pair.getValue());
+                setter.set(camelContext, config, pair.getKey(), 
pair.getValue());
             }
         } catch (URISyntaxException e) {
             throw new RuntimeCamelException(e);
@@ -110,16 +112,15 @@ public final class ConfigurationHelper {
             Class<?> clazz = config.getClass();
             Field[] fields = clazz.getDeclaredFields();
     
-            Field found = null;
-            URIField anno = null;
+            Field found;
+            URIField anno;
             for (final Field field : fields) {
                 anno = field.getAnnotation(URIField.class);
                 if (anno == null ? field.getName().equals(name) : 
anno.component().equals(name) 
                     || 
(anno.component().equals(EndpointConfiguration.URI_QUERY) && 
anno.parameter().equals(name))) { 
     
                     found = field;
-                    LOG.trace("Found field {}.{} as candidate for parameter 
{}", 
-                        new Object[] {clazz.getName(), found != null ? 
found.getName() : "<null>", name});
+                    LOG.trace("Found field {}.{} as candidate for parameter 
{}", new Object[]{clazz.getName(), found.getName(), name});
                     return found;
                 }
             }
@@ -137,38 +138,29 @@ public final class ConfigurationHelper {
             try {
                 return IntrospectionSupport.getProperty(config, 
field.getName());
             } catch (Exception e) {
-                LOG.trace("Filed to invokd setter for field '{}'. Reason: {}", 
field.getName(), e);
+                throw new RuntimeCamelException("Failed to get property '" + 
field.getName() + "' on " + config + " due " + e.getMessage(), e);
             }
         }
-        // We cannot distinguish between a null returned as the actually value 
of a parameter
-        // or the configuration parameter not being present, but it doesn't 
make much of a difference.
-        // Use findConfigurationParameter(EndpointConfiguration, String) to 
find that out.
         return null;
     }
 
-    public static <T> void setConfigurationField(EndpointConfiguration config, 
-        String name, T value) {
-
+    public static <T> void setConfigurationField(CamelContext camelContext, 
EndpointConfiguration config, String name, T value) {
         Field field = findConfigurationField(config, name);
         if (field == null) {
             return;
         }
 
-        // now try to set the field value
         try {
-            String setterName = "set" + name.substring(0, 
1).toUpperCase(Locale.ENGLISH) + name.substring(1);
-            Method setter = config.getClass().getMethod(setterName, 
field.getType());
-            setter.invoke(config, TC.convertTo(field.getType(), value));
+            IntrospectionSupport.setProperty(camelContext.getTypeConverter(), 
config, name, value);
         } catch (Exception e) {
-            LOG.trace("Filed to invokd setter for field '{}'. Reason: {}", 
name, e);
-            return;
+            throw new RuntimeCamelException("Failed to set property '" + name 
+ "' on " + config + " due " + e.getMessage(), e);
         }
     }
     
     public static class FieldParameterSetter implements ParameterSetter {
         @Override
-        public <T> void set(EndpointConfiguration config, String name, T 
value) {
-            setConfigurationField(config, name, value);
+        public <T> void set(CamelContext camelContext, EndpointConfiguration 
config, String name, T value) {
+            setConfigurationField(camelContext, config, name, value);
         }
     }
 }

Modified: 
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java?rev=1329069&r1=1329068&r2=1329069&view=diff
==============================================================================
--- 
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
 (original)
+++ 
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
 Mon Apr 23 05:32:44 2012
@@ -111,7 +111,7 @@ public abstract class DefaultComponent e
     }
 
     public EndpointConfiguration createConfiguration(String uri) throws 
Exception {
-        MappedEndpointConfiguration config = new 
MappedEndpointConfiguration(this);
+        MappedEndpointConfiguration config = new 
MappedEndpointConfiguration(getCamelContext());
         config.setURI(new URI(uri));
         return config;
     }

Modified: 
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java?rev=1329069&r1=1329068&r2=1329069&view=diff
==============================================================================
--- 
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
 (original)
+++ 
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
 Mon Apr 23 05:32:44 2012
@@ -18,7 +18,6 @@ package org.apache.camel.impl;
 
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
-import java.net.URI;
 import java.util.Map;
 
 import org.apache.camel.CamelContext;
@@ -26,11 +25,9 @@ import org.apache.camel.CamelContextAwar
 import org.apache.camel.Component;
 import org.apache.camel.Endpoint;
 import org.apache.camel.EndpointConfiguration;
-import org.apache.camel.EndpointConfiguration.UriFormat;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
 import org.apache.camel.PollingConsumer;
-import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.spi.HasId;
 import org.apache.camel.support.ServiceSupport;
 import org.apache.camel.util.EndpointHelper;
@@ -52,8 +49,8 @@ import org.apache.camel.util.URISupport;
  */
 public abstract class DefaultEndpoint extends ServiceSupport implements 
Endpoint, HasId, CamelContextAware {
 
-    // private String endpointUri;
-    private EndpointConfiguration config;
+    private String endpointUri;
+    private EndpointConfiguration endpointConfiguration;
     private CamelContext camelContext;
     private Component component;
     private ExchangePattern exchangePattern = ExchangePattern.InOnly;
@@ -145,19 +142,30 @@ public abstract class DefaultEndpoint ex
     }
 
     public String getEndpointUri() {
-        if (config == null) {
-            String uri = createEndpointUri();
-            if (uri == null) {
+        if (endpointUri == null) {
+            endpointUri = createEndpointUri();
+            if (endpointUri == null) {
                 throw new IllegalArgumentException("endpointUri is not 
specified and " + getClass().getName()
                     + " does not implement createEndpointUri() to create a 
default value");
             }
-            setEndpointUri(uri);
         }
-        return config.toUriString(UriFormat.Canonical);
+        return endpointUri;
     }
 
     public EndpointConfiguration getEndpointConfiguration() {
-        return config;
+        if (endpointConfiguration == null) {
+            endpointConfiguration = 
createEndpointConfiguration(getEndpointUri());
+        }
+        return endpointConfiguration;
+    }
+
+    /**
+     * Sets a custom {@link EndpointConfiguration}
+     *
+     * @param endpointConfiguration a custom endpoint configuration to be used.
+     */
+    public void setEndpointConfiguration(EndpointConfiguration 
endpointConfiguration) {
+        this.endpointConfiguration = endpointConfiguration;
     }
 
     public String getEndpointKey() {
@@ -283,6 +291,26 @@ public abstract class DefaultEndpoint ex
     }
 
     /**
+     * A factory method to lazily create the endpoint configuration if none is 
specified
+     */
+    protected EndpointConfiguration createEndpointConfiguration(String uri) {
+        // using this factory method to be backwards compatible with the old 
code
+        if (getComponent() != null) {
+            // prefer to use component endpoint configuration
+            try {
+                return getComponent().createConfiguration(uri);
+            } catch (Exception e) {
+                throw ObjectHelper.wrapRuntimeCamelException(e);
+            }
+        } else if (getCamelContext() != null) {
+            // fallback and use a mapped endpoint configuration
+            return new MappedEndpointConfiguration(getCamelContext(), uri);
+        }
+        // not configuration possible
+        return null;
+    }
+
+    /**
      * Sets the endpointUri if it has not been specified yet via some kind of
      * dependency injection mechanism. This allows dependency injection
      * frameworks such as Spring or Guice to set the default endpoint URI in
@@ -290,13 +318,7 @@ public abstract class DefaultEndpoint ex
      * in which an Endpoint is created.
      */
     public void setEndpointUriIfNotSpecified(String value) {
-        if (config == null) {
-            // FIXME: set the component first
-            // ObjectHelper.notNull(camelContext, "camelContext");
-            int s = value.indexOf(":");
-            if (camelContext != null && s > 0) {
-                component = camelContext.getComponent(value.substring(0, s));
-            }
+        if (endpointUri == null) {
             setEndpointUri(value);
         }
     }
@@ -305,21 +327,7 @@ public abstract class DefaultEndpoint ex
      * Sets the URI that created this endpoint.
      */
     protected void setEndpointUri(String endpointUri) {
-        if (endpointUri == null) {
-            config = null;
-            return;
-        }
-        try {
-            if (component != null) {
-                config = component.createConfiguration(endpointUri);
-            } else {
-                MappedEndpointConfiguration cfg = new 
MappedEndpointConfiguration(null);
-                cfg.setURI(new URI(endpointUri));
-                config = cfg;
-            }
-        } catch (Exception e) {
-            throw new RuntimeCamelException(e);
-        }
+        this.endpointUri = endpointUri;
     }
 
     public boolean isLenientProperties() {

Modified: 
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpointConfiguration.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpointConfiguration.java?rev=1329069&r1=1329068&r2=1329069&view=diff
==============================================================================
--- 
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpointConfiguration.java
 (original)
+++ 
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpointConfiguration.java
 Mon Apr 23 05:32:44 2012
@@ -19,9 +19,10 @@ package org.apache.camel.impl;
 import java.net.URI;
 import java.net.URISyntaxException;
 
-import org.apache.camel.Component;
+import org.apache.camel.CamelContext;
 import org.apache.camel.EndpointConfiguration;
 import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.util.ObjectHelper;
 
 /**
  * Default implementation of {@link EndpointConfiguration}.
@@ -30,15 +31,16 @@ import org.apache.camel.RuntimeCamelExce
  */
 public abstract class DefaultEndpointConfiguration implements 
EndpointConfiguration {
 
-    private Component component;
+    private final CamelContext camelContext;
     private URI uri;
-    
-    public DefaultEndpointConfiguration(Component component) {
-        this.component = component;
+
+    public DefaultEndpointConfiguration(CamelContext camelContext) {
+        ObjectHelper.notNull(camelContext, "CamelContext");
+        this.camelContext = camelContext;
     }
 
-    public DefaultEndpointConfiguration(Component component, String uri) {
-        this(component);
+    public DefaultEndpointConfiguration(CamelContext camelContext, String uri) 
{
+        this(camelContext);
         try {
             setURI(new URI(uri));
         } catch (URISyntaxException e) {
@@ -56,8 +58,12 @@ public abstract class DefaultEndpointCon
         parseURI();
     }
 
-    public void setComponent(Component component) {
-        this.component = component;
+    public void setURI(String uri) {
+        try {
+            setURI(new URI(uri));
+        } catch (URISyntaxException e) {
+            throw new RuntimeCamelException("Cannot parse uri: " + uri, e);
+        }
     }
 
     @Override
@@ -68,19 +74,14 @@ public abstract class DefaultEndpointCon
 
     @Override
     public <T> void setParameter(String name, T value) {
-        ConfigurationHelper.setConfigurationField(this, name, value);
-    }
-
-    @Override
-    public String toUriString(UriFormat format) {
-        return ConfigurationHelper.formatConfigurationUri(this, format);
+        ConfigurationHelper.setConfigurationField(camelContext, this, name, 
value);
     }
 
-    protected Component getComponent() {
-        return component;
+    protected CamelContext getCamelContext() {
+        return camelContext;
     }
 
     protected void parseURI() {
-        ConfigurationHelper.populateFromURI(this, new 
ConfigurationHelper.FieldParameterSetter());
+        ConfigurationHelper.populateFromURI(camelContext, this, new 
ConfigurationHelper.FieldParameterSetter());
     }
 }

Modified: 
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/MappedEndpointConfiguration.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/MappedEndpointConfiguration.java?rev=1329069&r1=1329068&r2=1329069&view=diff
==============================================================================
--- 
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/MappedEndpointConfiguration.java
 (original)
+++ 
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/MappedEndpointConfiguration.java
 Mon Apr 23 05:32:44 2012
@@ -18,15 +18,15 @@ package org.apache.camel.impl;
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.Component;
 import org.apache.camel.EndpointConfiguration;
 import org.apache.camel.TypeConverter;
-import org.apache.camel.impl.converter.PropertyEditorTypeConverter;
 import org.apache.camel.util.UnsafeUriCharactersEncoder;
 
 /**
@@ -34,16 +34,21 @@ import org.apache.camel.util.UnsafeUriCh
  * that did not yet define a configuration type.
  */
 public final class MappedEndpointConfiguration extends 
DefaultEndpointConfiguration {
-    private static final TypeConverter CONVERTER = new 
PropertyEditorTypeConverter();
-    private Map<String, Object> params = new ConcurrentHashMap<String, 
Object>();
+    // TODO: need 2 sets to differentiate between user keys and fixed keys
+    private Map<String, Object> params = new LinkedHashMap<String, Object>();
 
-    MappedEndpointConfiguration(Component component) {
-        super(component);
+    MappedEndpointConfiguration(CamelContext camelContext) {
+        super(camelContext);
+    }
+
+    MappedEndpointConfiguration(CamelContext camelContext, String uri) {
+        super(camelContext);
+        setURI(uri);
     }
 
     @SuppressWarnings("unchecked")
     public <T> T getParameter(String name) {
-        return (T)params.get(name);
+        return (T) params.get(name);
     }
 
     @Override
@@ -55,7 +60,7 @@ public final class MappedEndpointConfigu
     public boolean equals(Object other) {
         // if all parameters including scheme are the same, the component and 
uri must be the same too
         boolean eq = 
params.equals(((MappedEndpointConfiguration)other).params);
-        return this == other || (other != null && this.getClass() == 
other.getClass() && eq);
+        return this == other || (this.getClass() == other.getClass() && eq);
     }
 
     @Override
@@ -65,9 +70,9 @@ public final class MappedEndpointConfigu
 
     @Override
     protected void parseURI() {
-        ConfigurationHelper.populateFromURI(this, new 
ConfigurationHelper.ParameterSetter() {
+        ConfigurationHelper.populateFromURI(getCamelContext(), this, new 
ConfigurationHelper.ParameterSetter() {
             @Override
-            public <T> void set(EndpointConfiguration config, String name, T 
value) {
+            public <T> void set(CamelContext camelContext, 
EndpointConfiguration config, String name, T value) {
                 if (name != null && value != null) {
                     params.put(name, value);
                 }
@@ -86,16 +91,18 @@ public final class MappedEndpointConfigu
         String path = null;
         String fragment = null;
 
+        TypeConverter converter = getCamelContext().getTypeConverter();
+
         // Separate URI values from query parameters
         for (Map.Entry<String, Object> entry : entries) {
             String key = entry.getKey();
             Object value = entry.getValue();
             if (key.equals(EndpointConfiguration.URI_SCHEME)) {
-                scheme = CONVERTER.convertTo(String.class, value);
+                scheme = converter.convertTo(String.class, value);
             } else if 
(key.equals(EndpointConfiguration.URI_SCHEME_SPECIFIC_PART)) {
-                schemeSpecificPart = CONVERTER.convertTo(String.class, value);
+                schemeSpecificPart = converter.convertTo(String.class, value);
             } else if (key.equals(EndpointConfiguration.URI_AUTHORITY)) {
-                authority = CONVERTER.convertTo(String.class, value);
+                authority = converter.convertTo(String.class, value);
             } else if (key.equals(EndpointConfiguration.URI_USER_INFO)) {
                 // ignore, part of authority
             } else if (key.equals(EndpointConfiguration.URI_HOST)) {
@@ -103,11 +110,11 @@ public final class MappedEndpointConfigu
             } else if (key.equals(EndpointConfiguration.URI_PORT)) {
                 // ignore, part of authority
             } else if (key.equals(EndpointConfiguration.URI_PATH)) {
-                path = CONVERTER.convertTo(String.class, value);
+                path = converter.convertTo(String.class, value);
             } else if (key.equals(EndpointConfiguration.URI_QUERY)) {
                 // ignore, but this should not be the case, may be a good idea 
to log...
             } else if (key.equals(EndpointConfiguration.URI_FRAGMENT)) {
-                fragment = CONVERTER.convertTo(String.class, value);
+                fragment = converter.convertTo(String.class, value);
             } else {
                 // convert to "param=value" format here, order will be 
preserved
                 if (value instanceof List) {

Modified: 
camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/impl/ConfigurationHelperTest.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/impl/ConfigurationHelperTest.java?rev=1329069&r1=1329068&r2=1329069&view=diff
==============================================================================
--- 
camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/impl/ConfigurationHelperTest.java
 (original)
+++ 
camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/impl/ConfigurationHelperTest.java
 Mon Apr 23 05:32:44 2012
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.impl;
 
 import java.lang.reflect.Field;
@@ -36,7 +35,6 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
-
 public class ConfigurationHelperTest {
 
     private static final transient Logger LOG = 
LoggerFactory.getLogger(ConfigurationHelperTest.class);
@@ -138,10 +136,10 @@ public class ConfigurationHelperTest {
     @Test
     public void testConfigurationFormat() throws Exception {
         EndpointConfiguration config = 
ConfigurationHelper.createConfiguration("uri-dump:foo", context);
-        assertEquals("TBD", 
config.toUriString(EndpointConfiguration.UriFormat.Canonical));
-        assertEquals("TBD", 
config.toUriString(EndpointConfiguration.UriFormat.Provider));
-        assertEquals("TBD", 
config.toUriString(EndpointConfiguration.UriFormat.Consumer));
-        assertEquals("TBD", 
config.toUriString(EndpointConfiguration.UriFormat.Complete));
+        assertEquals(null, 
config.toUriString(EndpointConfiguration.UriFormat.Canonical));
+        assertEquals(null, 
config.toUriString(EndpointConfiguration.UriFormat.Provider));
+        assertEquals(null, 
config.toUriString(EndpointConfiguration.UriFormat.Consumer));
+        assertEquals(null, 
config.toUriString(EndpointConfiguration.UriFormat.Complete));
     }
 
     @Test
@@ -235,9 +233,9 @@ public class ConfigurationHelperTest {
         @Override
         public EndpointConfiguration createConfiguration(String uri) throws 
Exception {
             if (uri.equals(URIDUMP_SCHEME)) {
-                return new UriDumpConfiguration(this);
+                return new UriDumpConfiguration(getCamelContext());
             } else if (uri.equals(DUMMY_SCHEME)) {
-                return new DummyConfiguration(this);
+                return new DummyConfiguration(getCamelContext());
             }
             return null;
         }
@@ -254,8 +252,8 @@ public class ConfigurationHelperTest {
         private String query;
         private String fragment;
 
-        public UriDumpConfiguration(Component component) {
-            super(component);
+        public UriDumpConfiguration(CamelContext camelContext) {
+            super(camelContext);
         }
 
         public void setScheme(String scheme) {
@@ -329,6 +327,10 @@ public class ConfigurationHelperTest {
         public String getFragment() {
             return fragment;
         }
+
+        public String toUriString(UriFormat format) {
+            return null;
+        }
     }
 
     public static class DummyConfiguration extends 
DefaultEndpointConfiguration {
@@ -339,8 +341,8 @@ public class ConfigurationHelperTest {
         @URIField(component = "query", parameter = "second")
         private int second;
         
-        DummyConfiguration(Component component) {
-            super(component);
+        DummyConfiguration(CamelContext camelContext) {
+            super(camelContext);
         }
 
         public String getPath() {
@@ -366,5 +368,9 @@ public class ConfigurationHelperTest {
         public void setSecond(int second) {
             this.second = second;
         }
+
+        public String toUriString(UriFormat format) {
+            return null;
+        }
     }
 }

Modified: 
camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/impl/EndpointConfigurationTest.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/impl/EndpointConfigurationTest.java?rev=1329069&r1=1329068&r2=1329069&view=diff
==============================================================================
--- 
camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/impl/EndpointConfigurationTest.java
 (original)
+++ 
camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/impl/EndpointConfigurationTest.java
 Mon Apr 23 05:32:44 2012
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.impl;
 
 import org.apache.camel.CamelContext;
@@ -27,7 +26,6 @@ import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
 
-
 public class EndpointConfigurationTest {
 
     private static final String MAPPED_SCHEME = "mapped";    
@@ -59,7 +57,7 @@ public class EndpointConfigurationTest {
         EndpointConfiguration cfg2 = 
ConfigurationHelper.createConfiguration("mapped://foo?two=2&one=true", context);
         String uri1 = 
cfg1.toUriString(EndpointConfiguration.UriFormat.Complete);
         String uri2 = 
cfg2.toUriString(EndpointConfiguration.UriFormat.Complete);
-        assertEquals("Query paramater order should not matter", uri1, uri2);
+        assertEquals("Query parameter order should not matter", uri1, uri2);
     }
 
     private static class ConfiguredComponent implements Component {
@@ -82,7 +80,7 @@ public class EndpointConfigurationTest {
 
         @Override
         public EndpointConfiguration createConfiguration(String uri) throws 
Exception {
-            return new MappedEndpointConfiguration(this);
+            return new MappedEndpointConfiguration(getCamelContext());
         }
     }
 }


Reply via email to