Author: davsclaus
Date: Mon Apr 23 06:57:40 2012
New Revision: 1329093

URL: http://svn.apache.org/viewvc?rev=1329093&view=rev
Log:
CAMEL-5183: Polished

Modified:
    camel/branches/camel-2.9.x/   (props changed)
    
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/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/EndpointConfigurationTest.java

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

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/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=1329093&r1=1329092&r2=1329093&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 06:57:40 2012
@@ -72,10 +72,11 @@ public final class ConfigurationHelper {
                 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;
+            EndpointConfiguration config = 
component.createConfiguration(scheme);
+            if (config instanceof DefaultEndpointConfiguration) {
+                ((DefaultEndpointConfiguration) config).setURI(uri);
+            }
+            return config;
         } else {
             // no component to create the configuration
             return null;

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=1329093&r1=1329092&r2=1329093&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 06:57:40 2012
@@ -23,6 +23,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.EndpointConfiguration;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.UnsafeUriCharactersEncoder;
 
 /**
  * Default implementation of {@link EndpointConfiguration}.
@@ -60,7 +61,8 @@ public abstract class DefaultEndpointCon
 
     public void setURI(String uri) {
         try {
-            setURI(new URI(uri));
+            String encoded = UnsafeUriCharactersEncoder.encode(uri);
+            setURI(new URI(encoded));
         } catch (URISyntaxException e) {
             throw new RuntimeCamelException("Cannot parse uri: " + uri, e);
         }

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=1329093&r1=1329092&r2=1329093&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 06:57:40 2012
@@ -126,15 +126,15 @@ public final class MappedEndpointConfigu
                 }
             }
         }
-        
+
         Collections.sort(queryParams);
         String q = "";
         for (String entry : queryParams) {
             q += q.length() == 0 ? "" : "&";
             q += entry;
         }
-        
-        StringBuffer u = new StringBuffer(1024);
+
+        StringBuffer u = new StringBuffer(64);
         if (scheme != null) {
             u.append(scheme); // SHOULD NOT be null
             u.append(":");
@@ -152,6 +152,10 @@ public final class MappedEndpointConfigu
                 u.append(fragment);
             }
         } else {
+            // add leading // if not provided
+            if (!schemeSpecificPart.startsWith("//")) {
+                u.append("//");
+            }
             u.append(schemeSpecificPart);
         }
         return u.toString();

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=1329093&r1=1329092&r2=1329093&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 06:57:40 2012
@@ -22,6 +22,7 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.EndpointConfiguration;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
@@ -60,6 +61,14 @@ public class EndpointConfigurationTest {
         assertEquals("Query parameter order should not matter", uri1, uri2);
     }
 
+    @Test
+    @Ignore("Fails due CAMEL-5183")
+    public void testConfigurationPortParameter() throws Exception {
+        EndpointConfiguration cfg1 = 
ConfigurationHelper.createConfiguration("mapped://foo:8080?one=true&two=2&port=123",
 context);
+        String uri1 = 
cfg1.toUriString(EndpointConfiguration.UriFormat.Complete);
+        assertEquals("mapped://foo:8080?one=true&port=123&two=2", uri1);
+    }
+
     private static class ConfiguredComponent implements Component {
         private CamelContext context;
 


Reply via email to