camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hadr...@apache.org
Subject svn commit: r1166508 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/util/ components/camel-ahc/src/main/java/org/apache/camel/component/ahc/ components/camel-ahc/src/main/java/org/apache/cam...
Date Thu, 08 Sep 2011 03:04:39 GMT
Author: hadrian
Date: Thu Sep  8 03:04:39 2011
New Revision: 1166508

URL: http://svn.apache.org/viewvc?rev=1166508&view=rev
Log:
CAMEL-4425. Added a preProcessUri method to support per Component conversion of invalid URIs

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/URISupport.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/UnsafeUriCharactersEncoder.java
    camel/trunk/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/DefaultAhcBinding.java
    camel/trunk/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/helper/AhcHelper.java
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerRouterTest.java
    camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java?rev=1166508&r1=1166507&r2=1166508&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java Thu Sep
 8 03:04:39 2011
@@ -52,14 +52,23 @@ public abstract class DefaultComponent e
         this.camelContext = context;
     }
 
-    public Endpoint createEndpoint(String uri) throws Exception {
-        ObjectHelper.notNull(getCamelContext(), "camelContext");
+    @Deprecated
+    protected String preProcessUri(String uri) {
+        // Give components a chance to preprocess URIs and migrate to URI syntax that discourages
invalid URIs
+        // (see CAMEL-4425)
         // check URI string to the unsafe URI characters
         String encodedUri = UnsafeUriCharactersEncoder.encode(uri);
         if (!encodedUri.equals(uri)) {
             // uri supplied is not really valid
             LOG.warn("Supplied URI '{}' contains unsafe characters, please check encoding",
uri);
         }
+        return encodedUri;
+    }
+
+    public Endpoint createEndpoint(String uri) throws Exception {
+        ObjectHelper.notNull(getCamelContext(), "camelContext");
+        // check URI string to the unsafe URI characters
+        String encodedUri = preProcessUri(uri);
         URI u = new URI(encodedUri);
         String path = u.getSchemeSpecificPart();
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/URISupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/URISupport.java?rev=1166508&r1=1166507&r2=1166508&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/URISupport.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/URISupport.java Thu Sep  8
03:04:39 2011
@@ -230,9 +230,10 @@ public final class URISupport {
      * @param uri the uri
      * @return the normalized uri
      * @throws URISyntaxException in thrown if the uri syntax is invalid
+     * @throws UnsupportedEncodingException 
      */
     @SuppressWarnings("unchecked")
-    public static String normalizeUri(String uri) throws URISyntaxException {
+    public static String normalizeUri(String uri) throws URISyntaxException, UnsupportedEncodingException
{
 
         URI u = new URI(UnsafeUriCharactersEncoder.encode(uri));
         String path = u.getSchemeSpecificPart();
@@ -251,6 +252,7 @@ public final class URISupport {
         if (idx > 0) {
             path = path.substring(0, idx);
         }
+        path = UnsafeUriCharactersEncoder.encode(path);
 
         // in case there are parameters we should reorder them
         Map parameters = URISupport.parseParameters(u);

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/UnsafeUriCharactersEncoder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/UnsafeUriCharactersEncoder.java?rev=1166508&r1=1166507&r2=1166508&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/UnsafeUriCharactersEncoder.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/UnsafeUriCharactersEncoder.java
Thu Sep  8 03:04:39 2011
@@ -33,7 +33,7 @@ public final class UnsafeUriCharactersEn
         unsafeCharacters.set('<');
         unsafeCharacters.set('>');
         unsafeCharacters.set('#');
-        unsafeCharacters.set('%');
+        // unsafeCharacters.set('%');
         unsafeCharacters.set('{');
         unsafeCharacters.set('}');
         unsafeCharacters.set('|');

Modified: camel/trunk/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/DefaultAhcBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/DefaultAhcBinding.java?rev=1166508&r1=1166507&r2=1166508&view=diff
==============================================================================
--- camel/trunk/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/DefaultAhcBinding.java
(original)
+++ camel/trunk/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/DefaultAhcBinding.java
Thu Sep  8 03:04:39 2011
@@ -23,7 +23,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.Serializable;
 import java.io.UnsupportedEncodingException;
-import java.net.URISyntaxException;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -64,7 +63,7 @@ public class DefaultAhcBinding implement
             String url = AhcHelper.createURL(exchange, endpoint);
             log.trace("Setting url {}", url);
             builder.setUrl(url);
-        } catch (URISyntaxException e) {
+        } catch (Exception e) {
             throw new CamelExchangeException("Error creating URL", exchange, e);
         }
         String method = extractMethod(exchange);

Modified: camel/trunk/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/helper/AhcHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/helper/AhcHelper.java?rev=1166508&r1=1166507&r2=1166508&view=diff
==============================================================================
--- camel/trunk/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/helper/AhcHelper.java
(original)
+++ camel/trunk/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/helper/AhcHelper.java
Thu Sep  8 03:04:39 2011
@@ -21,6 +21,7 @@ import java.io.InputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
 import java.net.URI;
 import java.net.URISyntaxException;
 
@@ -96,8 +97,9 @@ public final class AhcHelper {
      * @param endpoint the endpoint
      * @return the URL to invoke
      * @throws java.net.URISyntaxException is thrown if the URL is invalid
+     * @throws UnsupportedEncodingException 
      */
-    public static String createURL(Exchange exchange, AhcEndpoint endpoint) throws URISyntaxException
{
+    public static String createURL(Exchange exchange, AhcEndpoint endpoint) throws URISyntaxException,
UnsupportedEncodingException {
         String url = doCreateURL(exchange, endpoint);
         return URISupport.normalizeUri(url);
     }

Modified: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerRouterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerRouterTest.java?rev=1166508&r1=1166507&r2=1166508&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerRouterTest.java
(original)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerRouterTest.java
Thu Sep  8 03:04:39 2011
@@ -78,7 +78,7 @@ public class CxfProducerRouterTest exten
     }
     
     @Test
-    public void testCxfEndpointUris() throws URISyntaxException {
+    public void testCxfEndpointUris() throws Exception {
         CxfEndpoint endpoint = context.getEndpoint(getSimpleEndpointUri(), CxfEndpoint.class);
         assertEquals("Get a wrong endpoint uri", getSimpleEndpointUri(), endpoint.getEndpointUri());
         

Modified: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java?rev=1166508&r1=1166507&r2=1166508&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
(original)
+++ camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
Thu Sep  8 03:04:39 2011
@@ -38,6 +38,7 @@ import org.apache.camel.util.CastUtils;
 import org.apache.camel.util.IntrospectionSupport;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.URISupport;
+import org.apache.camel.util.UnsafeUriCharactersEncoder;
 import org.apache.camel.util.jsse.SSLContextParameters;
 import org.eclipse.jetty.client.Address;
 import org.eclipse.jetty.client.HttpClient;
@@ -128,7 +129,6 @@ public class JettyHttpComponent extends 
 
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object>
parameters) throws Exception {
-        String addressUri = uri.startsWith("jetty:") ? remaining : uri;
         Map<String, Object> httpClientParameters = new HashMap<String, Object>(parameters);
         
         // must extract well known parameters before we create the endpoint
@@ -190,10 +190,12 @@ public class JettyHttpComponent extends 
         for (String key : parameters.keySet()) {
             httpClientParameters.remove(key);
         }
-        URI endpointUri = URISupport.createRemainingURI(new URI(addressUri), CastUtils.cast(httpClientParameters));
-        
+
+        String address = uri.startsWith("jetty:") ? remaining : uri;
+        URI addressUri = new URI(UnsafeUriCharactersEncoder.encode(address));
+        URI endpointUri = URISupport.createRemainingURI(addressUri, CastUtils.cast(httpClientParameters));
         // restructure uri to be based on the parameters left as we dont want to include
the Camel internal options
-        URI httpUri = URISupport.createRemainingURI(new URI(addressUri), CastUtils.cast(parameters));
+        URI httpUri = URISupport.createRemainingURI(addressUri, CastUtils.cast(parameters));
      
         // create endpoint after all known parameters have been extracted from parameters
         JettyHttpEndpoint endpoint = new JettyHttpEndpoint(this, endpointUri.toString(),
httpUri);



Mime
View raw message