directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r591064 - in /directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns: ./ protocol/ service/
Date Thu, 01 Nov 2007 16:03:48 GMT
Author: elecharny
Date: Thu Nov  1 09:03:46 2007
New Revision: 591064

URL: http://svn.apache.org/viewvc?rev=591064&view=rev
Log:
Get rid of the IoHandlerChain

Added:
    directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/service/DomainNameService.java
      - copied, changed from r590742, directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/service/DomainNameServiceChain.java
Removed:
    directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/service/BuildReply.java
    directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/service/DomainNameServiceChain.java
    directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/service/GetResourceRecords.java
    directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorMessage.java
    directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorReply.java
    directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorRequest.java
Modified:
    directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/DnsServer.java
    directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/Main.java
    directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolHandler.java

Modified: directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/DnsServer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/DnsServer.java?rev=591064&r1=591063&r2=591064&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/DnsServer.java
(original)
+++ directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/DnsServer.java
Thu Nov  1 09:03:46 2007
@@ -41,7 +41,6 @@
  */
 public class DnsServer extends DirectoryBackedService
 {
-    @SuppressWarnings ( { "UnusedDeclaration" } )
     private static final long serialVersionUID = 6943138644427163149L;
 
     /** The default IP port. */

Modified: directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/Main.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/Main.java?rev=591064&r1=591063&r2=591064&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/Main.java
(original)
+++ directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/Main.java
Thu Nov  1 09:03:46 2007
@@ -37,7 +37,7 @@
 public class Main
 {
     /** Logger for this class */
-    private static final Logger log = LoggerFactory.getLogger( Main.class );
+    private static final Logger LOG = LoggerFactory.getLogger( Main.class );
 
     private static DnsServer dnsConfiguration;
 
@@ -58,6 +58,8 @@
      */
     public void go() throws IOException
     {
+        LOG.debug( "Starting the DNS server" );
+        
         DatagramAcceptor datagramAcceptor = new DatagramAcceptor( null );
         SocketAcceptor socketAcceptor = new SocketAcceptor( null );
         DirectoryService directoryService = new DefaultDirectoryService();
@@ -73,6 +75,7 @@
 
     protected void shutdown()
     {
+        LOG.debug( "Stopping the DNS server" );
         dnsConfiguration.stop();
     }
 }

Modified: directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolHandler.java?rev=591064&r1=591063&r2=591064&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolHandler.java
(original)
+++ directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolHandler.java
Thu Nov  1 09:03:46 2007
@@ -32,14 +32,13 @@
 import org.apache.directory.server.dns.messages.ResourceRecord;
 import org.apache.directory.server.dns.messages.ResponseCode;
 import org.apache.directory.server.dns.service.DnsContext;
-import org.apache.directory.server.dns.service.DomainNameServiceChain;
+import org.apache.directory.server.dns.service.DomainNameService;
 import org.apache.directory.server.dns.store.RecordStore;
 import org.apache.mina.common.IdleStatus;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.TransportType;
 import org.apache.mina.filter.codec.ProtocolCodecFilter;
-import org.apache.mina.handler.chain.IoHandlerCommand;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -50,11 +49,10 @@
  */
 public class DnsProtocolHandler implements IoHandler
 {
-    private static final Logger log = LoggerFactory.getLogger( DnsProtocolHandler.class );
+    private static final Logger LOG = LoggerFactory.getLogger( DnsProtocolHandler.class );
 
     private DnsServer config;
     private RecordStore store;
-    private IoHandlerCommand dnsService;
     private String contextKey = "context";
 
 
@@ -68,16 +66,14 @@
     {
         this.config = config;
         this.store = store;
-
-        dnsService = new DomainNameServiceChain();
     }
 
 
     public void sessionCreated( IoSession session ) throws Exception
     {
-        if ( log.isDebugEnabled() )
+        if ( LOG.isDebugEnabled() )
         {
-            log.debug( "{} CREATED:  {}", session.getRemoteAddress(), session.getTransportType()
);
+            LOG.debug( "{} CREATED:  {}", session.getRemoteAddress(), session.getTransportType()
);
         }
 
         if ( session.getTransportType() == TransportType.DATAGRAM )
@@ -95,32 +91,32 @@
 
     public void sessionOpened( IoSession session )
     {
-        log.debug( "{} OPENED", session.getRemoteAddress() );
+        LOG.debug( "{} OPENED", session.getRemoteAddress() );
     }
 
 
     public void sessionClosed( IoSession session )
     {
-        log.debug( "{} CLOSED", session.getRemoteAddress() );
+        LOG.debug( "{} CLOSED", session.getRemoteAddress() );
     }
 
 
     public void sessionIdle( IoSession session, IdleStatus status )
     {
-        log.debug( "{} IDLE ({})", session.getRemoteAddress(), status );
+        LOG.debug( "{} IDLE ({})", session.getRemoteAddress(), status );
     }
 
 
     public void exceptionCaught( IoSession session, Throwable cause )
     {
-        log.error( session.getRemoteAddress() + " EXCEPTION", cause );
+        LOG.error( session.getRemoteAddress() + " EXCEPTION", cause );
         session.close();
     }
 
 
     public void messageReceived( IoSession session, Object message )
     {
-        log.debug( "{} RCVD:  {}", session.getRemoteAddress(), message );
+        LOG.debug( "{} RCVD:  {}", session.getRemoteAddress(), message );
 
         try
         {
@@ -129,7 +125,7 @@
             dnsContext.setStore( store );
             session.setAttribute( getContextKey(), dnsContext );
 
-            dnsService.execute( null, session, message );
+            DomainNameService.execute( dnsContext, (DnsMessage)message );
 
             DnsMessage response = dnsContext.getReply();
 
@@ -137,7 +133,7 @@
         }
         catch ( Exception e )
         {
-            log.error( e.getMessage(), e );
+            LOG.error( e.getMessage(), e );
 
             DnsMessage request = ( DnsMessage ) message;
             DnsException de = ( DnsException ) e;
@@ -166,7 +162,7 @@
 
     public void messageSent( IoSession session, Object message )
     {
-        log.debug( "{} SENT:  {}", session.getRemoteAddress(), message );
+        LOG.debug( "{} SENT:  {}", session.getRemoteAddress(), message );
     }
 
 

Copied: directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/service/DomainNameService.java
(from r590742, directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/service/DomainNameServiceChain.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/service/DomainNameService.java?p2=directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/service/DomainNameService.java&p1=directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/service/DomainNameServiceChain.java&r1=590742&r2=591064&rev=591064&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/service/DomainNameServiceChain.java
(original)
+++ directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/service/DomainNameService.java
Thu Nov  1 09:03:46 2007
@@ -20,7 +20,20 @@
 package org.apache.directory.server.dns.service;
 
 
-import org.apache.mina.handler.chain.IoHandlerChain;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.directory.server.dns.DnsException;
+import org.apache.directory.server.dns.messages.DnsMessage;
+import org.apache.directory.server.dns.messages.DnsMessageModifier;
+import org.apache.directory.server.dns.messages.MessageType;
+import org.apache.directory.server.dns.messages.OpCode;
+import org.apache.directory.server.dns.messages.QuestionRecord;
+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.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -31,34 +44,180 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class DomainNameServiceChain extends IoHandlerChain
+public class DomainNameService
 {
     /** the log for this class */
-    private static final Logger log = LoggerFactory.getLogger( DomainNameServiceChain.class
);
+    private static final Logger LOG = LoggerFactory.getLogger( DomainNameService.class );
 
 
     /**
-     * Creates a new instance of DomainNameServiceChain.
+     * Creates a new instance of DomainNameService.
      */
-    public DomainNameServiceChain()
+    public static void execute( DnsContext dnsContext, DnsMessage request ) throws Exception
     {
-        if ( log.isDebugEnabled() )
+        if ( LOG.isDebugEnabled() )
         {
-            addLast( "monitorRequest", new MonitorRequest() );
+            monitorRequest( request );
         }
 
-        addLast( "getResourceRecords", new GetResourceRecords() );
+        getResourceRecords( dnsContext, request );
 
-        if ( log.isDebugEnabled() )
+        if ( LOG.isDebugEnabled() )
         {
-            addLast( "monitorContext", new MonitorContext() );
+            monitorContext( dnsContext );
         }
 
-        addLast( "buildReply", new BuildReply() );
+        buildReply( dnsContext, request );
 
-        if ( log.isDebugEnabled() )
+        if ( LOG.isDebugEnabled() )
         {
-            addLast( "monitorReply", new MonitorReply() );
+            monitorReply( dnsContext );
         }
+    }
+    
+    private static void monitorRequest( DnsMessage request ) throws Exception
+    {
+        try
+        {
+            LOG.debug( monitorMessage( request, "request" ) );
+        }
+        catch ( Exception e )
+        {
+            // This is a monitor.  No exceptions should bubble up.
+            LOG.error( "Error in request monitor", e );
+        }
+    }
+    
+
+    private static void getResourceRecords( DnsContext dnsContext, DnsMessage request ) throws
Exception
+    {
+        RecordStore store = dnsContext.getStore();
+
+        List<QuestionRecord> questions = request.getQuestionRecords();
+
+        Iterator<QuestionRecord> it = questions.iterator();
+
+        while ( it.hasNext() )
+        {
+            dnsContext.addResourceRecords( getEntry( store, it.next() ) );
+        }
+    }
+    
+    
+    /**
+     * Returns a set of {@link ResourceRecord}s from a {@link RecordStore}, given a DNS {@link
QuestionRecord}.
+     *
+     * @param store
+     * @param question
+     * @return The set of {@link ResourceRecord}s.
+     * @throws DNSException
+     */
+    private static Set<ResourceRecord> getEntry( RecordStore store, QuestionRecord
question ) throws DnsException
+    {
+        Set<ResourceRecord> records = null;
+
+        records = store.getRecords( question );
+
+        if ( records == null || records.isEmpty() )
+        {
+            LOG.debug( "The domain name referenced in the query does not exist." );
+
+            throw new DnsException( ResponseCode.NAME_ERROR );
+        }
+
+        return records;
+    }
+    
+    
+    private static void monitorContext( DnsContext dnsContext ) throws Exception
+    {
+        try
+        {
+            RecordStore store = dnsContext.getStore();
+            List<ResourceRecord> records = dnsContext.getResourceRecords();
+
+            StringBuffer sb = new StringBuffer();
+            sb.append( "Monitoring context:" );
+            sb.append( "\n\t" + "store:                     " + store );
+            sb.append( "\n\t" + "records:                   " + records );
+
+            LOG.debug( sb.toString() );
+        }
+        catch ( Exception e )
+        {
+            // This is a monitor.  No exceptions should bubble up.
+            LOG.error( "Error in context monitor", e );
+        }
+    }
+    
+    
+    private static void buildReply( DnsContext dnsContext, DnsMessage request ) throws Exception
+    {
+        List<ResourceRecord> records = dnsContext.getResourceRecords();
+
+        DnsMessageModifier modifier = new DnsMessageModifier();
+
+        modifier.setTransactionId( request.getTransactionId() );
+        modifier.setMessageType( MessageType.RESPONSE );
+        modifier.setOpCode( OpCode.QUERY );
+        modifier.setAuthoritativeAnswer( false );
+        modifier.setTruncated( false );
+        modifier.setRecursionDesired( request.isRecursionDesired() );
+        modifier.setRecursionAvailable( false );
+        modifier.setReserved( false );
+        modifier.setAcceptNonAuthenticatedData( false );
+        modifier.setResponseCode( ResponseCode.NO_ERROR );
+        modifier.setQuestionRecords( request.getQuestionRecords() );
+
+        modifier.setAnswerRecords( records );
+        modifier.setAuthorityRecords( new ArrayList<ResourceRecord>() );
+        modifier.setAdditionalRecords( new ArrayList<ResourceRecord>() );
+
+        dnsContext.setReply( modifier.getDnsMessage() );
+    }
+ 
+    
+    private static void monitorReply( DnsContext dnsContext ) throws Exception
+    {
+        try
+        {
+            DnsMessage reply = dnsContext.getReply();
+
+            LOG.debug( monitorMessage( reply, "reply" ) );
+        }
+        catch ( Exception e )
+        {
+            // This is a monitor.  No exceptions should bubble up.
+            LOG.error( "Error in reply monitor", e );
+        }
+    }
+    
+    
+    private static String monitorMessage( DnsMessage message, String direction )
+    {
+        MessageType messageType = message.getMessageType();
+        OpCode opCode = message.getOpCode();
+        ResponseCode responseCode = message.getResponseCode();
+        int transactionId = message.getTransactionId();
+
+        StringBuffer sb = new StringBuffer();
+        sb.append( "Monitoring " + direction + ":" );
+        sb.append( "\n\t" + "messageType                " + messageType );
+        sb.append( "\n\t" + "opCode                     " + opCode );
+        sb.append( "\n\t" + "responseCode               " + responseCode );
+        sb.append( "\n\t" + "transactionId              " + transactionId );
+
+        sb.append( "\n\t" + "authoritativeAnswer        " + message.isAuthoritativeAnswer()
);
+        sb.append( "\n\t" + "truncated                  " + message.isTruncated() );
+        sb.append( "\n\t" + "recursionDesired           " + message.isRecursionDesired()
);
+        sb.append( "\n\t" + "recursionAvailable         " + message.isRecursionAvailable()
);
+        sb.append( "\n\t" + "reserved                   " + message.isReserved() );
+        sb.append( "\n\t" + "acceptNonAuthenticatedData " + message.isAcceptNonAuthenticatedData()
);
+
+        List<QuestionRecord> questions = message.getQuestionRecords();
+
+        sb.append( "\n\t" + "questions:                 " + questions );
+
+        return sb.toString();
     }
 }



Mime
View raw message