You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2018/09/15 03:35:48 UTC

[directory-ldap-api] branch master updated: o Fixed some StartTransaction implementation errors o Fixed some LOG message

This is an automated email from the ASF dual-hosted git repository.

elecharny pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git


The following commit(s) were added to refs/heads/master by this push:
     new e0baa92  o Fixed some StartTransaction implementation errors o Fixed some LOG message
e0baa92 is described below

commit e0baa924579ea89f4cdfc7b1682ccdab646697a7
Author: Emmanuel Lécharny <el...@symas.com>
AuthorDate: Sat Sep 15 05:35:46 2018 +0200

    o Fixed some StartTransaction implementation errors
    o Fixed some LOG message
---
 .../java/org/apache/directory/api/i18n/I18n.java   |  2 +
 .../apache/directory/api/i18n/errors.properties    |  2 +
 .../StartTransactionResponseImpl.java              | 17 +----
 .../startTransaction/StartTransactionFactory.java  | 10 +--
 .../StartTransactionResponseDecorator.java         | 83 ++++++++++++++++++++++
 .../ads_impl/whoAmI/WhoAmIResponseDecorator.java   |  2 +-
 6 files changed, 95 insertions(+), 21 deletions(-)

diff --git a/i18n/src/main/java/org/apache/directory/api/i18n/I18n.java b/i18n/src/main/java/org/apache/directory/api/i18n/I18n.java
index 75751c0..dba64c2 100644
--- a/i18n/src/main/java/org/apache/directory/api/i18n/I18n.java
+++ b/i18n/src/main/java/org/apache/directory/api/i18n/I18n.java
@@ -363,6 +363,8 @@ public enum I18n
     ERR_08227_AUTHZID_MUST_START_WITH_U_OR_DN( "ERR_08227_AUTHZID_MUST_START_WITH_U_OR_DN" ),
     ERR_08228_DECORATED_SP_NULL( "ERR_08228_DECORATED_SP_NULL" ),
     ERR_08229_UNEXPECTED_SYNC_INFO( "ERR_08229_UNEXPECTED_SYNC_INFO" ),
+    ERR_08230_WHOAMI_PAYLOAD_ENCODING_FAILED( "ERR_08230_WHOAMI_PAYLOAD_ENCODING_FAILED" ),
+    ERR_08231_START_TRANSACTION_PAYLOAD_ENCODING_FAILED( "ERR_08231_START_TRANSACTION_PAYLOAD_ENCODING_FAILED" ),
 
     //     intermediate                     8300-8399
     ERR_08300_REFRESH_DONE_DECODING_FAILED( "ERR_08300_REFRESH_DONE_DECODING_FAILED" ),
diff --git a/i18n/src/main/resources/org/apache/directory/api/i18n/errors.properties b/i18n/src/main/resources/org/apache/directory/api/i18n/errors.properties
index d2aa4cd..0b72ea4 100644
--- a/i18n/src/main/resources/org/apache/directory/api/i18n/errors.properties
+++ b/i18n/src/main/resources/org/apache/directory/api/i18n/errors.properties
@@ -355,6 +355,8 @@ ERR_08226_AUTHZID_TOO_SHORT_MISSING_U_OR_DN=authzId too short. Must starts with
 ERR_08227_AUTHZID_MUST_START_WITH_U_OR_DN=authzId Must starts with either u: or dn:, it starts with {0}
 ERR_08228_DECORATED_SP_NULL=decorated stored procedure request is null
 ERR_08229_UNEXPECTED_SYNC_INFO=Unexpected SynchronizationInfo: {0}
+ERR_08230_WHOAMI_PAYLOAD_ENCODING_FAILED=Failed to encode payload WhoAmIRequest
+ERR_08231_START_TRANSACTION_PAYLOAD_ENCODING_FAILED=Failed to encode payload StartTransactionRequest
 
 # api-ldap-extras-codec intermediate 8300-8399
 ERR_08300_REFRESH_DONE_DECODING_FAILED=failed to decode the refreshDone flag for SyncInfoValueControl
diff --git a/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/startTransaction/StartTransactionResponseImpl.java b/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/startTransaction/StartTransactionResponseImpl.java
index 405f6a9..8e9f8bb 100644
--- a/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/startTransaction/StartTransactionResponseImpl.java
+++ b/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/startTransaction/StartTransactionResponseImpl.java
@@ -58,7 +58,7 @@ public class StartTransactionResponseImpl extends ExtendedResponseImpl implement
      */
     public StartTransactionResponseImpl( int messageId, ResultCodeEnum resultCode, byte[] transactionId )
     {
-        super( messageId );
+        super( messageId, EXTENSION_OID );
 
         switch ( resultCode )
         {
@@ -89,7 +89,7 @@ public class StartTransactionResponseImpl extends ExtendedResponseImpl implement
      */
     public StartTransactionResponseImpl( int messageId, byte[] transactionId )
     {
-        super( messageId );
+        super( messageId, EXTENSION_OID );
         super.getLdapResult().setMatchedDn( null );
         super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
         this.transactionId = Strings.copy( transactionId );
@@ -122,19 +122,6 @@ public class StartTransactionResponseImpl extends ExtendedResponseImpl implement
 
 
     /**
-     * Gets the OID uniquely identifying this extended response (a.k.a. its
-     * name). It's a null value for the Cancel response
-     * 
-     * @return the OID of the extended response type.
-     */
-    @Override
-    public String getResponseName()
-    {
-        return "";
-    }
-
-
-    /**
      * {@inheritDoc}
      */
     @Override
diff --git a/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/startTransaction/StartTransactionFactory.java b/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/startTransaction/StartTransactionFactory.java
index 79a3fb2..bd05b8d 100644
--- a/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/startTransaction/StartTransactionFactory.java
+++ b/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/startTransaction/StartTransactionFactory.java
@@ -98,7 +98,7 @@ public class StartTransactionFactory implements ExtendedOperationFactory
             return ( StartTransactionRequestDecorator ) modelRequest;
         }
 
-        return new StartTransactionRequestDecorator( codec, null );
+        return new StartTransactionRequestDecorator( codec, ( StartTransactionRequest ) modelRequest );
     }
 
 
@@ -106,13 +106,13 @@ public class StartTransactionFactory implements ExtendedOperationFactory
      * {@inheritDoc}
      */
     @Override
-    public StartTransactionResponseDecorator decorate( ExtendedResponse decoratedMessage )
+    public StartTransactionResponseDecorator decorate( ExtendedResponse decoratedResponse )
     {
-        if ( decoratedMessage instanceof StartTransactionResponseDecorator )
+        if ( decoratedResponse instanceof StartTransactionResponseDecorator )
         {
-            return ( StartTransactionResponseDecorator ) decoratedMessage;
+            return ( StartTransactionResponseDecorator ) decoratedResponse;
         }
 
-        return new StartTransactionResponseDecorator( codec, null );
+        return new StartTransactionResponseDecorator( codec, ( StartTransactionResponse ) decoratedResponse );
     }
 }
diff --git a/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/startTransaction/StartTransactionResponseDecorator.java b/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/startTransaction/StartTransactionResponseDecorator.java
index f9942e5..9374f08 100644
--- a/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/startTransaction/StartTransactionResponseDecorator.java
+++ b/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/startTransaction/StartTransactionResponseDecorator.java
@@ -21,9 +21,19 @@ package org.apache.directory.api.ldap.extras.extended.ads_impl.startTransaction;
 
 
 import org.apache.directory.api.ldap.codec.decorators.ExtendedResponseDecorator;
+
+import java.nio.ByteBuffer;
+
+import org.apache.directory.api.asn1.EncoderException;
+import org.apache.directory.api.asn1.ber.tlv.BerValue;
+import org.apache.directory.api.asn1.ber.tlv.TLV;
+import org.apache.directory.api.i18n.I18n;
 import org.apache.directory.api.ldap.codec.api.LdapApiService;
 import org.apache.directory.api.ldap.extras.extended.startTransaction.StartTransactionResponse;
+import org.apache.directory.api.ldap.extras.extended.startTransaction.StartTransactionResponseImpl;
 import org.apache.directory.api.util.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -33,6 +43,9 @@ import org.apache.directory.api.util.Strings;
  */
 public class StartTransactionResponseDecorator extends ExtendedResponseDecorator<StartTransactionResponse> implements StartTransactionResponse
 {
+    /** A logger for this class */
+    private static final Logger LOG = LoggerFactory.getLogger( StartTransactionResponseDecorator.class );
+
     /** The startTransaction response */
     private StartTransactionResponse startTransactionResponse;
 
@@ -53,6 +66,67 @@ public class StartTransactionResponseDecorator extends ExtendedResponseDecorator
      * {@inheritDoc}
      */
     @Override
+    public byte[] getResponseValue()
+    {
+        if ( responseValue == null )
+        {
+            try
+            {
+                responseValue = encodeInternal().array();
+            }
+            catch ( EncoderException e )
+            {
+                LOG.error( I18n.err( I18n.ERR_08231_START_TRANSACTION_PAYLOAD_ENCODING_FAILED ), e );
+                throw new RuntimeException( e );
+            }
+        }
+
+        return responseValue;
+    }
+
+
+    /**
+     * Compute the StartTransactionResponse extended operation length
+     * <pre>
+     * 0x04 L1 transactionId
+     * </pre>
+     * 
+     * @return The extended operation's length
+     */
+    /* no qualifier */int computeLengthInternal()
+    {
+        if ( startTransactionResponse.getTransactionId() != null )
+        {
+            return 1 + TLV.getNbBytes( startTransactionResponse.getTransactionId().length )
+                + startTransactionResponse.getTransactionId().length;
+        }
+        else
+        {
+            return 1 + 1;
+        }
+    }
+
+
+    /**
+     * Encodes the StartTransactionResponse extended operation.
+     * 
+     * @return A ByteBuffer that contains the encoded PDU
+     * @throws EncoderException If anything goes wrong.
+     */
+    /* no qualifier */ByteBuffer encodeInternal() throws EncoderException
+    {
+        ByteBuffer bb = ByteBuffer.allocate( computeLengthInternal() );
+
+        BerValue.encode( bb, startTransactionResponse.getTransactionId() );
+
+        return bb;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
     public void setResponseValue( byte[] responseValue )
     {
         this.responseValue = Strings.copy( responseValue );
@@ -67,4 +141,13 @@ public class StartTransactionResponseDecorator extends ExtendedResponseDecorator
     {
         return startTransactionResponse.getTransactionId();
     }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public void setTransactionId( byte[] transactionId )
+    {
+        ( ( StartTransactionResponseImpl ) getDecorated() ).setTransactionId( transactionId );
+    }
 }
diff --git a/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/whoAmI/WhoAmIResponseDecorator.java b/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/whoAmI/WhoAmIResponseDecorator.java
index 4b0de3e..41040fd 100644
--- a/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/whoAmI/WhoAmIResponseDecorator.java
+++ b/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/whoAmI/WhoAmIResponseDecorator.java
@@ -102,7 +102,7 @@ public class WhoAmIResponseDecorator extends ExtendedResponseDecorator<WhoAmIRes
             }
             catch ( EncoderException e )
             {
-                LOG.error( I18n.err( I18n.ERR_08218_CERT_GENERATE_PAYLOAD_ENCODING_FAILED ), e );
+                LOG.error( I18n.err( I18n.ERR_08230_WHOAMI_PAYLOAD_ENCODING_FAILED ), e );
                 throw new RuntimeException( e );
             }
         }