camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r771309 - in /camel/branches/camel-1.x: ./ components/camel-ldap/src/main/java/org/apache/camel/component/ldap/LdapProducer.java
Date Mon, 04 May 2009 14:04:21 GMT
Author: davsclaus
Date: Mon May  4 14:04:20 2009
New Revision: 771309

URL: http://svn.apache.org/viewvc?rev=771309&view=rev
Log:
CAMEL-1583: ldap-producer is not thread safe. Applied patch with thanks to Christopher Hunt.

Modified:
    camel/branches/camel-1.x/   (props changed)
    camel/branches/camel-1.x/components/camel-ldap/src/main/java/org/apache/camel/component/ldap/LdapProducer.java

Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon May  4 14:04:20 2009
@@ -1 +1 @@
-/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258,747678-747704,748392,748436,748821,749563-749564,749574,749628-749629,749936,749956,750017,750334,750396,750761,750796,752068,752117,752418,752751-752755,752764-752773,752956,753087,753101,753175,755136,755487,756313,756348,756870,756939,757636,757693,757743,757865,758539,758563,758600,758617,758692,758990,759362,759453,759887,759931,760003,760890,760909,760937,761194,761536,761583,761607,762047,762633,762650,762935,763095,763484,763551,765154,765686,765729,765743,765824,766016,766289,766584,766588,766590,766602,766673,767403,767824,768342,769239,769346,769368,769434,770172,770906
+/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258,747678-747704,748392,748436,748821,749563-749564,749574,749628-749629,749936,749956,750017,750334,750396,750761,750796,752068,752117,752418,752751-752755,752764-752773,752956,753087,753101,753175,755136,755487,756313,756348,756870,756939,757636,757693,757743,757865,758539,758563,758600,758617,758692,758990,759362,759453,759887,759931,760003,760890,760909,760937,761194,761536,761583,761607,762047,762633,762650,762935,763095,763484,763551,765154,765686,765729,765743,765824,766016,766289,766584,766588,766590,766602,766673,767403,767824,768342,769239,769346,769368,769434,770172,770906,771303

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

Modified: camel/branches/camel-1.x/components/camel-ldap/src/main/java/org/apache/camel/component/ldap/LdapProducer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-ldap/src/main/java/org/apache/camel/component/ldap/LdapProducer.java?rev=771309&r1=771308&r2=771309&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-ldap/src/main/java/org/apache/camel/component/ldap/LdapProducer.java
(original)
+++ camel/branches/camel-1.x/components/camel-ldap/src/main/java/org/apache/camel/component/ldap/LdapProducer.java
Mon May  4 14:04:20 2009
@@ -18,7 +18,6 @@
 
 import java.util.ArrayList;
 import java.util.List;
-
 import javax.naming.NamingEnumeration;
 import javax.naming.directory.DirContext;
 import javax.naming.directory.SearchControls;
@@ -35,14 +34,14 @@
  */
 public class LdapProducer<E extends Exchange> extends DefaultProducer<DefaultExchange>
{
     private static final transient Log LOG = LogFactory.getLog(LdapProducer.class);
-    private DirContext ldapContext;
+    private String remaining;
     private SearchControls controls;
     private String searchBase;
 
     public LdapProducer(LdapEndpoint endpoint, String remaining, String base, int scope)
throws Exception {
         super(endpoint);
 
-        ldapContext = (DirContext)getEndpoint().getCamelContext().getRegistry().lookup(remaining);
+        this.remaining = remaining;
         searchBase = base;
         controls = new SearchControls();
         controls.setSearchScope(scope);
@@ -51,19 +50,27 @@
     public void process(Exchange exchange) throws Exception {
         String filter = exchange.getIn().getBody(String.class);
 
-        // could throw NamingException
-        List<SearchResult> data = new ArrayList<SearchResult>();
-        NamingEnumeration<SearchResult> namingEnumeration =
-            ldapContext.search(searchBase, filter, getControls());
-
-        while (namingEnumeration.hasMore()) {
-            data.add(namingEnumeration.next());
+        // Obtain our ldap context. We do this by looking up the context in our registry.

+        // Note though that a new context is expected each time. Therefore if spring is
+        // being used then use prototype="scope". If you do not then you might experience
+        // concurrency issues as InitialContext is not required to support concurrency.
+        // On the other hand if you have a DirContext that is able to support concurrency
+        // then using the default singleton scope is entirely sufficient. Most DirContext
+        // classes will require prototype scope though.
+        DirContext ldapContext = (DirContext) getEndpoint().getCamelContext().getRegistry().lookup(remaining);
+        try {
+            // could throw NamingException
+            List<SearchResult> data = new ArrayList<SearchResult>();
+            NamingEnumeration<SearchResult> namingEnumeration =
+                    ldapContext.search(searchBase, filter, getControls());
+
+            while (namingEnumeration.hasMore()) {
+                data.add(namingEnumeration.next());
+            }
+            exchange.getOut().setBody(data);
+        } finally {
+            ldapContext.close();
         }
-        exchange.getOut().setBody(data);
-    }
-
-    public DirContext getDirContext() {
-        return ldapContext;
     }
 
     protected SearchControls getControls() {



Mime
View raw message