You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by er...@apache.org on 2005/09/02 00:54:01 UTC
svn commit: r265797 - in
/directory/protocol-providers/dns/trunk/src/java/org/apache/dns: service/
store/ store/operations/
Author: erodriguez
Date: Thu Sep 1 15:53:48 2005
New Revision: 265797
URL: http://svn.apache.org/viewcvs?rev=265797&view=rev
Log:
Wired the DNS protocol provider to the Directory backing store:
o will now answer basic queries
o will now properly return an error if the query is not satisfied
o expanded monitor logging
Added:
directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorContext.java (with props)
directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/ContextOperation.java (with props)
directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/DnsAttribute.java (with props)
directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/JndiRecordStoreImpl.java (with props)
directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/RecordStore.java (with props)
directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/RecordStoreEntry.java (with props)
directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/RecordStoreEntryModifier.java (with props)
directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/operations/
directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/operations/GetRecord.java (with props)
Modified:
directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/BuildReply.java
directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/DnsExceptionHandler.java
directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/DomainNameServiceChain.java
directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/GetRecordEntry.java
directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorMessage.java
directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorReply.java
directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorRequest.java
Modified: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/BuildReply.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/BuildReply.java?rev=265797&r1=265796&r2=265797&view=diff
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/BuildReply.java (original)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/BuildReply.java Thu Sep 1 15:53:48 2005
@@ -16,17 +16,55 @@
*/
package org.apache.dns.service;
+import java.net.InetAddress;
+
import org.apache.dns.chain.Context;
import org.apache.dns.chain.impl.CommandBase;
+import org.apache.dns.messages.DnsMessage;
+import org.apache.dns.messages.DnsMessageModifier;
+import org.apache.dns.messages.MessageType;
+import org.apache.dns.messages.OpCode;
+import org.apache.dns.messages.ResponseCode;
+import org.apache.dns.records.ResourceRecord;
+import org.apache.dns.records.internet.AddressRecord;
+import org.apache.dns.store.RecordStoreEntry;
public class BuildReply extends CommandBase
{
public boolean execute( Context context ) throws Exception
{
DnsContext dnsContext = (DnsContext) context;
+ RecordStoreEntry entry = dnsContext.getRecordEntry();
+ DnsMessage request = dnsContext.getRequest();
+
+ 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() );
+
+ String dnsName = entry.getDnsName();
+ int dnsTtl = Integer.parseInt( entry.getDnsTtl() );
+ byte[] dnsIpAddress = InetAddress.getByName( entry.getDnsIpAddress() ).getAddress();
+
+ AddressRecord address = new AddressRecord( dnsName, dnsTtl, dnsIpAddress );
+
+ ResourceRecord[] records = new ResourceRecord[ 1 ];
+ records[ 0 ] = address;
+
+ modifier.setAnswerRecords( records );
+ modifier.setAuthorityRecords( new ResourceRecord[0] );
+ modifier.setAdditionalRecords( new ResourceRecord[0] );
- // TODO - enable store; currently echoing request
- dnsContext.setReply( dnsContext.getRequest() );
+ dnsContext.setReply( modifier.getDnsMessage() );
return CONTINUE_CHAIN;
}
Modified: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/DnsExceptionHandler.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/DnsExceptionHandler.java?rev=265797&r1=265796&r2=265797&view=diff
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/DnsExceptionHandler.java (original)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/DnsExceptionHandler.java Thu Sep 1 15:53:48 2005
@@ -20,7 +20,12 @@
import org.apache.dns.chain.Context;
import org.apache.dns.chain.Filter;
import org.apache.dns.chain.impl.CommandBase;
+import org.apache.dns.messages.DnsMessage;
import org.apache.dns.messages.DnsMessageModifier;
+import org.apache.dns.messages.MessageType;
+import org.apache.dns.messages.OpCode;
+import org.apache.dns.messages.ResponseCode;
+import org.apache.dns.records.ResourceRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -43,12 +48,26 @@
DnsContext dnsContext = (DnsContext) context;
DnsException de = (DnsException) exception;
+ DnsMessage message = dnsContext.getRequest();
- log.debug( "Exception " + de.getMessage() + " occurred." );
+ log.debug( de.getMessage() );
DnsMessageModifier modifier = new DnsMessageModifier();
- // TODO - figure out what to put in the error response
+ modifier.setTransactionId( message.getTransactionId() );
+ modifier.setMessageType( MessageType.RESPONSE );
+ modifier.setOpCode( OpCode.QUERY );
+ modifier.setAuthoritativeAnswer( false );
+ modifier.setTruncated( false );
+ modifier.setRecursionDesired( message.isRecursionDesired() );
+ modifier.setRecursionAvailable( false );
+ modifier.setReserved( false );
+ modifier.setAcceptNonAuthenticatedData( false );
+ modifier.setResponseCode( ResponseCode.getTypeByOrdinal( de.getResponseCode() ) );
+ modifier.setQuestionRecords( message.getQuestionRecords() );
+ modifier.setAnswerRecords( new ResourceRecord[ 0 ] );
+ modifier.setAuthorityRecords( new ResourceRecord[ 0 ] );
+ modifier.setAdditionalRecords( new ResourceRecord[ 0 ] );
dnsContext.setReply( modifier.getDnsMessage() );
Modified: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/DomainNameServiceChain.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/DomainNameServiceChain.java?rev=265797&r1=265796&r2=265797&view=diff
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/DomainNameServiceChain.java (original)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/DomainNameServiceChain.java Thu Sep 1 15:53:48 2005
@@ -17,22 +17,39 @@
package org.apache.dns.service;
import org.apache.dns.chain.impl.ChainBase;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Domain Name Service (DNS) Protocol (RFC 1034, 1035)
*/
public class DomainNameServiceChain extends ChainBase
{
+ /** the log for this class */
+ private static final Logger log = LoggerFactory.getLogger( DomainNameServiceChain.class );
+
public DomainNameServiceChain()
{
super();
addCommand( new DnsExceptionHandler() );
- addCommand( new MonitorRequest() );
- // TODO - enable store
- // addCommand( new GetRecordEntry() );
+ if ( log.isDebugEnabled() )
+ {
+ addCommand( new MonitorRequest() );
+ }
+
+ addCommand( new GetRecordEntry() );
+
+ if ( log.isDebugEnabled() )
+ {
+ addCommand( new MonitorContext() );
+ }
addCommand( new BuildReply() );
- addCommand( new MonitorReply() );
+
+ if ( log.isDebugEnabled() )
+ {
+ addCommand( new MonitorReply() );
+ }
}
}
Modified: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/GetRecordEntry.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/GetRecordEntry.java?rev=265797&r1=265796&r2=265797&view=diff
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/GetRecordEntry.java (original)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/GetRecordEntry.java Thu Sep 1 15:53:48 2005
@@ -29,12 +29,10 @@
{
public boolean execute( Context context ) throws Exception
{
- System.out.println( "Getting server entry." );
-
DnsContext dnsContext = (DnsContext) context;
RecordStore store = dnsContext.getStore();
- // TODO - major stub to make this compile
+ // TODO - handle more than 1 Question Record
QuestionRecord question = dnsContext.getRequest().getQuestionRecords()[ 0 ];
dnsContext.setRecordEntry( getEntry( store, question ) );
Added: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorContext.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorContext.java?rev=265797&view=auto
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorContext.java (added)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorContext.java Thu Sep 1 15:53:48 2005
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.dns.service;
+
+import org.apache.dns.chain.Context;
+import org.apache.dns.chain.impl.CommandBase;
+import org.apache.dns.store.RecordStore;
+import org.apache.dns.store.RecordStoreEntry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MonitorContext extends CommandBase
+{
+ /** the log for this class */
+ private static final Logger log = LoggerFactory.getLogger( MonitorContext.class );
+
+ public boolean execute( Context context ) throws Exception
+ {
+ if ( log.isDebugEnabled() )
+ {
+ try
+ {
+ DnsContext dnsContext = (DnsContext) context;
+ RecordStore store = dnsContext.getStore();
+ RecordStoreEntry entry = dnsContext.getRecordEntry();
+
+ StringBuffer sb = new StringBuffer();
+ sb.append( "Monitoring context:" );
+ sb.append( "\n\t" + "store " + store );
+ sb.append( "\n\t" + "dnsClass " + entry.getDnsClass() );
+ sb.append( "\n\t" + "dnsTtl " + entry.getDnsTtl() );
+ sb.append( "\n\t" + "dnsZoneName " + entry.getDnsZoneName() );
+ sb.append( "\n\t" + "dnsName " + entry.getDnsName() );
+ sb.append( "\n\t" + "dnsIpAddress " + entry.getDnsIpAddress() );
+
+ log.debug( sb.toString() );
+ }
+ catch ( Exception e )
+ {
+ // This is a monitor. No exceptions should bubble up.
+ log.error( "Error in context monitor", e );
+ }
+ }
+
+ return CONTINUE_CHAIN;
+ }
+}
Propchange: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorMessage.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorMessage.java?rev=265797&r1=265796&r2=265797&view=diff
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorMessage.java (original)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorMessage.java Thu Sep 1 15:53:48 2005
@@ -21,13 +21,12 @@
import org.apache.dns.messages.MessageType;
import org.apache.dns.messages.OpCode;
import org.apache.dns.messages.ResponseCode;
+import org.apache.dns.records.QuestionRecord;
public abstract class MonitorMessage extends CommandBase
{
- protected String monitorMessage( DnsContext dnsContext, String direction )
+ protected String monitorMessage( DnsMessage message, String direction )
{
- DnsMessage message = dnsContext.getRequest();
-
MessageType messageType = message.getMessageType();
OpCode opCode = message.getOpCode();
ResponseCode responseCode = message.getResponseCode();
@@ -35,10 +34,26 @@
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" + "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() );
+
+ QuestionRecord[] questions = message.getQuestionRecords();
+
+ for ( int ii = 0; ii < questions.length; ii++ )
+ {
+ sb.append( "\n\t" + "domain name " + questions[ ii ].getDomainName() );
+ sb.append( "\n\t" + "record class " + questions[ ii ].getRecordClass() );
+ sb.append( "\n\t" + "record type " + questions[ ii ].getRecordType() );
+ }
return sb.toString();
}
Modified: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorReply.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorReply.java?rev=265797&r1=265796&r2=265797&view=diff
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorReply.java (original)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorReply.java Thu Sep 1 15:53:48 2005
@@ -33,7 +33,7 @@
{
DnsContext dnsContext = (DnsContext) context;
- log.debug( monitorMessage( dnsContext, "reply" ) );
+ log.debug( monitorMessage( dnsContext.getReply(), "reply" ) );
}
catch ( Exception e )
{
Modified: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorRequest.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorRequest.java?rev=265797&r1=265796&r2=265797&view=diff
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorRequest.java (original)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/service/MonitorRequest.java Thu Sep 1 15:53:48 2005
@@ -33,7 +33,7 @@
{
DnsContext dnsContext = (DnsContext) context;
- log.debug( monitorMessage( dnsContext, "request" ) );
+ log.debug( monitorMessage( dnsContext.getRequest(), "request" ) );
}
catch ( Exception e )
{
Added: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/ContextOperation.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/ContextOperation.java?rev=265797&view=auto
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/ContextOperation.java (added)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/ContextOperation.java Thu Sep 1 15:53:48 2005
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.dns.store;
+
+import java.io.Serializable;
+
+import javax.naming.Name;
+import javax.naming.directory.DirContext;
+
+/**
+ * Interface to support the command pattern with JNDI contexts.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public interface ContextOperation extends Serializable
+{
+ /**
+ * The command pattern execute method.
+ *
+ * @param ctx The context to execute the command with
+ * @param searchBaseDn The base DN for working with the context
+ * @return Object The result returned by the command
+ * @throws Exception The exception thrown by the command
+ */
+ public Object execute( DirContext ctx, Name searchBaseDn ) throws Exception;
+}
Propchange: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/ContextOperation.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/DnsAttribute.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/DnsAttribute.java?rev=265797&view=auto
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/DnsAttribute.java (added)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/DnsAttribute.java Thu Sep 1 15:53:48 2005
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.dns.store;
+
+public class DnsAttribute
+{
+ /**
+ * Apache DNS Schema Attributes
+ */
+
+ /** the apachedns schema common name for an Apache DNS entry */
+ public static final String CN = "cn";
+
+ /**
+ * An abstract DNS record objectClass used to build other specific structural
+ * objectclasses for different record types
+ */
+
+ /** 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";
+ /** the apachedns schema zone for an apacheDnsAbstractRecord */
+ public static final String ZONE_NAME = "apacheDnsZoneName";
+ /** the apachedns schema name for an apacheDnsAbstractRecord */
+ public static final String NAME = "apacheDnsName";
+
+ /**
+ * 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 apacheDnsIpAddress */
+ public static final String IP_ADDRESS = "apacheDnsIpAddress";
+ /** the apachedns schema apacheDnsDomainName */
+ public static final String DOMAIN_NAME = "apacheDnsDomainName";
+}
Propchange: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/DnsAttribute.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/JndiRecordStoreImpl.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/JndiRecordStoreImpl.java?rev=265797&view=auto
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/JndiRecordStoreImpl.java (added)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/JndiRecordStoreImpl.java Thu Sep 1 15:53:48 2005
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.dns.store;
+
+import javax.naming.Name;
+import javax.naming.ldap.LdapContext;
+
+/**
+ * A simple implementation of the RecordStore interface using a JNDI
+ * based store.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class JndiRecordStoreImpl implements RecordStore
+{
+ /** a handle on the provider context */
+ private LdapContext ctx;
+
+ /** the search searchBase relative to the DN of the context supplied */
+ private Name searchBase;
+
+ /**
+ * Creates the action to be used against the embedded ApacheDS DIT. Note
+ * the searchBase is a relative name to the context and not a DN.
+ *
+ * @param ctx the JNDI context to the store
+ * @param searchBase the name relative to the context to use as the search base
+ */
+ public JndiRecordStoreImpl( LdapContext ctx, Name searchBase )
+ {
+ this.ctx = ctx;
+
+ this.searchBase = searchBase;
+ }
+
+ public Object execute( ContextOperation operation ) throws Exception
+ {
+ return operation.execute( ctx, searchBase );
+ }
+
+ /**
+ * Gets the LdapContext used to search for records in the JNDI store.
+ *
+ * @return the context for the search searchBase
+ */
+ protected LdapContext getContext()
+ {
+ return ctx;
+ }
+
+ /**
+ * Gets the search base use for finding records in the the store.
+ *
+ * @return search base relative to the supplied context
+ */
+ protected Name getSearchBase()
+ {
+ return searchBase;
+ }
+}
Propchange: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/JndiRecordStoreImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/RecordStore.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/RecordStore.java?rev=265797&view=auto
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/RecordStore.java (added)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/RecordStore.java Thu Sep 1 15:53:48 2005
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.dns.store;
+
+public interface RecordStore
+{
+ public Object execute( ContextOperation operation ) throws Exception;
+}
Propchange: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/RecordStore.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/RecordStoreEntry.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/RecordStoreEntry.java?rev=265797&view=auto
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/RecordStoreEntry.java (added)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/RecordStoreEntry.java Thu Sep 1 15:53:48 2005
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.dns.store;
+
+public class RecordStoreEntry
+{
+ private String dnsClass;
+ private String dnsTtl;
+ private String dnsZoneName;
+ private String dnsName;
+ private String dnsIpAddress;
+
+ /**
+ * @param dnsClass
+ * @param dnsIpAddress
+ * @param dnsName
+ * @param dnsTtl
+ * @param dnsZoneName
+ */
+ public RecordStoreEntry( String dnsClass, String dnsIpAddress, String dnsName, String dnsTtl, String dnsZoneName )
+ {
+ this.dnsClass = dnsClass;
+ this.dnsIpAddress = dnsIpAddress;
+ this.dnsName = dnsName;
+ this.dnsTtl = dnsTtl;
+ this.dnsZoneName = dnsZoneName;
+ }
+
+ /**
+ * @return Returns the dnsClass.
+ */
+ public String getDnsClass()
+ {
+ return dnsClass;
+ }
+
+ /**
+ * @return Returns the dnsIpAddress.
+ */
+ public String getDnsIpAddress()
+ {
+ return dnsIpAddress;
+ }
+
+ /**
+ * @return Returns the dnsName.
+ */
+ public String getDnsName()
+ {
+ return dnsName;
+ }
+
+ /**
+ * @return Returns the dnsTtl.
+ */
+ public String getDnsTtl()
+ {
+ return dnsTtl;
+ }
+
+ /**
+ * @return Returns the dnsZoneName.
+ */
+ public String getDnsZoneName()
+ {
+ return dnsZoneName;
+ }
+}
Propchange: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/RecordStoreEntry.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/RecordStoreEntryModifier.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/RecordStoreEntryModifier.java?rev=265797&view=auto
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/RecordStoreEntryModifier.java (added)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/RecordStoreEntryModifier.java Thu Sep 1 15:53:48 2005
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.dns.store;
+
+public class RecordStoreEntryModifier
+{
+ private String dnsClass;
+ private String dnsTtl;
+ private String dnsZoneName;
+ private String dnsName;
+ private String dnsIpAddress;
+
+ public RecordStoreEntry getEntry()
+ {
+ return new RecordStoreEntry( dnsClass, dnsIpAddress, dnsName, dnsTtl, dnsZoneName );
+ }
+
+ /**
+ * @param dnsClass The dnsClass to set.
+ */
+ public void setDnsClass( String dnsClass )
+ {
+ this.dnsClass = dnsClass;
+ }
+
+ /**
+ * @param dnsIpAddress The dnsIpAddress to set.
+ */
+ public void setDnsIpAddress( String dnsIpAddress )
+ {
+ this.dnsIpAddress = dnsIpAddress;
+ }
+
+ /**
+ * @param dnsName The dnsName to set.
+ */
+ public void setDnsName( String dnsName )
+ {
+ this.dnsName = dnsName;
+ }
+
+ /**
+ * @param dnsTtl The dnsTtl to set.
+ */
+ public void setDnsTtl( String dnsTtl )
+ {
+ this.dnsTtl = dnsTtl;
+ }
+
+ /**
+ * @param dnsZoneName The dnsZoneName to set.
+ */
+ public void setDnsZoneName( String dnsZoneName )
+ {
+ this.dnsZoneName = dnsZoneName;
+ }
+}
Propchange: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/RecordStoreEntryModifier.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/operations/GetRecord.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/operations/GetRecord.java?rev=265797&view=auto
==============================================================================
--- directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/operations/GetRecord.java (added)
+++ directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/operations/GetRecord.java Thu Sep 1 15:53:48 2005
@@ -0,0 +1,128 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.dns.store.operations;
+
+import javax.naming.Name;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchResult;
+
+import org.apache.dns.records.QuestionRecord;
+import org.apache.dns.store.ContextOperation;
+import org.apache.dns.store.DnsAttribute;
+import org.apache.dns.store.RecordStoreEntry;
+import org.apache.dns.store.RecordStoreEntryModifier;
+
+/**
+ * Encapsulates the action of looking up a Resource Record from an embedded JNDI provider.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class GetRecord implements ContextOperation
+{
+ /** The name of the question to get. */
+ private final QuestionRecord question;
+
+ /**
+ * Creates the action to be used against the embedded JNDI provider.
+ */
+ public GetRecord( 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 )
+ {
+ if ( question == null )
+ {
+ return null;
+ }
+
+ String[] attrIDs = { DnsAttribute.CLASS, DnsAttribute.TTL,
+ DnsAttribute.NAME, DnsAttribute.ZONE_NAME, DnsAttribute.IP_ADDRESS };
+
+ Attributes matchAttrs = new BasicAttributes( false ); // case-sensitive
+
+ matchAttrs.put( new BasicAttribute( DnsAttribute.NAME, question.getDomainName() ) );
+
+ RecordStoreEntry entry = null;
+
+ try
+ {
+ // Search for objects that have those matching attributes
+
+ NamingEnumeration answer = ctx.search( base, matchAttrs, attrIDs );
+
+ if ( answer.hasMore() )
+ {
+ SearchResult result = (SearchResult) answer.next();
+
+ Attributes attrs = result.getAttributes();
+
+ if ( attrs == null )
+ {
+ return null;
+ }
+
+ entry = getEntry( attrs );
+ }
+ }
+ catch ( NamingException e )
+ {
+ e.printStackTrace();
+
+ return null;
+ }
+
+ return entry;
+ }
+
+ /**
+ * 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 RecordStoreEntry getEntry( Attributes attrs ) throws NamingException
+ {
+ RecordStoreEntryModifier modifier = new RecordStoreEntryModifier();
+
+ String dnsClass = (String) attrs.get( DnsAttribute.CLASS ).get();
+ String dnsTtl = (String) attrs.get( DnsAttribute.TTL ).get();
+ String dnsZoneName = (String) attrs.get( DnsAttribute.ZONE_NAME ).get();
+ String dnsName = (String) attrs.get( DnsAttribute.NAME ).get();
+ String dnsIpAddress = (String) attrs.get( DnsAttribute.IP_ADDRESS ).get();
+
+ modifier.setDnsClass( dnsClass );
+ modifier.setDnsTtl( dnsTtl );
+ modifier.setDnsZoneName( dnsZoneName );
+ modifier.setDnsName( dnsName );
+ modifier.setDnsIpAddress( dnsIpAddress );
+
+ return modifier.getEntry();
+ }
+}
Propchange: directory/protocol-providers/dns/trunk/src/java/org/apache/dns/store/operations/GetRecord.java
------------------------------------------------------------------------------
svn:eol-style = native