Author: davsclaus
Date: Tue Nov 17 05:04:58 2009
New Revision: 881156

URL: http://svn.apache.org/viewvc?rev=881156&view=rev
Log:
CAMEL-2175: Fixed initialization of restlet endpoint not being threadsafe.

Modified:
    
camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletEndpoint.java

Modified: 
camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletEndpoint.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletEndpoint.java?rev=881156&r1=881155&r2=881156&view=diff
==============================================================================
--- 
camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletEndpoint.java
 (original)
+++ 
camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletEndpoint.java
 Tue Nov 17 05:04:58 2009
@@ -18,12 +18,12 @@
 
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.camel.Consumer;
 import org.apache.camel.ExchangePattern;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
+import org.apache.camel.Service;
 import org.apache.camel.impl.DefaultEndpoint;
 import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.camel.spi.HeaderFilterStrategyAware;
@@ -36,7 +36,7 @@
  *
  * @version $Revision$
  */
-public class RestletEndpoint extends DefaultEndpoint implements 
HeaderFilterStrategyAware {
+public class RestletEndpoint extends DefaultEndpoint implements 
HeaderFilterStrategyAware, Service {
     private static final Log LOG = LogFactory.getLog(RestletEndpoint.class);
 
     private static final int DEFAULT_PORT = 80;
@@ -61,7 +61,6 @@
     private Map<String, String> restletRealm;
     private HeaderFilterStrategy headerFilterStrategy;
     private RestletBinding restletBinding;
-    private AtomicBoolean bindingInitialized = new AtomicBoolean(false);
 
     public RestletEndpoint(RestletComponent component, String remaining) 
throws Exception {
         super(remaining, component);
@@ -134,23 +133,11 @@
     }
 
     public RestletBinding getRestletBinding() {
-        if (restletBinding == null) {
-            restletBinding = new DefaultRestletBinding();   
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Create default Restlet Binding " + restletBinding);
-            }
-        }
-        
-        if (!bindingInitialized.getAndSet(true) 
-                && restletBinding instanceof HeaderFilterStrategyAware) {
-            
((HeaderFilterStrategyAware)restletBinding).setHeaderFilterStrategy(getHeaderFilterStrategy());
-        }
         return restletBinding;
     }
 
     public void setRestletBinding(RestletBinding restletBinding) {
         this.restletBinding = restletBinding;
-        bindingInitialized.set(false);
     }
 
     public void setHeaderFilterStrategy(HeaderFilterStrategy 
headerFilterStrategy) {
@@ -161,12 +148,6 @@
     }
 
     public HeaderFilterStrategy getHeaderFilterStrategy() {
-        if (headerFilterStrategy == null) {
-            headerFilterStrategy = new RestletHeaderFilterStrategy();
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Create Restlet default header filter strategy " + 
headerFilterStrategy);
-            }
-        }
         return headerFilterStrategy;
     }
 
@@ -184,32 +165,35 @@
         return ExchangePattern.InOut;
     }
 
-    /**
-     * @param restletMethods the restletMethods to set
-     */
     public void setRestletMethods(Method[] restletMethods) {
         this.restletMethods = restletMethods;
     }
 
-    /**
-     * @return the restletMethods
-     */
     public Method[] getRestletMethods() {
         return restletMethods;
     }
 
-    /**
-     * @param restletUriPatterns the restletUriPatterns to set
-     */
     public void setRestletUriPatterns(List<String> restletUriPatterns) {
         this.restletUriPatterns = restletUriPatterns;
     }
 
-    /**
-     * @return the restletUriPatterns
-     */
     public List<String> getRestletUriPatterns() {
         return restletUriPatterns;
     }
 
+    public void start() throws Exception {
+        if (headerFilterStrategy == null) {
+            headerFilterStrategy = new RestletHeaderFilterStrategy();
+        }
+        if (restletBinding == null) {
+            restletBinding = new DefaultRestletBinding();
+        }
+        if (restletBinding instanceof HeaderFilterStrategyAware) {
+            
((HeaderFilterStrategyAware)restletBinding).setHeaderFilterStrategy(getHeaderFilterStrategy());
+        }
+    }
+
+    public void stop() throws Exception {
+        // noop
+    }
 }


Reply via email to