You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2006/01/18 04:53:46 UTC
svn commit: r370033 - in /directory/trunks:
apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/
common/ldap/src/main/java/org/apache/ldap/common/codec/
common/ldap/src/main/java/org/apache/ldap/common/message/extended/
Author: akarasulu
Date: Tue Jan 17 19:53:40 2006
New Revision: 370033
URL: http://svn.apache.org/viewcvs?rev=370033&view=rev
Log:
added notice of disconnect and hooked in protocolError trigger, waiting on DIRMINA-166 to complete the other trigger for unavailable resulttype
Added:
directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/extended/
directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/extended/NoticeOfDisconnect.java (with props)
Modified:
directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/LdapProtocolProvider.java
directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/TwixTransformer.java
Modified: directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/LdapProtocolProvider.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/LdapProtocolProvider.java?rev=370033&r1=370032&r2=370033&view=diff
==============================================================================
--- directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/LdapProtocolProvider.java (original)
+++ directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/LdapProtocolProvider.java Tue Jan 17 19:53:40 2006
@@ -60,6 +60,7 @@
import org.apache.ldap.common.message.SearchRequestImpl;
import org.apache.ldap.common.message.UnbindRequest;
import org.apache.ldap.common.message.UnbindRequestImpl;
+import org.apache.ldap.common.message.extended.NoticeOfDisconnect;
import org.apache.ldap.common.message.spi.Provider;
import org.apache.ldap.server.protocol.support.AbandonHandler;
import org.apache.ldap.server.protocol.support.AddHandler;
@@ -429,9 +430,14 @@
super.messageReceived( session, message );
}
+
public void exceptionCaught( IoSession session, Throwable cause )
{
- SessionLog.warn( session, "Unexpected exception.", cause );
+ SessionLog.warn( session,
+ "Unexpected exception forcing session to close: sending disconnect notice to client.", cause );
+ session.write( new NoticeOfDisconnect( ResultCodeEnum.PROTOCOLERROR ) );
+ SessionRegistry.getSingleton().remove( session );
+ session.close();
}
}
}
Modified: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/TwixTransformer.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/TwixTransformer.java?rev=370033&r1=370032&r2=370033&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/TwixTransformer.java (original)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/TwixTransformer.java Tue Jan 17 19:53:40 2006
@@ -893,7 +893,6 @@
private void transformExtendedResponse( LdapMessage twixMessage, Message snickersMessage )
{
ExtendedResponseImpl snickersExtendedResponse = (ExtendedResponseImpl)snickersMessage;
-
ExtendedResponse extendedResponse = new ExtendedResponse();
// Snickers : String oid -> Twix : OID responseName
Added: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/extended/NoticeOfDisconnect.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/extended/NoticeOfDisconnect.java?rev=370033&view=auto
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/extended/NoticeOfDisconnect.java (added)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/extended/NoticeOfDisconnect.java Tue Jan 17 19:53:40 2006
@@ -0,0 +1,194 @@
+/*
+ * Copyright 2006 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.ldap.common.message.extended;
+
+
+import org.apache.ldap.common.message.ExtendedResponseImpl;
+import org.apache.ldap.common.message.ResultCodeEnum;
+
+
+/**
+ * An extended operation intended for notifying clients of upcoming disconnection.
+ * Here's what <a href="http://www.faqs.org/rfcs/rfc2251.html">RFC 2251</a> has to
+ * say about it:
+ * <pre>
+ * Section 4.1.1 (Small snippet on sending NoD)
+ *
+ * If the server receives a PDU from the client in which the LDAPMessage
+ * SEQUENCE tag cannot be recognized, the messageID cannot be parsed,
+ * the tag of the protocolOp is not recognized as a request, or the
+ * encoding structures or lengths of data fields are found to be
+ * incorrect, then the server MUST return the notice of disconnection
+ * described in section 4.4.1, with resultCode protocolError, and
+ * immediately close the connection. In other cases that the server
+ * cannot parse the request received by the client, the server MUST
+ * return an appropriate response to the request, with the resultCode
+ * set to protocolError.
+ *
+ * ...
+ *
+ * 4.4. Unsolicited Notification
+ *
+ * An unsolicited notification is an LDAPMessage sent from the server to
+ * the client which is not in response to any LDAPMessage received by
+ * the server. It is used to signal an extraordinary condition in the
+ * server or in the connection between the client and the server. The
+ * notification is of an advisory nature, and the server will not expect
+ * any response to be returned from the client.
+ *
+ * The unsolicited notification is structured as an LDAPMessage in which
+ * the messageID is 0 and protocolOp is of the extendedResp form. The
+ * responseName field of the ExtendedResponse is present. The LDAPOID
+ * value MUST be unique for this notification, and not be used in any
+ * other situation.
+ *
+ * One unsolicited notification is defined in this document.
+ *
+ * 4.4.1. Notice of Disconnection
+ *
+ * This notification may be used by the server to advise the client that
+ * the server is about to close the connection due to an error
+ * condition. Note that this notification is NOT a response to an
+ * unbind requested by the client: the server MUST follow the procedures
+ * of section 4.3. This notification is intended to assist clients in
+ * distinguishing between an error condition and a transient network
+ * failure. As with a connection close due to network failure, the
+ * client MUST NOT assume that any outstanding requests which modified
+ * the directory have succeeded or failed.
+ *
+ * The responseName is 1.3.6.1.4.1.1466.20036, the response field is
+ * absent, and the resultCode is used to indicate the reason for the
+ * disconnection.
+ *
+ * The following resultCode values are to be used in this notification:
+ *
+ * - protocolError: The server has received data from the client in
+ * which the LDAPMessage structure could not be parsed.
+ *
+ * - strongAuthRequired: The server has detected that an established
+ * underlying security association protecting communication between
+ * the client and server has unexpectedly failed or been compromised.
+ *
+ * - unavailable: This server will stop accepting new connections and
+ * operations on all existing connections, and be unavailable for an
+ * extended period of time. The client may make use of an alternative
+ * server.
+ *
+ * After sending this notice, the server MUST close the connection.
+ * After receiving this notice, the client MUST NOT transmit any further
+ * on the connection, and may abruptly close the connection.
+ * </pre>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class NoticeOfDisconnect extends ExtendedResponseImpl
+{
+ public static final String OID = "1.3.6.1.4.1.1466.20036";
+ private static final byte[] EMPTY_RESPONSE = new byte[0];
+
+
+ public NoticeOfDisconnect( ResultCodeEnum rcode )
+ {
+ super( 0 );
+
+ switch ( rcode.getValue() )
+ {
+ case( ResultCodeEnum.UNAVAILABLE_VAL ):
+ break;
+ case( ResultCodeEnum.PROTOCOLERROR_VAL ):
+ break;
+ case( ResultCodeEnum.STRONGAUTHREQUIRED_VAL ):
+ break;
+ default:
+ throw new IllegalArgumentException( "The result code can only be one of: " +
+ ResultCodeEnum.UNAVAILABLE + ", " +
+ ResultCodeEnum.PROTOCOLERROR + ", " +
+ ResultCodeEnum.STRONGAUTHREQUIRED );
+ }
+ super.getLdapResult().setErrorMessage( "The server will disconnect!" );
+ super.getLdapResult().setMatchedDn( "" );
+ super.getLdapResult().setResultCode( rcode );
+ }
+
+
+ // ------------------------------------------------------------------------
+ // ExtendedResponse Interface Method Implementations
+ // ------------------------------------------------------------------------
+
+
+ /**
+ * Gets the reponse OID specific encoded response values.
+ *
+ * @return the response specific encoded response values.
+ */
+ public byte [] getResponse()
+ {
+ return EMPTY_RESPONSE;
+ }
+
+
+ /**
+ * Sets the reponse OID specific encoded response values.
+ *
+ * @param value the response specific encoded response values.
+ */
+ public void setResponse( byte [] value )
+ {
+ throw new UnsupportedOperationException( "the response is hardcoded as zero length array" );
+ }
+
+
+ /**
+ * Gets the OID uniquely identifying this extended response (a.k.a. its
+ * name).
+ *
+ * @return the OID of the extended response type.
+ */
+ public String getResponseName()
+ {
+ return OID;
+ }
+
+
+ /**
+ * Sets the OID uniquely identifying this extended response (a.k.a. its
+ * name).
+ *
+ * @param oid the OID of the extended response type.
+ */
+ public void setResponseName( String oid )
+ {
+ throw new UnsupportedOperationException( "the OID is fixed: " + OID );
+ }
+
+
+ public boolean equals( Object obj )
+ {
+ if ( obj == this )
+ {
+ return true;
+ }
+
+ if ( obj instanceof NoticeOfDisconnect )
+ {
+ return true;
+ }
+
+ return false;
+ }
+}
Propchange: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/extended/NoticeOfDisconnect.java
------------------------------------------------------------------------------
svn:eol-style = native