Author: davsclaus
Date: Tue Nov 10 07:22:33 2009
New Revision: 834374

URL: http://svn.apache.org/viewvc?rev=834374&view=rev
Log:
CAMEL-2150: Fixed rss/atom components sending camel parameters when using http.

Added:
    
camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomHttpConsumerTest.java
      - copied, changed from r834163, 
camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomPollingConsumerTest.java
    
camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomHttpNoCamelParametersTest.java
   (with props)
    
camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssHttpNoCamelParametersTest.java
   (with props)
Modified:
    
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
    
camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomComponent.java
    
camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomPollingConsumerTest.java
    
camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/RssComponent.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=834374&r1=834373&r2=834374&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
 Tue Nov 10 07:22:33 2009
@@ -93,10 +93,25 @@
             }
         }
 
+        afterConfiguration(uri, path, endpoint, parameters);
         return endpoint;
     }
 
     /**
+     * Strategy to do post configuration logic.
+     * <p/>
+     * Can be used to construct an URI based on the remaining parameters. For 
example the parameters that configures
+     * the endpoint have been removed from the parameters which which leaves 
it with only additional parameters.
+     *
+     * @param endpoint the created endpoint
+     * @param parameters the remaining parameters after the endpoint has been 
created and parsed the parameters
+     * @throws Exception can be thrown to indicate error creating the endpoint
+     */
+    protected void afterConfiguration(String uri, String remaining, Endpoint 
endpoint, Map parameters) throws Exception {
+        // noop
+    }
+
+    /**
      * Strategy for validation of parameters, that was not able to be resolved 
to any endpoint options.
      *
      * @param uri          the uri - the uri the end user provided untouched

Modified: 
camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomComponent.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomComponent.java?rev=834374&r1=834373&r2=834374&view=diff
==============================================================================
--- 
camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomComponent.java
 (original)
+++ 
camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomComponent.java
 Tue Nov 10 07:22:33 2009
@@ -19,6 +19,7 @@
 import java.net.URI;
 import java.util.Map;
 
+import org.apache.camel.Endpoint;
 import org.apache.camel.component.feed.FeedComponent;
 import org.apache.camel.component.feed.FeedEndpoint;
 import org.apache.camel.util.URISupport;
@@ -34,18 +35,28 @@
 
     @Override
     protected FeedEndpoint createEndpoint(String uri, String remaining, Map 
parameters) throws Exception {
+        return new AtomEndpoint(uri, this, null);
+    }
 
-        // Parameters should be kept in the remaining path, since they might 
be needed to get the actual ATOM feed
-        URI remainingUri = URISupport.createRemainingURI(new URI(remaining), 
parameters);
+    @Override
+    protected void afterConfiguration(String uri, String remaining, Endpoint 
endpoint, Map parameters) throws Exception {
+        AtomEndpoint atom = (AtomEndpoint) endpoint;
+        if (atom.getFeedUri() != null) {
+            // already set so do not change it
+            return;
+        }
 
-        // if http or https then the uri should include the parameters as we 
can have URI parameters
-        // that need to be sent to the remote server when retrieving feeds
-        String scheme = remainingUri.getScheme();
-        if (scheme != null && (scheme.equals("http") || 
scheme.equals("https"))) {
-            return new AtomEndpoint(uri, this, remainingUri.toString());
+        // recreate feed uri after we have configured the endpoint so we can 
use the left over parameters
+        // for the http feed
+        String feedUri;
+        if (!parameters.isEmpty()) {
+            URI remainingUri = URISupport.createRemainingURI(new 
URI(remaining), parameters);
+            feedUri = remainingUri.toString();
+        } else {
+            feedUri = remaining;
         }
 
-        return new AtomEndpoint(uri, this, remaining);
+        atom.setFeedUri(feedUri);
     }
 
 }

Copied: 
camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomHttpConsumerTest.java
 (from r834163, 
camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomPollingConsumerTest.java)
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomHttpConsumerTest.java?p2=camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomHttpConsumerTest.java&p1=camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomPollingConsumerTest.java&r1=834163&r2=834374&rev=834374&view=diff
==============================================================================
--- 
camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomPollingConsumerTest.java
 (original)
+++ 
camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomHttpConsumerTest.java
 Tue Nov 10 07:22:33 2009
@@ -16,57 +16,31 @@
  */
 package org.apache.camel.component.atom;
 
-import java.util.List;
-
-import org.apache.abdera.model.Feed;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Ignore;
 import org.junit.Test;
 
 /**
- * Unit test for AtomPollingConsumer
+ * Unit test for consuming from a http feed
  */
-public class AtomPollingConsumerTest extends CamelTestSupport {
+public class AtomHttpConsumerTest extends CamelTestSupport {
 
+    @Ignore("requires to be online for testing")
     @Test
-    public void testNoSplitEntries() throws Exception {
+    public void testHttpConsumer() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMessageCount(1);
         mock.assertIsSatisfied();
-
-        Exchange exchange = mock.getExchanges().get(0);
-        Message in = exchange.getIn();
-        assertNotNull(in);
-        assertTrue(in.getBody() instanceof List);
-        assertTrue(in.getHeader(AtomConstants.ATOM_FEED) instanceof Feed);
-
-        Feed feed = in.getHeader(AtomConstants.ATOM_FEED, Feed.class);
-        assertEquals("James Strachan", feed.getAuthor().getName());
-
-        List entries = in.getBody(List.class);
-        assertEquals(7, entries.size());
-    }
-
-    @Test
-    public void testUsingAtomUriParameter() throws Exception {
-        MockEndpoint mock = getMockEndpoint("mock:result2");
-        mock.expectedMessageCount(1);
-        mock.assertIsSatisfied();
     }
 
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
-                
from("atom:file:src/test/data/feed.atom?splitEntries=false").to("mock:result");
-
-                // this is a bit weird syntax that normally is not used using 
the feedUri parameter
-                
from("atom:?feedUri=file:src/test/data/feed.atom&splitEntries=false").to("mock:result2");
+                
from("atom:http://feeds2.feedburner.com/ApacheCamel.atom?splitEntries=false";).to("mock:result");
             }
         };
     }
 
-}
+}
\ No newline at end of file

Added: 
camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomHttpNoCamelParametersTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomHttpNoCamelParametersTest.java?rev=834374&view=auto
==============================================================================
--- 
camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomHttpNoCamelParametersTest.java
 (added)
+++ 
camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomHttpNoCamelParametersTest.java
 Tue Nov 10 07:22:33 2009
@@ -0,0 +1,47 @@
+/**
+ * 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.atom;
+
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class AtomHttpNoCamelParametersTest extends CamelTestSupport {
+
+    @Test
+    public void testAtomHttpNoCamelParameters() throws Exception {
+        AtomEndpoint atom = 
context.getEndpoint("atom://http://www.iafrica.com/pls/cms/grapevine.xml?sortEntries=true&feedHeader=true";,
 AtomEndpoint.class);
+        assertNotNull(atom);
+
+        assertEquals("http://www.iafrica.com/pls/cms/grapevine.xml";, 
atom.getFeedUri());
+        assertEquals(true, atom.isFeedHeader());
+        assertEquals(true, atom.isSortEntries());
+    }
+
+    @Test
+    public void testAtomHttpNoCamelParametersAndOneFeedParameter() throws 
Exception {
+        AtomEndpoint atom = 
context.getEndpoint("atom://http://www.iafrica.com/pls/cms/grapevine.xml?sortEntries=true&feedHeader=true&foo=bar";,
 AtomEndpoint.class);
+        assertNotNull(atom);
+
+        assertEquals("http://www.iafrica.com/pls/cms/grapevine.xml?foo=bar";, 
atom.getFeedUri());
+        assertEquals(true, atom.isFeedHeader());
+        assertEquals(true, atom.isSortEntries());
+    }
+
+}

Propchange: 
camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomHttpNoCamelParametersTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomHttpNoCamelParametersTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: 
camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomPollingConsumerTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomPollingConsumerTest.java?rev=834374&r1=834373&r2=834374&view=diff
==============================================================================
--- 
camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomPollingConsumerTest.java
 (original)
+++ 
camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomPollingConsumerTest.java
 Tue Nov 10 07:22:33 2009
@@ -58,6 +58,12 @@
         mock.assertIsSatisfied();
     }
 
+    @Test
+    public void testNoCamelParametersInFeedUri() throws Exception {
+        AtomEndpoint endpoint = 
context.getEndpoint("atom:file:src/test/data/feed.atom?splitEntries=false", 
AtomEndpoint.class);
+        assertEquals("file:src/test/data/feed.atom", endpoint.getFeedUri());
+    }
+
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {

Modified: 
camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/RssComponent.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/RssComponent.java?rev=834374&r1=834373&r2=834374&view=diff
==============================================================================
--- 
camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/RssComponent.java
 (original)
+++ 
camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/RssComponent.java
 Tue Nov 10 07:22:33 2009
@@ -19,6 +19,7 @@
 import java.net.URI;
 import java.util.Map;
 
+import org.apache.camel.Endpoint;
 import org.apache.camel.component.feed.FeedComponent;
 import org.apache.camel.component.feed.FeedEndpoint;
 import org.apache.camel.util.URISupport;
@@ -31,15 +32,28 @@
 public class RssComponent extends FeedComponent {
 
     protected FeedEndpoint createEndpoint(String uri, String remaining, Map 
parameters) throws Exception {
+        return new RssEndpoint(uri, this, null);
+    }
 
-        // Parameters should be kept in the remaining path, since they might 
be needed to get the actual RSS feed
-        URI remainingUri = URISupport.createRemainingURI(new URI(remaining), 
parameters);
+    @Override
+    protected void afterConfiguration(String uri, String remaining, Endpoint 
endpoint, Map parameters) throws Exception {
+        RssEndpoint rss = (RssEndpoint) endpoint;
+        if (rss.getFeedUri() != null) {
+            // already set so do not change it
+            return;
+        }
 
-        if (remainingUri.getScheme().equals("http") || 
remainingUri.getScheme().equals("https")) {
-            return new RssEndpoint(uri, this, remainingUri.toString());
+        // recreate feed uri after we have configured the endpoint so we can 
use the left over parameters
+        // for the http feed
+        String feedUri;
+        if (!parameters.isEmpty()) {
+            URI remainingUri = URISupport.createRemainingURI(new 
URI(remaining), parameters);
+            feedUri = remainingUri.toString();
+        } else {
+            feedUri = remaining;
         }
 
-        return new RssEndpoint(uri, this, remaining);
+        rss.setFeedUri(feedUri);
     }
-    
+
 }
\ No newline at end of file

Added: 
camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssHttpNoCamelParametersTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssHttpNoCamelParametersTest.java?rev=834374&view=auto
==============================================================================
--- 
camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssHttpNoCamelParametersTest.java
 (added)
+++ 
camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssHttpNoCamelParametersTest.java
 Tue Nov 10 07:22:33 2009
@@ -0,0 +1,47 @@
+/**
+ * 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.rss;
+
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class RssHttpNoCamelParametersTest extends CamelTestSupport {
+
+    @Test
+    public void testRssHttpNoCamelParameters() throws Exception {
+        RssEndpoint rss = 
context.getEndpoint("rss://http://www.iafrica.com/pls/cms/grapevine.xml?sortEntries=true&feedHeader=true";,
 RssEndpoint.class);
+        assertNotNull(rss);
+
+        assertEquals("http://www.iafrica.com/pls/cms/grapevine.xml";, 
rss.getFeedUri());
+        assertEquals(true, rss.isFeedHeader());
+        assertEquals(true, rss.isSortEntries());
+    }
+
+    @Test
+    public void testRssHttpNoCamelParametersAndOneFeedParameter() throws 
Exception {
+        RssEndpoint rss = 
context.getEndpoint("rss://http://www.iafrica.com/pls/cms/grapevine.xml?sortEntries=true&feedHeader=true&foo=bar";,
 RssEndpoint.class);
+        assertNotNull(rss);
+
+        assertEquals("http://www.iafrica.com/pls/cms/grapevine.xml?foo=bar";, 
rss.getFeedUri());
+        assertEquals(true, rss.isFeedHeader());
+        assertEquals(true, rss.isSortEntries());
+    }
+
+}

Propchange: 
camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssHttpNoCamelParametersTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssHttpNoCamelParametersTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date


Reply via email to