Author: elecharny
Date: Sun Jul 31 08:16:33 2005
New Revision: 226647
URL: http://svn.apache.org/viewcvs?rev=226647&view=rev
Log:
Added the encode method for BindResponse, ExtendedResponse
and ExtendedRequest.
Modified:
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapConstants.java
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/BindResponseGrammar.java
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ExtendedRequestGrammar.java
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ExtendedResponseGrammar.java
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/BindResponse.java
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/DelRequest.java
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ExtendedRequest.java
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ExtendedResponse.java
directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/BindResponseTest.java
directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/ExtendedRequestTest.java
directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/ExtendedResponseTest.java
Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapConstants.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapConstants.java?rev=226647&r1=226646&r2=226647&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapConstants.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapConstants.java
Sun Jul 31 08:16:33 2005
@@ -54,13 +54,21 @@
public static final byte UNBIND_REQUEST_TAG = 0x42;
public static final byte DEL_REQUEST_TAG = 0x4A;
public static final byte ABANDON_REQUEST_TAG = 0x50;
+ public static final byte BIND_RESPONSE_TAG = 0x61;
public static final byte SEARCH_RESULT_DONE_TAG = 0x65;
public static final byte MODIFY_RESPONSE_TAG = 0x67;
public static final byte ADD_RESPONSE_TAG = 0x69;
public static final byte DEL_RESPONSE_TAG = 0x6B;
public static final byte MODIFY_DN_RESPONSE_TAG = 0x6D;
public static final byte COMPARE_RESPONSE_TAG = 0x6F;
+ public static final byte EXTENDED_REQUEST_TAG = 0x77;
+ public static final byte EXTENDED_RESPONSE_TAG = 0x78;
+ public static final int EXTENDED_REQUEST_NAME_TAG = 0x80;
+ public static final int EXTENDED_REQUEST_VALUE_TAG = 0x81;
public static final int LDAP_RESULT_REFERRAL_SEQUENCE_TAG = 0x83;
+ public static final int SERVER_SASL_CREDENTIAL_TAG = 0x87;
+ public static final int EXTENDED_RESPONSE_RESPONSE_NAME_TAG = 0x8A;
+ public static final int EXTENDED_RESPONSE_RESPONSE_TAG = 0x8B;
public static final int CONTROLS_SEQUENCE_TAG = 0x90;
}
Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/BindResponseGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/BindResponseGrammar.java?rev=226647&r1=226646&r2=226647&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/BindResponseGrammar.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/BindResponseGrammar.java
Sun Jul 31 08:16:33 2005
@@ -23,6 +23,7 @@
import org.apache.asn1.ber.grammar.GrammarTransition;
import org.apache.asn1.ber.grammar.IGrammar;
import org.apache.asn1.ber.tlv.TLV;
+import org.apache.asn1.ldap.codec.LdapConstants;
import org.apache.asn1.ldap.codec.LdapMessageContainer;
import org.apache.asn1.ldap.pojo.BindResponse;
import org.apache.asn1.ldap.pojo.LdapMessage;
@@ -72,13 +73,13 @@
// COMPONENTS OF LDAPResult,
// ...
// Nothing to do
- super.transitions[LdapStatesEnum.BIND_RESPONSE_TAG][0x61] = new GrammarTransition(
+ super.transitions[LdapStatesEnum.BIND_RESPONSE_TAG][LdapConstants.BIND_RESPONSE_TAG]
= new GrammarTransition(
LdapStatesEnum.BIND_RESPONSE_TAG, LdapStatesEnum.BIND_RESPONSE_VALUE, null
);
// LdapMessage ::= ... BindResponse ...
// BindResponse ::= [APPLICATION 1] SEQUENCE { ... (Value)
// We won't have a value. The next Tag will be the LDAPResult Tag (0x0A)
- super.transitions[LdapStatesEnum.BIND_RESPONSE_VALUE][0x61] = new GrammarTransition(
+ super.transitions[LdapStatesEnum.BIND_RESPONSE_VALUE][LdapConstants.BIND_RESPONSE_TAG]
= new GrammarTransition(
LdapStatesEnum.BIND_RESPONSE_VALUE, LdapStatesEnum.BIND_RESPONSE_LDAP_RESULT,
new GrammarAction( "Init BindReponse" )
{
@@ -106,7 +107,7 @@
// COMPONENTS OF LDAPResult, ...
// The Tag will be the LDAPResult Tag (0x0A). So we have to switch the grammar.
// The current state will be stored.
- super.transitions[LdapStatesEnum.BIND_RESPONSE_LDAP_RESULT][0x0A] = new GrammarTransition(
+ super.transitions[LdapStatesEnum.BIND_RESPONSE_LDAP_RESULT][LdapConstants.ENUMERATED_TAG]
= new GrammarTransition(
LdapStatesEnum.BIND_RESPONSE_LDAP_RESULT, LdapStatesEnum.LDAP_RESULT_GRAMMAR_SWITCH,
null );
@@ -116,7 +117,7 @@
// serverSaslCreds [7] OCTET STRING OPTIONAL }
// If there is a sasl credential, we will decode it here. We must control that we
had a LdapResult
//
- super.transitions[LdapStatesEnum.BIND_RESPONSE_LDAP_RESULT][0x87] = new GrammarTransition(
+ super.transitions[LdapStatesEnum.BIND_RESPONSE_LDAP_RESULT][LdapConstants.SERVER_SASL_CREDENTIAL_TAG]
= new GrammarTransition(
LdapStatesEnum.BIND_RESPONSE_LDAP_RESULT,
LdapStatesEnum.BIND_RESPONSE_SERVER_SASL_CREDS_VALUE, null );
@@ -125,7 +126,7 @@
// serverSaslCreds [7] OCTET STRING OPTIONAL } (Tag)
// It's a server sasl credential if the tag is 0x87
// Otherwise, if the tag is 0x90, it's a control
- super.transitions[LdapStatesEnum.BIND_RESPONSE_SERVER_SASL_CREDS_TAG][0x87] =
+ super.transitions[LdapStatesEnum.BIND_RESPONSE_SERVER_SASL_CREDS_TAG][LdapConstants.SERVER_SASL_CREDENTIAL_TAG]
=
new GrammarTransition( LdapStatesEnum.BIND_RESPONSE_SERVER_SASL_CREDS_TAG,
LdapStatesEnum.BIND_RESPONSE_SERVER_SASL_CREDS_VALUE, null );
@@ -139,7 +140,7 @@
// - nothing at all (end of the BindResponse).
// We just have to transit to the first case, which will accept or not the transition.
// This is done by transiting to the GRAMMAR_END state
- super.transitions[LdapStatesEnum.BIND_RESPONSE_SERVER_SASL_CREDS_VALUE][0x87] =
+ super.transitions[LdapStatesEnum.BIND_RESPONSE_SERVER_SASL_CREDS_VALUE][LdapConstants.SERVER_SASL_CREDENTIAL_TAG]
=
new GrammarTransition( LdapStatesEnum.BIND_RESPONSE_SERVER_SASL_CREDS_VALUE,
LdapStatesEnum.GRAMMAR_END,
new GrammarAction( "Store server sasl credentials value" )
Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ExtendedRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ExtendedRequestGrammar.java?rev=226647&r1=226646&r2=226647&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ExtendedRequestGrammar.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ExtendedRequestGrammar.java
Sun Jul 31 08:16:33 2005
@@ -23,6 +23,7 @@
import org.apache.asn1.ber.grammar.GrammarTransition;
import org.apache.asn1.ber.grammar.IGrammar;
import org.apache.asn1.ber.tlv.TLV;
+import org.apache.asn1.ldap.codec.LdapConstants;
import org.apache.asn1.ldap.codec.LdapMessageContainer;
import org.apache.asn1.ldap.pojo.ExtendedRequest;
import org.apache.asn1.ldap.pojo.LdapMessage;
@@ -70,13 +71,13 @@
//============================================================================================
// ExtendedRequest ::= [APPLICATION 23] SEQUENCE { (Tag)
// Nothing to do
- super.transitions[LdapStatesEnum.EXTENDED_REQUEST_TAG][0x77] = new GrammarTransition(
+ super.transitions[LdapStatesEnum.EXTENDED_REQUEST_TAG][LdapConstants.EXTENDED_REQUEST_TAG]
= new GrammarTransition(
LdapStatesEnum.EXTENDED_REQUEST_TAG,
LdapStatesEnum.EXTENDED_REQUEST_VALUE, null );
// ExtendedRequest ::= [APPLICATION 23] SEQUENCE { (Value)
// Initialize the compare request pojo
- super.transitions[LdapStatesEnum.EXTENDED_REQUEST_VALUE][0x77] = new GrammarTransition(
+ super.transitions[LdapStatesEnum.EXTENDED_REQUEST_VALUE][LdapConstants.EXTENDED_REQUEST_TAG]
= new GrammarTransition(
LdapStatesEnum.EXTENDED_REQUEST_VALUE, LdapStatesEnum.EXTENDED_REQUEST_NAME_TAG,
new GrammarAction( "Init Extended Request" )
{
@@ -97,7 +98,7 @@
// requestName [0] LDAPOID, (Tag)
// ...
// Nothing to do
- super.transitions[LdapStatesEnum.EXTENDED_REQUEST_NAME_TAG][0x80] = new GrammarTransition(
+ super.transitions[LdapStatesEnum.EXTENDED_REQUEST_NAME_TAG][LdapConstants.EXTENDED_REQUEST_NAME_TAG]
= new GrammarTransition(
LdapStatesEnum.EXTENDED_REQUEST_NAME_TAG,
LdapStatesEnum.EXTENDED_REQUEST_NAME_VALUE, null );
@@ -105,7 +106,7 @@
// requestName [0] LDAPOID, (Value)
// ...
// Store the DN to be compared
- super.transitions[LdapStatesEnum.EXTENDED_REQUEST_NAME_VALUE][0x80] = new GrammarTransition(
+ super.transitions[LdapStatesEnum.EXTENDED_REQUEST_NAME_VALUE][LdapConstants.EXTENDED_REQUEST_NAME_TAG]
= new GrammarTransition(
LdapStatesEnum.EXTENDED_REQUEST_NAME_VALUE, LdapStatesEnum.EXTENDED_REQUEST_VALUE_TAG,
new GrammarAction( "Store name" )
{
@@ -130,7 +131,7 @@
}
else
{
- extendedRequest.setName( new OID( tlv.getValue().getData() )
);
+ extendedRequest.setRequestName( new OID( tlv.getValue().getData()
) );
}
}
} );
@@ -139,7 +140,7 @@
// ...
// requestValue [1] OCTET STRING OPTIONAL } (Tag)
// Nothing to do
- super.transitions[LdapStatesEnum.EXTENDED_REQUEST_VALUE_TAG][0x81] = new GrammarTransition(
+ super.transitions[LdapStatesEnum.EXTENDED_REQUEST_VALUE_TAG][LdapConstants.EXTENDED_REQUEST_VALUE_TAG]
= new GrammarTransition(
LdapStatesEnum.EXTENDED_REQUEST_VALUE_TAG,
LdapStatesEnum.EXTENDED_REQUEST_VALUE_VALUE, null );
@@ -147,7 +148,7 @@
// ...
// requestValue [1] OCTET STRING OPTIONAL } (Value)
// Store the DN to be compared
- super.transitions[LdapStatesEnum.EXTENDED_REQUEST_VALUE_VALUE][0x81] = new GrammarTransition(
+ super.transitions[LdapStatesEnum.EXTENDED_REQUEST_VALUE_VALUE][LdapConstants.EXTENDED_REQUEST_VALUE_TAG]
= new GrammarTransition(
LdapStatesEnum.EXTENDED_REQUEST_VALUE_VALUE, LdapStatesEnum.END_STATE,
new GrammarAction( "Store value" )
{
@@ -168,11 +169,11 @@
// We have to handle the special case of a 0 length matched OID
if ( tlv.getLength().getLength() == 0 )
{
- extendedRequest.setValue( OctetString.EMPTY_STRING );
+ extendedRequest.setRequestValue( OctetString.EMPTY_STRING );
}
else
{
- extendedRequest.setValue( new OctetString( tlv.getValue().getData()
) );
+ extendedRequest.setRequestValue( new OctetString( tlv.getValue().getData()
) );
}
}
} );
Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ExtendedResponseGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ExtendedResponseGrammar.java?rev=226647&r1=226646&r2=226647&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ExtendedResponseGrammar.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ExtendedResponseGrammar.java
Sun Jul 31 08:16:33 2005
@@ -23,6 +23,7 @@
import org.apache.asn1.ber.grammar.GrammarTransition;
import org.apache.asn1.ber.grammar.IGrammar;
import org.apache.asn1.ber.tlv.TLV;
+import org.apache.asn1.ldap.codec.LdapConstants;
import org.apache.asn1.ldap.codec.LdapMessageContainer;
import org.apache.asn1.ldap.pojo.ExtendedResponse;
import org.apache.asn1.ldap.pojo.LdapMessage;
@@ -70,13 +71,13 @@
//============================================================================================
// ExtendedResponse ::= [APPLICATION 24] SEQUENCE { (Tag)
// Nothing to do
- super.transitions[LdapStatesEnum.EXTENDED_RESPONSE_TAG][0x78] = new GrammarTransition(
+ super.transitions[LdapStatesEnum.EXTENDED_RESPONSE_TAG][LdapConstants.EXTENDED_RESPONSE_TAG]
= new GrammarTransition(
LdapStatesEnum.EXTENDED_RESPONSE_TAG,
LdapStatesEnum.EXTENDED_RESPONSE_VALUE, null );
// ExtendedResponse ::= [APPLICATION 24] SEQUENCE { (Value)
// Initialize the compare request pojo
- super.transitions[LdapStatesEnum.EXTENDED_RESPONSE_VALUE][0x78] = new GrammarTransition(
+ super.transitions[LdapStatesEnum.EXTENDED_RESPONSE_VALUE][LdapConstants.EXTENDED_RESPONSE_TAG]
= new GrammarTransition(
LdapStatesEnum.EXTENDED_RESPONSE_VALUE, LdapStatesEnum.EXTENDED_RESPONSE_LDAP_RESULT,
new GrammarAction( "Init Extended Reponse" )
{
@@ -98,7 +99,7 @@
// ...
// The Tag will be the LDAPResult Tag (0x0A). So we have to switch the grammar.
// The current state will be stored.
- super.transitions[LdapStatesEnum.EXTENDED_RESPONSE_LDAP_RESULT][0x0A] = new GrammarTransition(
+ super.transitions[LdapStatesEnum.EXTENDED_RESPONSE_LDAP_RESULT][LdapConstants.ENUMERATED_TAG]
= new GrammarTransition(
LdapStatesEnum.EXTENDED_RESPONSE_LDAP_RESULT,
LdapStatesEnum.LDAP_RESULT_GRAMMAR_SWITCH, null );
@@ -107,7 +108,7 @@
// responseName [10] LDAPOID OPTIONAL, (Tag)
// ...
// Nothing to do.
- super.transitions[LdapStatesEnum.EXTENDED_RESPONSE_LDAP_RESULT][0x8A] = new GrammarTransition(
+ super.transitions[LdapStatesEnum.EXTENDED_RESPONSE_LDAP_RESULT][LdapConstants.EXTENDED_RESPONSE_RESPONSE_NAME_TAG]
= new GrammarTransition(
LdapStatesEnum.EXTENDED_RESPONSE_LDAP_RESULT, LdapStatesEnum.EXTENDED_RESPONSE_NAME_VALUE,
null
);
@@ -116,7 +117,7 @@
// responseName [10] LDAPOID OPTIONAL, (Value)
// ...
// Store the response name.
- super.transitions[LdapStatesEnum.EXTENDED_RESPONSE_NAME_VALUE][0x8A] = new GrammarTransition(
+ super.transitions[LdapStatesEnum.EXTENDED_RESPONSE_NAME_VALUE][LdapConstants.EXTENDED_RESPONSE_RESPONSE_NAME_TAG]
= new GrammarTransition(
LdapStatesEnum.EXTENDED_RESPONSE_NAME_VALUE, LdapStatesEnum.EXTENDED_RESPONSE_RESPONSE_TAG,
new GrammarAction( "Store name" )
{
@@ -141,7 +142,7 @@
}
else
{
- extendedResponse.setName( new OID( tlv.getValue().getData() ) );
+ extendedResponse.setResponseName( new OID( tlv.getValue().getData()
) );
}
}
} );
@@ -150,7 +151,7 @@
// ...
// response [11] OCTET STRING OPTIONAL } (Tag)
// Nothing to do
- super.transitions[LdapStatesEnum.EXTENDED_RESPONSE_RESPONSE_TAG][0x8B] = new GrammarTransition(
+ super.transitions[LdapStatesEnum.EXTENDED_RESPONSE_RESPONSE_TAG][LdapConstants.EXTENDED_RESPONSE_RESPONSE_TAG]
= new GrammarTransition(
LdapStatesEnum.EXTENDED_RESPONSE_RESPONSE_TAG,
LdapStatesEnum.EXTENDED_RESPONSE_RESPONSE_VALUE, null );
@@ -158,7 +159,7 @@
// ...
// response [11] OCTET STRING OPTIONAL } (Value)
// Store the response
- super.transitions[LdapStatesEnum.EXTENDED_RESPONSE_RESPONSE_VALUE][0x8B] = new GrammarTransition(
+ super.transitions[LdapStatesEnum.EXTENDED_RESPONSE_RESPONSE_VALUE][LdapConstants.EXTENDED_RESPONSE_RESPONSE_TAG]
= new GrammarTransition(
LdapStatesEnum.EXTENDED_RESPONSE_RESPONSE_VALUE, LdapStatesEnum.END_STATE,
new GrammarAction( "Store response" )
{
Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/BindResponse.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/BindResponse.java?rev=226647&r1=226646&r2=226647&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/BindResponse.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/BindResponse.java
Sun Jul 31 08:16:33 2005
@@ -16,7 +16,12 @@
*/
package org.apache.asn1.ldap.pojo;
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
+import org.apache.asn1.EncoderException;
import org.apache.asn1.ber.tlv.Length;
+import org.apache.asn1.ldap.codec.LdapConstants;
import org.apache.asn1.primitives.OctetString;
/**
@@ -35,6 +40,9 @@
/** The server credentials */
private OctetString serverSaslCreds;
+
+ /** The bind response length */
+ private transient int bindResponseLength;
//~ Constructors -------------------------------------------------------------------------------
@@ -82,14 +90,62 @@
public int computeLength()
{
int ldapResponseLength = super.computeLength();
- int bindResponseLength = 1 + Length.getNbBytes( ldapResponseLength ) + ldapResponseLength;
+
+ bindResponseLength = ldapResponseLength;
if (serverSaslCreds != null)
{
bindResponseLength += 1 + Length.getNbBytes(serverSaslCreds.getLength()) + serverSaslCreds.getLength();
}
- return bindResponseLength;
+ return 1 + Length.getNbBytes( bindResponseLength ) + bindResponseLength;
+ }
+
+ /**
+ * Encode the BindResponse message to a PDU.
+ *
+ * BindResponse :
+ *
+ * LdapResult.encode
+ * [0x87 LL serverSaslCreds]
+ *
+ * @param buffer The buffer where to put the PDU
+ * @return The PDU.
+ */
+ public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+ {
+ if (buffer == null)
+ {
+ throw new EncoderException("Cannot put a PDU in a null buffer !");
+ }
+
+ try
+ {
+ // The BindResponse Tag
+ buffer.put( LdapConstants.BIND_RESPONSE_TAG );
+ buffer.put( Length.getBytes( bindResponseLength ) );
+
+ // The LdapResult
+ super.encode(buffer);
+
+ // The serverSaslCredential, if any
+ if ( serverSaslCreds != null )
+ {
+ buffer.put( (byte)LdapConstants.SERVER_SASL_CREDENTIAL_TAG );
+ buffer.put( Length.getBytes( serverSaslCreds.getLength() ) );
+
+ if ( serverSaslCreds.getLength() != 0 )
+ {
+ buffer.put( serverSaslCreds.getValue() );
+ }
+ }
+ }
+ catch ( BufferOverflowException boe )
+ {
+ throw new EncoderException("The PDU buffer size is too small !");
+ }
+
+ return buffer;
}
/**
Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/DelRequest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/DelRequest.java?rev=226647&r1=226646&r2=226647&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/DelRequest.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/DelRequest.java
Sun Jul 31 08:16:33 2005
@@ -88,7 +88,7 @@
}
/**
- * Compute the DelRequest length
+ * Encode the DelRequest message to a PDU.
*
* DelRequest :
*
Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ExtendedRequest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ExtendedRequest.java?rev=226647&r1=226646&r2=226647&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ExtendedRequest.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ExtendedRequest.java
Sun Jul 31 08:16:33 2005
@@ -16,7 +16,12 @@
*/
package org.apache.asn1.ldap.pojo;
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
+import org.apache.asn1.EncoderException;
import org.apache.asn1.ber.tlv.Length;
+import org.apache.asn1.ldap.codec.LdapConstants;
import org.apache.asn1.primitives.OID;
import org.apache.asn1.primitives.OctetString;
@@ -34,10 +39,13 @@
//~ Instance fields ----------------------------------------------------------------------------
/** The name */
- private OID name;
+ private OID requestName;
/** The value */
- private OctetString value;
+ private OctetString requestValue;
+
+ /** The extended request length */
+ private transient int extendedRequestLength;
//~ Constructors -------------------------------------------------------------------------------
@@ -54,41 +62,41 @@
/**
* Get the extended request name
*
- * @return Returns the name.
+ * @return Returns the request name.
*/
- public String getName()
+ public String getRequestName()
{
- return ( ( name == null ) ? "" : name.toString() );
+ return ( ( requestName == null ) ? "" : requestName.toString() );
}
/**
* Set the extended request name
*
- * @param name The name to set.
+ * @param requestName The request name to set.
*/
- public void setName( OID name )
+ public void setRequestName( OID requestName )
{
- this.name = name;
+ this.requestName = requestName;
}
/**
* Get the extended request value
*
- * @return Returns the value.
+ * @return Returns the request value.
*/
- public OctetString getValue()
+ public OctetString getRequestValue()
{
- return value;
+ return requestValue;
}
/**
* Set the extended request value
*
- * @param value The value to set.
+ * @param requestValue The request value to set.
*/
- public void setValue( OctetString value )
+ public void setRequestValue( OctetString requestValue )
{
- this.value = value;
+ this.requestValue = requestValue;
}
/**
@@ -108,17 +116,75 @@
*/
public int computeLength()
{
- int extendedRequestLength = 1 + Length.getNbBytes( name.getOIDLength() ) + name.getOIDLength();
+ extendedRequestLength = 1 + Length.getNbBytes( requestName.getOIDLength() ) + requestName.getOIDLength();
- if ( value != null)
+ if ( requestValue != null)
{
- extendedRequestLength += 1 + Length.getNbBytes( value.getLength() ) + value.getLength();
+ extendedRequestLength += 1 + Length.getNbBytes( requestValue.getLength() ) +
requestValue.getLength();
}
return 1 + Length.getNbBytes( extendedRequestLength ) + extendedRequestLength;
}
/**
+ * Encode the ExtendedRequest message to a PDU.
+ *
+ * ExtendedRequest :
+ *
+ * 0x80 LL resquest name
+ * [0x81 LL request value]
+ *
+ * @param buffer The buffer where to put the PDU
+ * @return The PDU.
+ */
+ public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+ {
+ if (buffer == null)
+ {
+ throw new EncoderException("Cannot put a PDU in a null buffer !");
+ }
+
+ try
+ {
+ // The BindResponse Tag
+ buffer.put( LdapConstants.EXTENDED_REQUEST_TAG );
+ buffer.put( Length.getBytes( extendedRequestLength ) );
+
+ // The requestName, if any
+ if ( requestName == null )
+ {
+ throw new EncoderException("The request name must not be null");
+ }
+
+ buffer.put( (byte)LdapConstants.EXTENDED_REQUEST_NAME_TAG );
+ buffer.put( Length.getBytes( requestName.getOIDLength() ) );
+
+ if ( requestName.getOIDLength() != 0 )
+ {
+ buffer.put( requestName.getOID() );
+ }
+
+ // The requestValue, if any
+ if ( requestValue != null )
+ {
+ buffer.put( (byte)LdapConstants.EXTENDED_REQUEST_VALUE_TAG );
+ buffer.put( Length.getBytes( requestValue.getLength() ) );
+
+ if ( requestValue.getLength() != 0 )
+ {
+ buffer.put( requestValue.getValue() );
+ }
+ }
+ }
+ catch ( BufferOverflowException boe )
+ {
+ throw new EncoderException("The PDU buffer size is too small !");
+ }
+
+ return buffer;
+ }
+
+ /**
* Get a String representation of an Extended Request
*
* @return an Extended Request String
@@ -128,11 +194,11 @@
StringBuffer sb = new StringBuffer();
sb.append( " Extended request\n" );
- sb.append( " Request name : '" ).append( name.toString() ).append( "'\n" );
+ sb.append( " Request name : '" ).append( requestName.toString() ).append(
"'\n" );
- if ( value != null )
+ if ( requestValue != null )
{
- sb.append( " Request value : '" ).append( value.toString() ).append( "'\n"
);
+ sb.append( " Request value : '" ).append( requestValue.toString() ).append(
"'\n" );
}
return sb.toString();
Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ExtendedResponse.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ExtendedResponse.java?rev=226647&r1=226646&r2=226647&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ExtendedResponse.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ExtendedResponse.java
Sun Jul 31 08:16:33 2005
@@ -16,7 +16,12 @@
*/
package org.apache.asn1.ldap.pojo;
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
+import org.apache.asn1.EncoderException;
import org.apache.asn1.ber.tlv.Length;
+import org.apache.asn1.ldap.codec.LdapConstants;
import org.apache.asn1.primitives.OID;
import org.apache.asn1.primitives.OctetString;
@@ -35,10 +40,13 @@
//~ Instance fields ----------------------------------------------------------------------------
/** The name */
- private OID name;
+ private OID responseName;
/** The response */
private OctetString response;
+
+ /** The extended response length */
+ private transient int extendedResponseLength;
//~ Constructors -------------------------------------------------------------------------------
@@ -57,9 +65,9 @@
*
* @return Returns the name.
*/
- public String getName()
+ public String getResponseName()
{
- return ( ( name == null ) ? "" : name.toString() );
+ return ( ( responseName == null ) ? "" : responseName.toString() );
}
/**
@@ -67,9 +75,9 @@
*
* @param name The name to set.
*/
- public void setName( OID name )
+ public void setResponseName( OID responseName )
{
- this.name = name;
+ this.responseName = responseName;
}
/**
@@ -113,12 +121,12 @@
public int computeLength()
{
- int extendedResponseLength = super.computeLength();
+ extendedResponseLength = super.computeLength();
- if ( name != null )
+ if ( responseName != null )
{
- extendedResponseLength += 1 + Length.getNbBytes( name.getOIDLength() ) +
- name.getOIDLength();
+ extendedResponseLength += 1 + Length.getNbBytes( responseName.getOIDLength()
) +
+ responseName.getOIDLength();
if ( response != null )
{
@@ -131,6 +139,66 @@
}
/**
+ * Encode the ExtendedResponse message to a PDU.
+ *
+ * ExtendedResponse :
+ *
+ * LdapResult.encode()
+ * [0x8A LL response name]
+ * [0x8B LL response]
+ *
+ * @param buffer The buffer where to put the PDU
+ * @return The PDU.
+ */
+ public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+ {
+ if (buffer == null)
+ {
+ throw new EncoderException("Cannot put a PDU in a null buffer !");
+ }
+
+ try
+ {
+ // The BindResponse Tag
+ buffer.put( LdapConstants.EXTENDED_RESPONSE_TAG );
+ buffer.put( Length.getBytes( extendedResponseLength ) );
+
+ // The LdapResult
+ super.encode(buffer);
+
+ // The responseName, if any
+ if ( responseName != null )
+ {
+ buffer.put( (byte)LdapConstants.EXTENDED_RESPONSE_RESPONSE_NAME_TAG );
+ buffer.put( Length.getBytes( responseName.getOIDLength() ) );
+
+ if ( responseName.getOIDLength() != 0 )
+ {
+ buffer.put( responseName.getOID() );
+ }
+ }
+
+ // The response, if any
+ if ( response != null )
+ {
+ buffer.put( (byte)LdapConstants.EXTENDED_RESPONSE_RESPONSE_TAG );
+ buffer.put( Length.getBytes( response.getLength() ) );
+
+ if ( response.getLength() != 0 )
+ {
+ buffer.put( response.getValue() );
+ }
+ }
+ }
+ catch ( BufferOverflowException boe )
+ {
+ throw new EncoderException("The PDU buffer size is too small !");
+ }
+
+ return buffer;
+ }
+
+ /**
* Get a String representation of an ExtendedResponse
*
* @return An ExtendedResponse String
@@ -143,9 +211,9 @@
sb.append( " Extended Response\n" );
sb.append( super.toString() );
- if ( name != null )
+ if ( responseName != null )
{
- sb.append( " Response name :'" ).append( name.toString() ).append( "'\n"
);
+ sb.append( " Response name :'" ).append( responseName.toString() ).append(
"'\n" );
}
if ( response != null )
Modified: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/BindResponseTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/BindResponseTest.java?rev=226647&r1=226646&r2=226647&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/BindResponseTest.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/BindResponseTest.java
Sun Jul 31 08:16:33 2005
@@ -19,10 +19,12 @@
import java.nio.ByteBuffer;
import org.apache.asn1.DecoderException;
+import org.apache.asn1.EncoderException;
import org.apache.asn1.ber.Asn1Decoder;
import org.apache.asn1.ber.containers.IAsn1Container;
import org.apache.asn1.ldap.pojo.BindResponse;
import org.apache.asn1.ldap.pojo.LdapMessage;
+import org.apache.asn1.util.StringUtils;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
@@ -70,6 +72,7 @@
// serverSaslCreds [7] OCTET STRING OPTIONAL }
} );
+ String decodedPdu = StringUtils.dumpBytes( stream.array() );
stream.flip();
// Allocate a LdapMessage Container
@@ -97,6 +100,21 @@
// Check the length
Assert.assertEquals(0x2D, message.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb = message.encode( null );
+
+ String encodedPdu = StringUtils.dumpBytes( bb.array() );
+
+ Assert.assertEquals(encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ Assert.fail( ee.getMessage() );
+ }
}
/**
@@ -128,6 +146,7 @@
(byte)0x87, 0x02, 'A', 'B' // serverSaslCreds [7] OCTET STRING OPTIONAL }
} );
+ String decodedPdu = StringUtils.dumpBytes( stream.array() );
stream.flip();
// Allocate a LdapMessage Container
@@ -156,5 +175,20 @@
// Check the length
Assert.assertEquals(0x31, message.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb = message.encode( null );
+
+ String encodedPdu = StringUtils.dumpBytes( bb.array() );
+
+ Assert.assertEquals(encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ Assert.fail( ee.getMessage() );
+ }
}
}
Modified: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/ExtendedRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/ExtendedRequestTest.java?rev=226647&r1=226646&r2=226647&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/ExtendedRequestTest.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/ExtendedRequestTest.java
Sun Jul 31 08:16:33 2005
@@ -21,10 +21,12 @@
import javax.naming.NamingException;
import org.apache.asn1.DecoderException;
+import org.apache.asn1.EncoderException;
import org.apache.asn1.ber.Asn1Decoder;
import org.apache.asn1.ber.containers.IAsn1Container;
import org.apache.asn1.ldap.pojo.ExtendedRequest;
import org.apache.asn1.ldap.pojo.LdapMessage;
+import org.apache.asn1.util.StringUtils;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
@@ -67,6 +69,7 @@
(byte)0x81, 0x05, 'v', 'a', 'l', 'u', 'e'
} );
+ String decodedPdu = StringUtils.dumpBytes( stream.array() );
stream.flip();
// Allocate a LdapMessage Container
@@ -88,11 +91,26 @@
ExtendedRequest extendedRequest = message.getExtendedRequest();
Assert.assertEquals( 1, message.getMessageId() );
- Assert.assertEquals( "1.3.6.1.5.5.2", extendedRequest.getName() );
- Assert.assertEquals( "value", extendedRequest.getValue().toString() );
+ Assert.assertEquals( "1.3.6.1.5.5.2", extendedRequest.getRequestName() );
+ Assert.assertEquals( "value", extendedRequest.getRequestValue().toString() );
// Check the length
Assert.assertEquals(0x16, message.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb = message.encode( null );
+
+ String encodedPdu = StringUtils.dumpBytes( bb.array() );
+
+ Assert.assertEquals(encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ Assert.fail( ee.getMessage() );
+ }
}
/**
@@ -115,6 +133,7 @@
(byte)0x80, 0x06, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x02,
} );
+ String decodedPdu = StringUtils.dumpBytes( stream.array() );
stream.flip();
// Allocate a LdapMessage Container
@@ -136,9 +155,24 @@
ExtendedRequest extendedRequest = message.getExtendedRequest();
Assert.assertEquals( 1, message.getMessageId() );
- Assert.assertEquals( "1.3.6.1.5.5.2", extendedRequest.getName() );
+ Assert.assertEquals( "1.3.6.1.5.5.2", extendedRequest.getRequestName() );
// Check the length
Assert.assertEquals(0x0F, message.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb = message.encode( null );
+
+ String encodedPdu = StringUtils.dumpBytes( bb.array() );
+
+ Assert.assertEquals(encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ Assert.fail( ee.getMessage() );
+ }
}
}
Modified: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/ExtendedResponseTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/ExtendedResponseTest.java?rev=226647&r1=226646&r2=226647&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/ExtendedResponseTest.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/ExtendedResponseTest.java
Sun Jul 31 08:16:33 2005
@@ -21,10 +21,12 @@
import javax.naming.NamingException;
import org.apache.asn1.DecoderException;
+import org.apache.asn1.EncoderException;
import org.apache.asn1.ber.Asn1Decoder;
import org.apache.asn1.ber.containers.IAsn1Container;
import org.apache.asn1.ldap.pojo.ExtendedResponse;
import org.apache.asn1.ldap.pojo.LdapMessage;
+import org.apache.asn1.util.StringUtils;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
@@ -77,6 +79,7 @@
(byte)0x8B, 0x05, 'v', 'a', 'l', 'u', 'e'
} );
+ String decodedPdu = StringUtils.dumpBytes( stream.array() );
stream.flip();
// Allocate a LdapMessage Container
@@ -101,11 +104,26 @@
Assert.assertEquals( 0, extendedResponse.getLdapResult().getResultCode() );
Assert.assertEquals( "uid=akarasulu,dc=example,dc=com", extendedResponse.getLdapResult().getMatchedDN()
);
Assert.assertEquals( "", extendedResponse.getLdapResult().getErrorMessage() );
- Assert.assertEquals( "1.3.6.1.5.5.2", extendedResponse.getName() );
+ Assert.assertEquals( "1.3.6.1.5.5.2", extendedResponse.getResponseName() );
Assert.assertEquals( "value", extendedResponse.getResponse().toString() );
// Check the length
Assert.assertEquals(0x3C, message.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb = message.encode( null );
+
+ String encodedPdu = StringUtils.dumpBytes( bb.array() );
+
+ Assert.assertEquals(encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ Assert.fail( ee.getMessage() );
+ }
}
/**
@@ -136,6 +154,7 @@
// referral [3] Referral OPTIONAL }
// requestName [0] LDAPOID,
} );
+ String decodedPdu = StringUtils.dumpBytes( stream.array() );
stream.flip();
// Allocate a LdapMessage Container
@@ -163,5 +182,20 @@
// Check the length
Assert.assertEquals(0x2D, message.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb = message.encode( null );
+
+ String encodedPdu = StringUtils.dumpBytes( bb.array() );
+
+ Assert.assertEquals(encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ Assert.fail( ee.getMessage() );
+ }
}
}
|