directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r396147 - in /directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns: protocol/ service/
Date Sat, 22 Apr 2006 18:54:32 GMT
Author: erodriguez
Date: Sat Apr 22 11:54:28 2006
New Revision: 396147

URL: http://svn.apache.org/viewcvs?rev=396147&view=rev
Log:
Updated DNS protocol provider to use MINA IoHandlerChain, replacing protocol-common chain.

Removed:
    directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/DnsExceptionHandler.java
Modified:
    directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolHandler.java
    directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/BuildReply.java
    directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/DnsContext.java
    directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/DomainNameServiceChain.java
    directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/GetResourceRecords.java
    directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorContext.java
    directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorMessage.java
    directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorReply.java
    directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorRequest.java

Modified: directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolHandler.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolHandler.java?rev=396147&r1=396146&r2=396147&view=diff
==============================================================================
--- directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolHandler.java
(original)
+++ directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolHandler.java
Sat Apr 22 11:54:28 2006
@@ -19,15 +19,21 @@
 
 
 import org.apache.directory.server.dns.DnsConfiguration;
+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.ResourceRecords;
+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.store.RecordStore;
-import org.apache.directory.server.protocol.shared.chain.Command;
 import org.apache.mina.common.IdleStatus;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.filter.codec.ProtocolCodecFilter;
+import org.apache.mina.handler.chain.IoHandlerCommand;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -38,8 +44,8 @@
 
     private DnsConfiguration config;
     private RecordStore store;
-
-    private Command dnsService;
+    private IoHandlerCommand dnsService;
+    private String contextKey = "context";
 
 
     public DnsProtocolHandler(DnsConfiguration config, RecordStore store)
@@ -88,22 +94,44 @@
     {
         log.debug( "{} RCVD: {}", session.getRemoteAddress(), message );
 
-        DnsMessage request = ( DnsMessage ) message;
-
         try
         {
             DnsContext dnsContext = new DnsContext();
             dnsContext.setConfig( config );
             dnsContext.setStore( store );
-            dnsContext.setRequest( request );
+            session.setAttribute( getContextKey(), dnsContext );
+
+            dnsService.execute( null, session, message );
 
-            dnsService.execute( dnsContext );
+            DnsMessage response = dnsContext.getReply();
 
-            session.write( dnsContext.getReply() );
+            session.write( response );
         }
         catch ( Exception e )
         {
             log.error( e.getMessage(), e );
+
+            DnsMessage request = (DnsMessage) message;
+            DnsException de = (DnsException) e;
+
+            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.getTypeByOrdinal( de.getResponseCode()
) );
+            modifier.setQuestionRecords( request.getQuestionRecords() );
+            modifier.setAnswerRecords( new ResourceRecords() );
+            modifier.setAuthorityRecords( new ResourceRecords() );
+            modifier.setAdditionalRecords( new ResourceRecords() );
+
+            session.write( modifier.getDnsMessage() );
         }
     }
 
@@ -111,5 +139,11 @@
     public void messageSent( IoSession session, Object message )
     {
         log.debug( "{} SENT: {}", session.getRemoteAddress(), message );
+    }
+
+
+    public String getContextKey()
+    {
+        return ( this.contextKey );
     }
 }

Modified: directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/BuildReply.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/BuildReply.java?rev=396147&r1=396146&r2=396147&view=diff
==============================================================================
--- directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/BuildReply.java
(original)
+++ directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/BuildReply.java
Sat Apr 22 11:54:28 2006
@@ -23,17 +23,19 @@
 import org.apache.directory.server.dns.messages.OpCode;
 import org.apache.directory.server.dns.messages.ResourceRecords;
 import org.apache.directory.server.dns.messages.ResponseCode;
-import org.apache.directory.server.protocol.shared.chain.Context;
-import org.apache.directory.server.protocol.shared.chain.impl.CommandBase;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.handler.chain.IoHandlerCommand;
 
 
-public class BuildReply extends CommandBase
+public class BuildReply implements IoHandlerCommand
 {
-    public boolean execute( Context context ) throws Exception
+    private String contextKey = "context";
+
+    public void execute( NextCommand next, IoSession session, Object message ) throws Exception
     {
-        DnsContext dnsContext = ( DnsContext ) context;
+        DnsContext dnsContext = (DnsContext) session.getAttribute( getContextKey() );
         ResourceRecords records = dnsContext.getResourceRecords();
-        DnsMessage request = dnsContext.getRequest();
+        DnsMessage request = (DnsMessage) message;
 
         DnsMessageModifier modifier = new DnsMessageModifier();
 
@@ -55,6 +57,11 @@
 
         dnsContext.setReply( modifier.getDnsMessage() );
 
-        return CONTINUE_CHAIN;
+        next.execute( session, message );
+    }
+
+    public String getContextKey()
+    {
+        return ( this.contextKey );
     }
 }

Modified: directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/DnsContext.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/DnsContext.java?rev=396147&r1=396146&r2=396147&view=diff
==============================================================================
--- directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/DnsContext.java
(original)
+++ directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/DnsContext.java
Sat Apr 22 11:54:28 2006
@@ -24,16 +24,14 @@
 import org.apache.directory.server.dns.messages.ResourceRecord;
 import org.apache.directory.server.dns.messages.ResourceRecords;
 import org.apache.directory.server.dns.store.RecordStore;
-import org.apache.directory.server.protocol.shared.chain.impl.ContextBase;
 
 
-public class DnsContext extends ContextBase
+public class DnsContext
 {
     private static final long serialVersionUID = -5911142975867852436L;
 
     private DnsConfiguration config;
     private RecordStore store;
-    private DnsMessage request;
     private DnsMessage reply;
     private ResourceRecords records = new ResourceRecords();
 
@@ -98,24 +96,6 @@
     public void setReply( DnsMessage reply )
     {
         this.reply = reply;
-    }
-
-
-    /**
-     * @return Returns the request.
-     */
-    public DnsMessage getRequest()
-    {
-        return request;
-    }
-
-
-    /**
-     * @param request The request to set.
-     */
-    public void setRequest( DnsMessage request )
-    {
-        this.request = request;
     }
 
 

Modified: directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/DomainNameServiceChain.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/DomainNameServiceChain.java?rev=396147&r1=396146&r2=396147&view=diff
==============================================================================
--- directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/DomainNameServiceChain.java
(original)
+++ directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/DomainNameServiceChain.java
Sat Apr 22 11:54:28 2006
@@ -17,7 +17,7 @@
 package org.apache.directory.server.dns.service;
 
 
-import org.apache.directory.server.protocol.shared.chain.impl.ChainBase;
+import org.apache.mina.handler.chain.IoHandlerChain;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -25,7 +25,7 @@
 /**
  * Domain Name Service (DNS) Protocol (RFC 1034, 1035)
  */
-public class DomainNameServiceChain extends ChainBase
+public class DomainNameServiceChain extends IoHandlerChain
 {
     /** the log for this class */
     private static final Logger log = LoggerFactory.getLogger( DomainNameServiceChain.class
);
@@ -33,25 +33,23 @@
 
     public DomainNameServiceChain()
     {
-        addCommand( new DnsExceptionHandler() );
-
         if ( log.isDebugEnabled() )
         {
-            addCommand( new MonitorRequest() );
+            addLast( "monitorRequest", new MonitorRequest() );
         }
 
-        addCommand( new GetResourceRecords() );
+        addLast( "getResourceRecords", new GetResourceRecords() );
 
         if ( log.isDebugEnabled() )
         {
-            addCommand( new MonitorContext() );
+            addLast( "monitorContext", new MonitorContext() );
         }
 
-        addCommand( new BuildReply() );
+        addLast( "buildReply", new BuildReply() );
 
         if ( log.isDebugEnabled() )
         {
-            addCommand( new MonitorReply() );
+            addLast( "monitorReply", new MonitorReply() );
         }
     }
 }

Modified: directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/GetResourceRecords.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/GetResourceRecords.java?rev=396147&r1=396146&r2=396147&view=diff
==============================================================================
--- directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/GetResourceRecords.java
(original)
+++ directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/GetResourceRecords.java
Sat Apr 22 11:54:28 2006
@@ -21,22 +21,27 @@
 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.QuestionRecord;
 import org.apache.directory.server.dns.messages.QuestionRecords;
 import org.apache.directory.server.dns.messages.ResponseCode;
 import org.apache.directory.server.dns.store.RecordStore;
-import org.apache.directory.server.protocol.shared.chain.Context;
-import org.apache.directory.server.protocol.shared.chain.impl.CommandBase;
+import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.handler.chain.IoHandlerCommand;
 
 
-public class GetResourceRecords extends CommandBase
+public class GetResourceRecords implements IoHandlerCommand
 {
-    public boolean execute( Context context ) throws Exception
+    private String contextKey = "context";
+
+    public void execute( NextCommand next, IoSession session, Object message ) throws Exception
     {
-        DnsContext dnsContext = ( DnsContext ) context;
+        DnsContext dnsContext = (DnsContext) session.getAttribute( getContextKey() );
         RecordStore store = dnsContext.getStore();
 
-        QuestionRecords questions = dnsContext.getRequest().getQuestionRecords();
+        DnsMessage request = (DnsMessage) message;
+        QuestionRecords questions = request.getQuestionRecords();
 
         Iterator it = questions.iterator();
 
@@ -45,7 +50,7 @@
             dnsContext.addResourceRecords( getEntry( store, ( QuestionRecord ) it.next()
) );
         }
 
-        return CONTINUE_CHAIN;
+        next.execute( session, message );
     }
 
 
@@ -57,6 +62,10 @@
         {
             records = store.getRecords( question );
         }
+        catch ( LdapNameNotFoundException lnnfe )
+        {
+            throw new DnsException( ResponseCode.NAME_ERROR );
+        }
         catch ( Exception e )
         {
             throw new DnsException( ResponseCode.SERVER_FAILURE );
@@ -68,5 +77,10 @@
         }
 
         return records;
+    }
+
+    public String getContextKey()
+    {
+        return ( this.contextKey );
     }
 }

Modified: directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorContext.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorContext.java?rev=396147&r1=396146&r2=396147&view=diff
==============================================================================
--- directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorContext.java
(original)
+++ directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorContext.java
Sat Apr 22 11:54:28 2006
@@ -19,25 +19,26 @@
 
 import org.apache.directory.server.dns.messages.ResourceRecords;
 import org.apache.directory.server.dns.store.RecordStore;
-import org.apache.directory.server.protocol.shared.chain.Context;
-import org.apache.directory.server.protocol.shared.chain.impl.CommandBase;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.handler.chain.IoHandlerCommand;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 
-public class MonitorContext extends CommandBase
+public class MonitorContext implements IoHandlerCommand
 {
     /** the log for this class */
     private static final Logger log = LoggerFactory.getLogger( MonitorContext.class );
 
+    private String contextKey = "context";
 
-    public boolean execute( Context context ) throws Exception
+    public void execute( NextCommand next, IoSession session, Object message ) throws Exception
     {
         if ( log.isDebugEnabled() )
         {
             try
             {
-                DnsContext dnsContext = ( DnsContext ) context;
+                DnsContext dnsContext = (DnsContext) session.getAttribute( getContextKey()
);
                 RecordStore store = dnsContext.getStore();
                 ResourceRecords records = dnsContext.getResourceRecords();
 
@@ -55,6 +56,11 @@
             }
         }
 
-        return CONTINUE_CHAIN;
+        next.execute( session, message );
+    }
+
+    public String getContextKey()
+    {
+        return ( this.contextKey );
     }
 }

Modified: directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorMessage.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorMessage.java?rev=396147&r1=396146&r2=396147&view=diff
==============================================================================
--- directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorMessage.java
(original)
+++ directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorMessage.java
Sat Apr 22 11:54:28 2006
@@ -22,10 +22,10 @@
 import org.apache.directory.server.dns.messages.OpCode;
 import org.apache.directory.server.dns.messages.QuestionRecords;
 import org.apache.directory.server.dns.messages.ResponseCode;
-import org.apache.directory.server.protocol.shared.chain.impl.CommandBase;
+import org.apache.mina.handler.chain.IoHandlerCommand;
 
 
-public abstract class MonitorMessage extends CommandBase
+public abstract class MonitorMessage implements IoHandlerCommand
 {
     protected String monitorMessage( DnsMessage message, String direction )
     {

Modified: directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorReply.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorReply.java?rev=396147&r1=396146&r2=396147&view=diff
==============================================================================
--- directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorReply.java
(original)
+++ directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorReply.java
Sat Apr 22 11:54:28 2006
@@ -17,7 +17,8 @@
 package org.apache.directory.server.dns.service;
 
 
-import org.apache.directory.server.protocol.shared.chain.Context;
+import org.apache.directory.server.dns.messages.DnsMessage;
+import org.apache.mina.common.IoSession;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -27,16 +28,18 @@
     /** the log for this class */
     private static final Logger log = LoggerFactory.getLogger( MonitorReply.class );
 
+    private String contextKey = "context";
 
-    public boolean execute( Context context ) throws Exception
+    public void execute( NextCommand next, IoSession session, Object message ) throws Exception
     {
         if ( log.isDebugEnabled() )
         {
             try
             {
-                DnsContext dnsContext = ( DnsContext ) context;
+                DnsContext dnsContext = (DnsContext) session.getAttribute( getContextKey()
);
+                DnsMessage reply = dnsContext.getReply();
 
-                log.debug( monitorMessage( dnsContext.getReply(), "reply" ) );
+                log.debug( monitorMessage( reply, "reply" ) );
             }
             catch ( Exception e )
             {
@@ -45,6 +48,11 @@
             }
         }
 
-        return CONTINUE_CHAIN;
+        next.execute( session, message );
+    }
+
+    public String getContextKey()
+    {
+        return ( this.contextKey );
     }
 }

Modified: directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorRequest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorRequest.java?rev=396147&r1=396146&r2=396147&view=diff
==============================================================================
--- directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorRequest.java
(original)
+++ directory/trunks/apacheds/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorRequest.java
Sat Apr 22 11:54:28 2006
@@ -17,7 +17,8 @@
 package org.apache.directory.server.dns.service;
 
 
-import org.apache.directory.server.protocol.shared.chain.Context;
+import org.apache.directory.server.dns.messages.DnsMessage;
+import org.apache.mina.common.IoSession;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -27,16 +28,15 @@
     /** the log for this class */
     private static final Logger log = LoggerFactory.getLogger( MonitorRequest.class );
 
-
-    public boolean execute( Context context ) throws Exception
+    public void execute( NextCommand next, IoSession session, Object message ) throws Exception
     {
         if ( log.isDebugEnabled() )
         {
             try
             {
-                DnsContext dnsContext = ( DnsContext ) context;
+                DnsMessage request = (DnsMessage) message;
 
-                log.debug( monitorMessage( dnsContext.getRequest(), "request" ) );
+                log.debug( monitorMessage( request, "request" ) );
             }
             catch ( Exception e )
             {
@@ -45,6 +45,6 @@
             }
         }
 
-        return CONTINUE_CHAIN;
+        next.execute( session, message );
     }
 }



Mime
View raw message