Author: wtam
Date: Tue Dec 30 19:21:12 2008
New Revision: 730301

URL: http://svn.apache.org/viewvc?rev=730301&view=rev
Log:
Merged revisions 730299 via svnmerge from 
https://svn.apache.org/repos/asf/activemq/camel/trunk

........
  r730299 | wtam | 2008-12-30 22:17:58 -0500 (Tue, 30 Dec 2008) | 1 line
  
  [CAMEL-1203] patch provided by Przemyslaw Budzik that enables basic 
authentication for Restlet endpoints
........

Added:
    
activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletConstants.java
      - copied unchanged from r730299, 
activemq/camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletConstants.java
    
activemq/camel/branches/camel-1.x/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletRouteBuilderAuthTest.java
      - copied unchanged from r730299, 
activemq/camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletRouteBuilderAuthTest.java
    
activemq/camel/branches/camel-1.x/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/route/
      - copied from r730299, 
activemq/camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/route/
    
activemq/camel/branches/camel-1.x/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/route/TestRouteBuilder.java
      - copied unchanged from r730299, 
activemq/camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/route/TestRouteBuilder.java
    
activemq/camel/branches/camel-1.x/components/camel-restlet/src/test/resources/org/
      - copied from r730299, 
activemq/camel/trunk/components/camel-restlet/src/test/resources/org/
    
activemq/camel/branches/camel-1.x/components/camel-restlet/src/test/resources/org/apache/
      - copied from r730299, 
activemq/camel/trunk/components/camel-restlet/src/test/resources/org/apache/
    
activemq/camel/branches/camel-1.x/components/camel-restlet/src/test/resources/org/apache/camel/
      - copied from r730299, 
activemq/camel/trunk/components/camel-restlet/src/test/resources/org/apache/camel/
    
activemq/camel/branches/camel-1.x/components/camel-restlet/src/test/resources/org/apache/camel/component/
      - copied from r730299, 
activemq/camel/trunk/components/camel-restlet/src/test/resources/org/apache/camel/component/
    
activemq/camel/branches/camel-1.x/components/camel-restlet/src/test/resources/org/apache/camel/component/restlet/
      - copied from r730299, 
activemq/camel/trunk/components/camel-restlet/src/test/resources/org/apache/camel/component/restlet/
    
activemq/camel/branches/camel-1.x/components/camel-restlet/src/test/resources/org/apache/camel/component/restlet/camel-context.xml
      - copied unchanged from r730299, 
activemq/camel/trunk/components/camel-restlet/src/test/resources/org/apache/camel/component/restlet/camel-context.xml
Modified:
    activemq/camel/branches/camel-1.x/   (props changed)
    activemq/camel/branches/camel-1.x/components/camel-restlet/pom.xml
    
activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
    
activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
    
activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletEndpoint.java

Propchange: activemq/camel/branches/camel-1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Dec 30 19:21:12 2008
@@ -1 +1 @@
-/activemq/camel/trunk:709850,711200,711206,711219-711220,711523,711531,711756,711784,711859,711874,711962,711971,712064,712119,712148,712662,712692,712925,713013,713107,713136,713273,713290,713292,713295,713314,713475,713625,713932,713944,714032,717965,717989,718242,718273,718312-718515,719163-719184,719334,719339,719524,719662,719848,719851,719855,719864,719978-719979,720207,720435-720437,720806,721272,721331,721333-721334,721360,721669,721764,721813,721985,722005,722070,722110,722415,722438,722726,722845,722878,723264,723314,723325-723327,723409,723835,723966,724122,724619,724681,725040,725309-725320,725340,725351,725569-725572,725612,725652-725660,725715,725883,726339,726640-726645,726932,727113,727375,727377,727624,727713,727946,729401,729892,730154,730275
+/activemq/camel/trunk:709850,711200,711206,711219-711220,711523,711531,711756,711784,711859,711874,711962,711971,712064,712119,712148,712662,712692,712925,713013,713107,713136,713273,713290,713292,713295,713314,713475,713625,713932,713944,714032,717965,717989,718242,718273,718312-718515,719163-719184,719334,719339,719524,719662,719848,719851,719855,719864,719978-719979,720207,720435-720437,720806,721272,721331,721333-721334,721360,721669,721764,721813,721985,722005,722070,722110,722415,722438,722726,722845,722878,723264,723314,723325-723327,723409,723835,723966,724122,724619,724681,725040,725309-725320,725340,725351,725569-725572,725612,725652-725660,725715,725883,726339,726640-726645,726932,727113,727375,727377,727624,727713,727946,729401,729892,730154,730275,730299

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

Modified: activemq/camel/branches/camel-1.x/components/camel-restlet/pom.xml
URL: 
http://svn.apache.org/viewvc/activemq/camel/branches/camel-1.x/components/camel-restlet/pom.xml?rev=730301&r1=730300&r2=730301&view=diff
==============================================================================
--- activemq/camel/branches/camel-1.x/components/camel-restlet/pom.xml 
(original)
+++ activemq/camel/branches/camel-1.x/components/camel-restlet/pom.xml Tue Dec 
30 19:21:12 2008
@@ -62,6 +62,19 @@
     </dependency>
 
     <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-spring</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-spring</artifactId>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
       <groupId>commons-logging</groupId>
       <artifactId>commons-logging</artifactId>
       <scope>test</scope>

Modified: 
activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java?rev=730301&r1=730300&r2=730301&view=diff
==============================================================================
--- 
activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
 (original)
+++ 
activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
 Tue Dec 30 19:21:12 2008
@@ -25,6 +25,8 @@
 import org.apache.camel.converter.jaxp.StringSource;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.restlet.data.ChallengeResponse;
+import org.restlet.data.ChallengeScheme;
 import org.restlet.data.Form;
 import org.restlet.data.MediaType;
 import org.restlet.data.Request;
@@ -105,6 +107,20 @@
             LOG.debug("Populate Restlet request from exchange body: " + body);
         }
         
+        String login = (String) exchange.getIn().removeHeader(
+                RestletConstants.LOGIN);
+        String password = (String) exchange.getIn().removeHeader(
+                RestletConstants.PASSWORD);
+          
+        if (login != null && password != null) {
+            ChallengeResponse authentication = new ChallengeResponse(
+                    ChallengeScheme.HTTP_BASIC, login, password);
+            request.setChallengeResponse(authentication);
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Basic HTTP Authentication has been applied");
+            }
+        }
+        
         for (Map.Entry<String, Object> entry : 
exchange.getIn().getHeaders().entrySet()) {
             form.add(entry.getKey(), entry.getValue().toString());
             if (LOG.isDebugEnabled()) {

Modified: 
activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java?rev=730301&r1=730300&r2=730301&view=diff
==============================================================================
--- 
activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
 (original)
+++ 
activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
 Tue Dec 30 19:21:12 2008
@@ -25,7 +25,10 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.restlet.Component;
+import org.restlet.Guard;
+import org.restlet.Restlet;
 import org.restlet.Server;
+import org.restlet.data.ChallengeScheme;
 import org.restlet.data.Method;
 import org.restlet.data.Protocol;
 
@@ -39,7 +42,7 @@
 
     private Map<String, Server> servers = new HashMap<String, Server>();
     private Map<String, MethodBasedRouter> routers = new HashMap<String, 
MethodBasedRouter>();
-
+    
     private Component component = new Component();
 
     @Override
@@ -52,18 +55,35 @@
         if (ref != null) {
             restletBinding = 
CamelContextHelper.mandatoryLookup(getCamelContext(), 
                     ref, RestletBinding.class);
+            if (restletBinding == null) {
+                LOG.warn("Binding '" + ref + "' cannot be found in the 
context");
+            }
         }
         
         if (restletBinding == null) {
             restletBinding = new DefaultRestletBinding();
         }
         
+        Map<String, String> realm = null;
+        ref = getAndRemoveParameter(parameters, "restletRealmRef", 
String.class);
+        if (ref != null) {
+            realm = CamelContextHelper.mandatoryLookup(getCamelContext(), ref, 
Map.class);
+            if (realm == null) {
+                LOG.warn("Realm '" + ref + "' cannot be found in the context");
+            }
+        }
+        
         Method method = getAndRemoveParameter(parameters, "restletMethod", 
Method.class);
         RestletEndpoint result = new RestletEndpoint(this, remaining, 
parameters, restletBinding);
+        
         if (method != null) {
             result.setRestletMethod(method);
         }
         
+        if (realm != null) {
+            result.setRealm(realm);
+        }
+                
         return result;
     }
     
@@ -91,7 +111,23 @@
         RestletEndpoint endpoint = (RestletEndpoint)consumer.getEndpoint();
         addServerIfNeccessary(endpoint);
         MethodBasedRouter router = getMethodRouter(endpoint.getUriPattern());
-        router.addRoute(endpoint.getRestletMethod(), consumer.getRestlet());
+        
+        Map<String, String> realm = endpoint.getRealm();
+        Restlet target = consumer.getRestlet();
+        if (realm != null && realm.size() > 0) {
+            Guard guard = new 
Guard(component.getContext().createChildContext(), 
+                    ChallengeScheme.HTTP_BASIC, "Camel-Restlet Endpoint 
Realm");
+            for (Map.Entry<String, String> entry : realm.entrySet()) {
+                guard.getSecrets().put(entry.getKey(), 
entry.getValue().toCharArray());
+            }
+            guard.setNext(target);
+            target = guard;
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Target has been set to guard: " + guard);
+            }
+        }
+        
+        router.addRoute(endpoint.getRestletMethod(), target);
         
         if (!router.hasBeenAttached()) {
             component.getDefaultHost().attach(endpoint.getUriPattern(), 
router);

Modified: 
activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletEndpoint.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletEndpoint.java?rev=730301&r1=730300&r2=730301&view=diff
==============================================================================
--- 
activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletEndpoint.java
 (original)
+++ 
activemq/camel/branches/camel-1.x/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletEndpoint.java
 Tue Dec 30 19:21:12 2008
@@ -45,6 +45,7 @@
     private int port = DEFAULT_PORT;
     private String uriPattern;
     private RestletBinding restletBinding;
+    private Map<String, String> realm;
     
     public RestletEndpoint(RestletComponent component, String remaining, 
             Map<String, String> parameters, RestletBinding restletBinding) 
throws Exception {
@@ -146,4 +147,19 @@
         return restletMethod;
     }
 
+    /**
+     * @param realm
+     */
+    public void setRealm(Map<String, String> realm) {
+        this.realm = realm;
+    }
+    
+    /**
+     * @return the realm
+     */
+    public Map<String, String> getRealm() {
+        return realm;
+    }
+
+
 }


Reply via email to