directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jvermill...@apache.org
Subject svn commit: r549458 - in /directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns: service/ store/ store/jndi/ store/jndi/operations/ store/operations/
Date Thu, 21 Jun 2007 12:45:21 GMT
Author: jvermillard
Date: Thu Jun 21 05:45:19 2007
New Revision: 549458

URL: http://svn.apache.org/viewvc?view=rev&rev=549458
Log:
DNS provider :
* improved Exception catching in RecordStore (DIRSERVER-976)
* moved JNDI backend to it's own package
* a bit of Javadocing

Added:
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/DnsAttribute.java
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/DnsCatalog.java
      - copied, changed from r548368, directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/DnsCatalog.java
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/JndiRecordStoreImpl.java
      - copied, changed from r548368, directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/JndiRecordStoreImpl.java
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/MultiBaseSearch.java
      - copied, changed from r548368, directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/MultiBaseSearch.java
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/SearchStrategy.java
      - copied, changed from r548368, directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/SearchStrategy.java
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/SingleBaseSearch.java
      - copied, changed from r548368, directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/SingleBaseSearch.java
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/operations/
      - copied from r548368, directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/operations/
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/operations/GetFlatRecord.java
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/operations/GetRecords.java
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/operations/package-info.java
      - copied, changed from r549453, directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/operations/package-info.java
Removed:
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/DnsCatalog.java
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/JndiRecordStoreImpl.java
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/MultiBaseSearch.java
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/SearchStrategy.java
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/SingleBaseSearch.java
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/operations/
Modified:
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/service/GetResourceRecords.java
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/RecordStore.java
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/RecordStoreStub.java
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/package-info.java

Modified: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/service/GetResourceRecords.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/service/GetResourceRecords.java?view=diff&rev=549458&r1=549457&r2=549458
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/service/GetResourceRecords.java
(original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/service/GetResourceRecords.java
Thu Jun 21 05:45:19 2007
@@ -30,7 +30,6 @@
 import org.apache.directory.server.dns.messages.ResourceRecord;
 import org.apache.directory.server.dns.messages.ResponseCode;
 import org.apache.directory.server.dns.store.RecordStore;
-import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.handler.chain.IoHandlerCommand;
 import org.slf4j.Logger;
@@ -74,28 +73,13 @@
      * @param store
      * @param question
      * @return The set of {@link ResourceRecord}s.
-     * @throws Exception
+     * @throws DNSException
      */
-    public Set<ResourceRecord> getEntry( RecordStore store, QuestionRecord question
) throws Exception
+    public Set<ResourceRecord> getEntry( RecordStore store, QuestionRecord question
) throws DnsException
     {
         Set<ResourceRecord> records = null;
 
-        try
-        {
-            records = store.getRecords( question );
-        }
-        catch ( LdapNameNotFoundException lnnfe )
-        {
-            log.debug( "Name for DNS record search does not exist.", lnnfe );
-
-            throw new DnsException( ResponseCode.NAME_ERROR );
-        }
-        catch ( Exception e )
-        {
-            log.debug( "Unexpected error retrieving DNS records.", e );
-
-            throw new DnsException( ResponseCode.SERVER_FAILURE );
-        }
+        records = store.getRecords( question );
 
         if ( records == null || records.isEmpty() )
         {

Added: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/DnsAttribute.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/DnsAttribute.java?view=auto&rev=549458
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/DnsAttribute.java
(added)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/DnsAttribute.java
Thu Jun 21 05:45:19 2007
@@ -0,0 +1,92 @@
+/*
+ *  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.directory.server.dns.store;
+
+
+/**
+ * Constants representing the DNS attribute ids as defined by the Apache DNS schema.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class DnsAttribute
+{
+    /**
+     * Apache DNS Schema Attributes
+     */
+
+    /**
+     * An abstract DNS record objectClass used to build other specific structural
+     * objectclasses for different record types
+     */
+
+    /** the apachedns schema name for an apacheDnsAbstractRecord */
+    public static final String NAME = "apacheDnsName";
+    /** the apachedns schema type for an apacheDnsAbstractRecord */
+    public static final String TYPE = "apacheDnsType";
+    /** the apachedns schema class for an apacheDnsAbstractRecord */
+    public static final String CLASS = "apacheDnsClass";
+    /** the apachedns schema TTL for an apacheDnsAbstractRecord */
+    public static final String TTL = "apacheDnsTtl";
+
+    /**
+     * DNS record type - Start of Authority
+     */
+
+    /** the apachedns schema apacheDnsSoaMName for an apacheDnsStartOfAuthorityRecord */
+    public static final String SOA_M_NAME = "apacheDnsSoaMName";
+    /** the apachedns schema apacheDnsSoaRName for an apacheDnsStartOfAuthorityRecord */
+    public static final String SOA_R_NAME = "apacheDnsSoaRName";
+    /** the apachedns schema apacheDnsSoaSerial for an apacheDnsStartOfAuthorityRecord */
+    public static final String SOA_SERIAL = "apacheDnsSoaSerial";
+    /** the apachedns schema apacheDnsSoaRefresh for an apacheDnsStartOfAuthorityRecord */
+    public static final String SOA_REFRESH = "apacheDnsSoaRefresh";
+    /** the apachedns schema apacheDnsSoaRetry for an apacheDnsStartOfAuthorityRecord */
+    public static final String SOA_RETRY = "apacheDnsSoaRetry";
+    /** the apachedns schema apacheDnsSoaExpire for an apacheDnsStartOfAuthorityRecord */
+    public static final String SOA_EXPIRE = "apacheDnsSoaExpire";
+    /** the apachedns schema apacheDnsSoaMinimum for an apacheDnsStartOfAuthorityRecord */
+    public static final String SOA_MINIMUM = "apacheDnsSoaMinimum";
+
+    /**
+     * Other DNS record attributes
+     */
+
+    /** the apachedns schema apacheDnsDomainName */
+    public static final String DOMAIN_NAME = "apacheDnsDomainName";
+
+    /** the apachedns schema apacheDnsIpAddress */
+    public static final String IP_ADDRESS = "apacheDnsIpAddress";
+
+    /** the apachedns schema apacheDnsMxPreference */
+    public static final String MX_PREFERENCE = "apacheDnsMxPreference";
+
+    /** the apachedns schema apacheDnsCharacterString */
+    public static final String CHARACTER_STRING = "apacheDnsCharacterString";
+
+    /** the apachedns schema apacheDnsServicePriority */
+    public static final String SERVICE_PRIORITY = "apacheDnsServicePriority";
+
+    /** the apachedns schema apacheDnsServiceWeight */
+    public static final String SERVICE_WEIGHT = "apacheDnsServiceWeight";
+
+    /** the apachedns schema apacheDnsServicePort */
+    public static final String SERVICE_PORT = "apacheDnsServicePort";
+}

Modified: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/RecordStore.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/RecordStore.java?view=diff&rev=549458&r1=549457&r2=549458
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/RecordStore.java
(original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/RecordStore.java
Thu Jun 21 05:45:19 2007
@@ -22,6 +22,7 @@
 
 import java.util.Set;
 
+import org.apache.directory.server.dns.DnsException;
 import org.apache.directory.server.dns.messages.QuestionRecord;
 import org.apache.directory.server.dns.messages.ResourceRecord;
 
@@ -36,10 +37,10 @@
 {
     /**
      * Returns a set of {@link ResourceRecord}s, given a DNS {@link QuestionRecord}.
-     *
+     * If something bad happens throw the accurate {@link DNSException} 
      * @param question
      * @return The set of {@link ResourceRecord}s.
-     * @throws Exception
+     * @throws DNSException
      */
-    public Set<ResourceRecord> getRecords( QuestionRecord question ) throws Exception;
+    public Set<ResourceRecord> getRecords( QuestionRecord question ) throws DnsException;
 }

Modified: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/RecordStoreStub.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/RecordStoreStub.java?view=diff&rev=549458&r1=549457&r2=549458
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/RecordStoreStub.java
(original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/RecordStoreStub.java
Thu Jun 21 05:45:19 2007
@@ -23,6 +23,7 @@
 import java.util.HashSet;
 import java.util.Set;
 
+import org.apache.directory.server.dns.DnsException;
 import org.apache.directory.server.dns.messages.QuestionRecord;
 import org.apache.directory.server.dns.messages.RecordClass;
 import org.apache.directory.server.dns.messages.RecordType;
@@ -36,7 +37,7 @@
  */
 public class RecordStoreStub implements RecordStore
 {
-    public Set<ResourceRecord> getRecords( QuestionRecord question ) throws Exception
+    public Set<ResourceRecord> getRecords( QuestionRecord question ) throws DnsException
     {
         Set<ResourceRecord> set = new HashSet<ResourceRecord>();
 

Copied: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/DnsCatalog.java
(from r548368, directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/DnsCatalog.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/DnsCatalog.java?view=diff&rev=549458&p1=directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/DnsCatalog.java&r1=548368&p2=directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/DnsCatalog.java&r2=549458
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/DnsCatalog.java
(original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/DnsCatalog.java
Thu Jun 21 05:45:19 2007
@@ -18,7 +18,7 @@
  *  
  */
 
-package org.apache.directory.server.dns.store;
+package org.apache.directory.server.dns.store.jndi;
 
 
 import java.util.Map;

Copied: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/JndiRecordStoreImpl.java
(from r548368, directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/JndiRecordStoreImpl.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/JndiRecordStoreImpl.java?view=diff&rev=549458&p1=directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/JndiRecordStoreImpl.java&r1=548368&p2=directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/JndiRecordStoreImpl.java&r2=549458
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/JndiRecordStoreImpl.java
(original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/JndiRecordStoreImpl.java
Thu Jun 21 05:45:19 2007
@@ -17,7 +17,7 @@
  *  under the License. 
  *  
  */
-package org.apache.directory.server.dns.store;
+package org.apache.directory.server.dns.store.jndi;
 
 
 import java.util.Set;
@@ -25,8 +25,10 @@
 import javax.naming.spi.InitialContextFactory;
 
 import org.apache.directory.server.dns.DnsConfiguration;
+import org.apache.directory.server.dns.DnsException;
 import org.apache.directory.server.dns.messages.QuestionRecord;
 import org.apache.directory.server.dns.messages.ResourceRecord;
+import org.apache.directory.server.dns.store.RecordStore;
 
 
 /**
@@ -62,7 +64,7 @@
     }
 
 
-    public Set<ResourceRecord> getRecords( QuestionRecord question ) throws Exception
+    public Set<ResourceRecord> getRecords( QuestionRecord question ) throws DnsException
     {
         return strategy.getRecords( question );
     }

Copied: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/MultiBaseSearch.java
(from r548368, directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/MultiBaseSearch.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/MultiBaseSearch.java?view=diff&rev=549458&p1=directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/MultiBaseSearch.java&r1=548368&p2=directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/MultiBaseSearch.java&r2=549458
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/MultiBaseSearch.java
(original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/MultiBaseSearch.java
Thu Jun 21 05:45:19 2007
@@ -18,7 +18,7 @@
  *  
  */
 
-package org.apache.directory.server.dns.store;
+package org.apache.directory.server.dns.store.jndi;
 
 
 import java.util.Hashtable;
@@ -31,13 +31,16 @@
 import javax.naming.spi.InitialContextFactory;
 
 import org.apache.directory.server.dns.DnsConfiguration;
+import org.apache.directory.server.dns.DnsException;
 import org.apache.directory.server.dns.messages.QuestionRecord;
 import org.apache.directory.server.dns.messages.ResourceRecord;
-import org.apache.directory.server.dns.store.operations.GetRecords;
+import org.apache.directory.server.dns.messages.ResponseCode;
+import org.apache.directory.server.dns.store.jndi.operations.GetRecords;
 import org.apache.directory.server.protocol.shared.ServiceConfigurationException;
 import org.apache.directory.server.protocol.shared.catalog.Catalog;
 import org.apache.directory.server.protocol.shared.catalog.GetCatalog;
 import org.apache.directory.server.protocol.shared.store.ContextOperation;
+import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -82,7 +85,7 @@
     }
 
 
-    public Set<ResourceRecord> getRecords( QuestionRecord question ) throws Exception
+    public Set<ResourceRecord> getRecords( QuestionRecord question ) throws DnsException
     {
         env.put( Context.PROVIDER_URL, catalog.getBaseDn( question.getDomainName() ) );
 
@@ -91,12 +94,24 @@
             DirContext ctx = ( DirContext ) factory.getInitialContext( env );
             return ( Set ) execute( ctx, new GetRecords( question ) );
         }
+        catch ( LdapNameNotFoundException lnnfe )
+	    {
+	        log.debug( "Name for DNS record search does not exist.", lnnfe );
+	
+	        throw new DnsException( ResponseCode.NAME_ERROR );
+	    }
         catch ( NamingException ne )
         {
             log.error( ne.getMessage(), ne );
             String message = "Failed to get initial context " + ( String ) env.get( Context.PROVIDER_URL
);
             throw new ServiceConfigurationException( message, ne );
         }
+	    catch ( Exception e )
+	    {
+	        log.debug( "Unexpected error retrieving DNS records.", e );
+	        throw new DnsException( ResponseCode.SERVER_FAILURE );
+	    }
+
     }
 
 

Copied: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/SearchStrategy.java
(from r548368, directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/SearchStrategy.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/SearchStrategy.java?view=diff&rev=549458&p1=directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/SearchStrategy.java&r1=548368&p2=directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/SearchStrategy.java&r2=549458
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/SearchStrategy.java
(original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/SearchStrategy.java
Thu Jun 21 05:45:19 2007
@@ -18,11 +18,12 @@
  *  
  */
 
-package org.apache.directory.server.dns.store;
+package org.apache.directory.server.dns.store.jndi;
 
 
 import java.util.Set;
 
+import org.apache.directory.server.dns.DnsException;
 import org.apache.directory.server.dns.messages.QuestionRecord;
 import org.apache.directory.server.dns.messages.ResourceRecord;
 
@@ -44,5 +45,5 @@
      * @return The set of {@link ResourceRecord}s.
      * @throws Exception
      */
-    Set<ResourceRecord> getRecords( QuestionRecord question ) throws Exception;
+    Set<ResourceRecord> getRecords( QuestionRecord question ) throws DnsException;
 }

Copied: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/SingleBaseSearch.java
(from r548368, directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/SingleBaseSearch.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/SingleBaseSearch.java?view=diff&rev=549458&p1=directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/SingleBaseSearch.java&r1=548368&p2=directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/SingleBaseSearch.java&r2=549458
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/SingleBaseSearch.java
(original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/SingleBaseSearch.java
Thu Jun 21 05:45:19 2007
@@ -18,7 +18,7 @@
  *  
  */
 
-package org.apache.directory.server.dns.store;
+package org.apache.directory.server.dns.store.jndi;
 
 
 import java.util.Hashtable;
@@ -30,11 +30,14 @@
 import javax.naming.spi.InitialContextFactory;
 
 import org.apache.directory.server.dns.DnsConfiguration;
+import org.apache.directory.server.dns.DnsException;
 import org.apache.directory.server.dns.messages.QuestionRecord;
 import org.apache.directory.server.dns.messages.ResourceRecord;
-import org.apache.directory.server.dns.store.operations.GetRecords;
+import org.apache.directory.server.dns.messages.ResponseCode;
+import org.apache.directory.server.dns.store.jndi.operations.GetRecords;
 import org.apache.directory.server.protocol.shared.ServiceConfigurationException;
 import org.apache.directory.server.protocol.shared.store.ContextOperation;
+import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -68,28 +71,45 @@
     }
 
 
-    public Set<ResourceRecord> getRecords( QuestionRecord question ) throws Exception
+    public Set<ResourceRecord> getRecords( QuestionRecord question ) throws DnsException
     {
         return ( Set ) execute( new GetRecords( question ) );
     }
 
 
-    private Object execute( ContextOperation operation ) throws Exception
+    private Object execute( ContextOperation operation ) throws DnsException
     {
-        if ( ctx == null )
-        {
-            try
-            {
-                ctx = ( DirContext ) factory.getInitialContext( env );
-            }
-            catch ( NamingException ne )
-            {
-                log.error( ne.getMessage(), ne );
-                String message = "Failed to get initial context " + ( String ) env.get( Context.PROVIDER_URL
);
-                throw new ServiceConfigurationException( message, ne );
-            }
+    	try {
+    		
+	        if ( ctx == null )
+	        {
+	            try
+	            {
+	                ctx = ( DirContext ) factory.getInitialContext( env );
+	            }
+		        catch ( LdapNameNotFoundException lnnfe )
+			    {
+			        log.debug( "Name for DNS record search does not exist.", lnnfe );
+			
+			        throw new DnsException( ResponseCode.NAME_ERROR );
+			    }
+	            catch ( NamingException ne )
+	            {
+	                log.error( ne.getMessage(), ne );
+	                String message = "Failed to get initial context " + ( String ) env.get(
Context.PROVIDER_URL );
+	                throw new ServiceConfigurationException( message, ne );
+	            }
+	        }
+	        
+	        return operation.execute( ctx, null );
         }
+	    catch ( Exception e )
+	    {
+	        log.debug( "Unexpected error retrieving DNS records.", e );
+	        throw new DnsException( ResponseCode.SERVER_FAILURE );
+	    }
+
+
 
-        return operation.execute( ctx, null );
     }
 }

Added: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/operations/GetFlatRecord.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/operations/GetFlatRecord.java?view=auto&rev=549458
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/operations/GetFlatRecord.java
(added)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/operations/GetFlatRecord.java
Thu Jun 21 05:45:19 2007
@@ -0,0 +1,139 @@
+/*
+ *  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.directory.server.dns.store.jndi.operations;
+
+
+import javax.naming.Name;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchResult;
+
+import org.apache.directory.server.dns.messages.QuestionRecord;
+import org.apache.directory.server.dns.messages.RecordClass;
+import org.apache.directory.server.dns.messages.RecordType;
+import org.apache.directory.server.dns.messages.ResourceRecord;
+import org.apache.directory.server.dns.messages.ResourceRecordModifier;
+import org.apache.directory.server.dns.store.DnsAttribute;
+import org.apache.directory.server.protocol.shared.store.ContextOperation;
+import org.apache.directory.shared.ldap.message.AttributeImpl;
+import org.apache.directory.shared.ldap.message.AttributesImpl;
+
+
+/**
+ * A JNDI context operation for looking up a Resource Record with flat attributes.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class GetFlatRecord implements ContextOperation
+{
+    private static final long serialVersionUID = 4931303293468915435L;
+
+    /** The name of the question to get. */
+    private final QuestionRecord question;
+
+
+    /**
+     * Creates the action to be used against the embedded JNDI provider.
+     * 
+     * @param question 
+     */
+    public GetFlatRecord( QuestionRecord question )
+    {
+        this.question = question;
+    }
+
+
+    /**
+     * Note that the base is a relative path from the exiting context.
+     * It is not a DN.
+     */
+    public Object execute( DirContext ctx, Name base ) throws Exception
+    {
+        if ( question == null )
+        {
+            return null;
+        }
+
+        Attributes matchAttrs = new AttributesImpl( true );
+
+        matchAttrs.put( new AttributeImpl( DnsAttribute.NAME, question.getDomainName() )
);
+        matchAttrs.put( new AttributeImpl( DnsAttribute.TYPE, question.getRecordType().name()
) );
+        matchAttrs.put( new AttributeImpl( DnsAttribute.CLASS, question.getRecordClass().name()
) );
+
+        ResourceRecord record = null;
+
+        NamingEnumeration answer = ctx.search( base, matchAttrs );
+
+        if ( answer.hasMore() )
+        {
+            SearchResult result = ( SearchResult ) answer.next();
+
+            Attributes attrs = result.getAttributes();
+
+            if ( attrs == null )
+            {
+                return null;
+            }
+
+            record = getRecord( attrs );
+        }
+
+        return record;
+    }
+
+
+    /**
+     * Marshals a RecordStoreEntry from an Attributes object.
+     *
+     * @param attrs the attributes of the DNS question
+     * @return the entry for the question
+     * @throws NamingException if there are any access problems
+     */
+    private ResourceRecord getRecord( Attributes attrs ) throws NamingException
+    {
+        ResourceRecordModifier modifier = new ResourceRecordModifier();
+
+        Attribute attr;
+
+        String dnsName = ( attr = attrs.get( DnsAttribute.NAME ) ) != null ? ( String ) attr.get()
: null;
+        String dnsType = ( attr = attrs.get( DnsAttribute.TYPE ) ) != null ? ( String ) attr.get()
: null;
+        String dnsClass = ( attr = attrs.get( DnsAttribute.CLASS ) ) != null ? ( String )
attr.get() : null;
+        String dnsTtl = ( attr = attrs.get( DnsAttribute.TTL ) ) != null ? ( String ) attr.get()
: null;
+
+        modifier.setDnsName( dnsName );
+        modifier.setDnsType( RecordType.valueOf( dnsType ) );
+        modifier.setDnsClass( RecordClass.valueOf( dnsClass ) );
+        modifier.setDnsTtl( Integer.parseInt( dnsTtl ) );
+
+        NamingEnumeration ids = attrs.getIDs();
+
+        while ( ids.hasMore() )
+        {
+            String id = ( String ) ids.next();
+            modifier.put( id, ( String ) attrs.get( id ).get() );
+        }
+
+        return modifier.getEntry();
+    }
+}

Added: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/operations/GetRecords.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/operations/GetRecords.java?view=auto&rev=549458
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/operations/GetRecords.java
(added)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/operations/GetRecords.java
Thu Jun 21 05:45:19 2007
@@ -0,0 +1,325 @@
+/*
+ *  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.directory.server.dns.store.jndi.operations;
+
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.naming.CompoundName;
+import javax.naming.Name;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import org.apache.directory.server.dns.messages.QuestionRecord;
+import org.apache.directory.server.dns.messages.RecordClass;
+import org.apache.directory.server.dns.messages.RecordType;
+import org.apache.directory.server.dns.messages.ResourceRecord;
+import org.apache.directory.server.dns.messages.ResourceRecordModifier;
+import org.apache.directory.server.dns.store.DnsAttribute;
+import org.apache.directory.server.protocol.shared.store.ContextOperation;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+
+
+/**
+ * A JNDI context operation for looking up Resource Records from an embedded JNDI provider.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class GetRecords implements ContextOperation
+{
+    private static final long serialVersionUID = 1077580995617778894L;
+
+    /** The name of the question to get. */
+    private final QuestionRecord question;
+
+
+    /**
+     * Creates the action to be used against the embedded JNDI provider.
+     * 
+     * @param question 
+     */
+    public GetRecords( QuestionRecord question )
+    {
+        this.question = question;
+    }
+
+    /**
+     * Mappings of type to objectClass.
+     */
+    private static final Map<RecordType, String> TYPE_TO_OBJECTCLASS;
+
+    static
+    {
+        Map<RecordType, String> typeToObjectClass = new HashMap<RecordType, String>();
+        typeToObjectClass.put( RecordType.SOA, "apacheDnsStartOfAuthorityRecord" );
+        typeToObjectClass.put( RecordType.A, "apacheDnsAddressRecord" );
+        typeToObjectClass.put( RecordType.NS, "apacheDnsNameServerRecord" );
+        typeToObjectClass.put( RecordType.CNAME, "apacheDnsCanonicalNameRecord" );
+        typeToObjectClass.put( RecordType.PTR, "apacheDnsPointerRecord" );
+        typeToObjectClass.put( RecordType.MX, "apacheDnsMailExchangeRecord" );
+        typeToObjectClass.put( RecordType.SRV, "apacheDnsServiceRecord" );
+        typeToObjectClass.put( RecordType.TXT, "apacheDnsTextRecord" );
+
+        TYPE_TO_OBJECTCLASS = Collections.unmodifiableMap( typeToObjectClass );
+    }
+
+    /**
+     * Mappings of type to objectClass.
+     */
+    private static final Map<String, RecordType> OBJECTCLASS_TO_TYPE;
+
+    static
+    {
+        Map<String, RecordType> objectClassToType = new HashMap<String, RecordType>();
+        objectClassToType.put( "apacheDnsStartOfAuthorityRecord", RecordType.SOA );
+        objectClassToType.put( "apacheDnsAddressRecord", RecordType.A );
+        objectClassToType.put( "apacheDnsNameServerRecord", RecordType.NS );
+        objectClassToType.put( "apacheDnsCanonicalNameRecord", RecordType.CNAME );
+        objectClassToType.put( "apacheDnsPointerRecord", RecordType.PTR );
+        objectClassToType.put( "apacheDnsMailExchangeRecord", RecordType.MX );
+        objectClassToType.put( "apacheDnsServiceRecord", RecordType.SRV );
+        objectClassToType.put( "apacheDnsTextRecord", RecordType.TXT );
+        objectClassToType.put( "apacheDnsReferralNameServer", RecordType.NS );
+        objectClassToType.put( "apacheDnsReferralAddress", RecordType.A );
+
+        OBJECTCLASS_TO_TYPE = Collections.unmodifiableMap( objectClassToType );
+    }
+
+
+    /**
+     * Note that the base is a relative path from the exiting context.
+     * It is not a DN.
+     */
+    public Object execute( DirContext ctx, Name base ) throws Exception
+    {
+        if ( question == null )
+        {
+            return null;
+        }
+
+        String name = question.getDomainName();
+        RecordType type = question.getRecordType();
+
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+
+        String filter = "(objectClass=" + TYPE_TO_OBJECTCLASS.get( type ) + ")";
+
+        NamingEnumeration list = ctx.search( transformDomainName( name ), filter, controls
);
+
+        Set<ResourceRecord> set = new HashSet<ResourceRecord>();
+
+        while ( list.hasMore() )
+        {
+            SearchResult result = ( SearchResult ) list.next();
+            Name relative = getRelativeName( ctx.getNameInNamespace(), result.getName() );
+
+            set.add( getRecord( result.getAttributes(), relative ) );
+        }
+
+        return set;
+    }
+
+
+    /**
+     * Marshals a RecordStoreEntry from an Attributes object.
+     *
+     * @param attrs the attributes of the DNS question
+     * @return the entry for the question
+     * @throws NamingException if there are any access problems
+     */
+    private ResourceRecord getRecord( Attributes attrs, Name relative ) throws NamingException
+    {
+        String SOA_MINIMUM = "86400";
+        String SOA_CLASS = "IN";
+
+        ResourceRecordModifier modifier = new ResourceRecordModifier();
+
+        Attribute attr;
+
+        // if no name, transform rdn
+        attr = attrs.get( DnsAttribute.NAME );
+
+        if ( attr != null )
+        {
+            modifier.setDnsName( ( String ) attr.get() );
+        }
+        else
+        {
+            relative = getDomainComponents( relative );
+
+            String dnsName;
+            dnsName = transformDistinguishedName( relative.toString() );
+            modifier.setDnsName( dnsName );
+        }
+
+        // type is implicit in objectclass
+        attr = attrs.get( DnsAttribute.TYPE );
+
+        if ( attr != null )
+        {
+            modifier.setDnsType( RecordType.valueOf( ( String ) attr.get() ) );
+        }
+        else
+        {
+            modifier.setDnsType( getType( attrs.get( SchemaConstants.OBJECT_CLASS_AT ) )
);
+        }
+
+        // class defaults to SOA CLASS
+        String dnsClass = ( attr = attrs.get( DnsAttribute.CLASS ) ) != null ? ( String )
attr.get() : SOA_CLASS;
+        modifier.setDnsClass( RecordClass.valueOf( dnsClass ) );
+
+        // ttl defaults to SOA MINIMUM
+        String dnsTtl = ( attr = attrs.get( DnsAttribute.TTL ) ) != null ? ( String ) attr.get()
: SOA_MINIMUM;
+        modifier.setDnsTtl( Integer.parseInt( dnsTtl ) );
+
+        NamingEnumeration ids = attrs.getIDs();
+
+        while ( ids.hasMore() )
+        {
+            String id = ( String ) ids.next();
+            modifier.put( id, ( String ) attrs.get( id ).get() );
+        }
+
+        return modifier.getEntry();
+    }
+
+
+    /**
+     * Uses the algorithm in <a href="http://www.faqs.org/rfcs/rfc2247.html">RFC 2247</a>
+     * to transform any Internet domain name into a distinguished name.
+     *
+     * @param domainName the domain name
+     * @return the distinguished name
+     */
+    String transformDomainName( String domainName )
+    {
+        if ( domainName == null || domainName.length() == 0 )
+        {
+            return "";
+        }
+
+        StringBuffer buf = new StringBuffer( domainName.length() + 16 );
+
+        buf.append( "dc=" );
+        buf.append( domainName.replaceAll( "\\.", ",dc=" ) );
+
+        return buf.toString();
+    }
+
+
+    /**
+     * Uses the algorithm in <a href="http://www.faqs.org/rfcs/rfc2247.html">RFC 2247</a>
+     * to transform a distinguished name into an Internet domain name.
+     *
+     * @param distinguishedName the distinguished name
+     * @return the domain name
+     */
+    String transformDistinguishedName( String distinguishedName )
+    {
+        if ( distinguishedName == null || distinguishedName.length() == 0 )
+        {
+            return "";
+        }
+
+        String domainName = distinguishedName.replaceFirst( "dc=", "" );
+        domainName = domainName.replaceAll( ",dc=", "." );
+
+        return domainName;
+    }
+
+
+    private RecordType getType( Attribute objectClass ) throws NamingException
+    {
+        NamingEnumeration list = objectClass.getAll();
+
+        while ( list.hasMore() )
+        {
+            String value = ( String ) list.next();
+
+            if ( !value.equals( "apacheDnsAbstractRecord" ) )
+            {
+                RecordType type = OBJECTCLASS_TO_TYPE.get( value );
+
+                if ( type == null )
+                {
+                    throw new RuntimeException( "Record type to objectClass mapping has not
been set." );
+                }
+
+                return type;
+            }
+        }
+
+        throw new NamingException( "ResourceRecord requires STRUCTURAL objectClass" );
+    }
+
+
+    private Name getRelativeName( String nameInNamespace, String baseDn ) throws NamingException
+    {
+        Properties props = new Properties();
+        props.setProperty( "jndi.syntax.direction", "right_to_left" );
+        props.setProperty( "jndi.syntax.separator", "," );
+        props.setProperty( "jndi.syntax.ignorecase", "true" );
+        props.setProperty( "jndi.syntax.trimblanks", "true" );
+
+        Name searchBaseDn = null;
+
+        Name ctxRoot = new CompoundName( nameInNamespace, props );
+        searchBaseDn = new CompoundName( baseDn, props );
+
+        if ( !searchBaseDn.startsWith( ctxRoot ) )
+        {
+            throw new NamingException( "Invalid search base " + baseDn );
+        }
+
+        for ( int ii = 0; ii < ctxRoot.size(); ii++ )
+        {
+            searchBaseDn.remove( 0 );
+        }
+
+        return searchBaseDn;
+    }
+
+
+    private Name getDomainComponents( Name name ) throws NamingException
+    {
+        for ( int ii = 0; ii < name.size(); ii++ )
+        {
+            if ( !name.get( ii ).startsWith( "dc=" ) )
+            {
+                name.remove( ii );
+            }
+        }
+
+        return name;
+    }
+}

Copied: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/operations/package-info.java
(from r549453, directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/operations/package-info.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/operations/package-info.java?view=diff&rev=549458&p1=directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/operations/package-info.java&r1=549453&p2=directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/operations/package-info.java&r2=549458
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/operations/package-info.java
(original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/operations/package-info.java
Thu Jun 21 05:45:19 2007
@@ -25,4 +25,4 @@
  * @version $Rev$, $Date$
  */
 
-package org.apache.directory.server.dns.store.operations;
+package org.apache.directory.server.dns.store.jndi.operations;

Modified: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/package-info.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/package-info.java?view=diff&rev=549458&r1=549457&r2=549458
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/package-info.java
(original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/package-info.java
Thu Jun 21 05:45:19 2007
@@ -19,8 +19,8 @@
  */
 
 /**
- * Provides the store implementation for serving DNS resource records
- * backed by JNDI.
+ * Provides {@link RecordStore} interface for serving DNS resource records
+ * to {@link DNSServer}.
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$



Mime
View raw message