From 8a441f0c5003f4b87b9c2057de3e6e9e06f14607 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 26 Mar 2013 11:46:31 +0000
Subject: [PATCH] OPENDJ-832 Leverage the work queue for processing requests received on the HTTP connection handler

---
 opendj3/opendj-server2x-adapter/src/main/java/org/forgerock/opendj/adapter/server2x/Converters.java         |  237 ++++++++++++++++++++++++++++++++++++++++++++++-
 opendj3/opendj-server2x-adapter/src/main/java/org/forgerock/opendj/adapter/server2x/Adapters.java           |   32 ++----
 opendj3/opendj-server2x-adapter/src/test/java/org/forgerock/opendj/adapter/server2x/ConvertersTestCase.java |    9 -
 3 files changed, 246 insertions(+), 32 deletions(-)

diff --git a/opendj3/opendj-server2x-adapter/src/main/java/org/forgerock/opendj/adapter/server2x/Adapters.java b/opendj3/opendj-server2x-adapter/src/main/java/org/forgerock/opendj/adapter/server2x/Adapters.java
index a7c15b9..f245500 100644
--- a/opendj3/opendj-server2x-adapter/src/main/java/org/forgerock/opendj/adapter/server2x/Adapters.java
+++ b/opendj3/opendj-server2x-adapter/src/main/java/org/forgerock/opendj/adapter/server2x/Adapters.java
@@ -23,7 +23,6 @@
  *
  *      Copyright 2013 ForgeRock AS.
  */
-
 package org.forgerock.opendj.adapter.server2x;
 
 import java.net.InetAddress;
@@ -81,11 +80,8 @@
 
 import com.forgerock.opendj.util.CompletedFutureResult;
 
-import static org.forgerock.opendj.adapter.server2x.StaticUtils.from;
-import static org.forgerock.opendj.adapter.server2x.StaticUtils.to;
-import static org.forgerock.opendj.adapter.server2x.StaticUtils.toModifications;
-import static org.forgerock.opendj.adapter.server2x.StaticUtils.getCredentials;
-import static org.forgerock.opendj.ldap.ByteString.valueOf;
+import static org.forgerock.opendj.adapter.server2x.Converters.*;
+import static org.forgerock.opendj.ldap.ByteString.*;
 
 /**
  * This class provides a connection factory and an adapter for the OpenDJ 2.x
@@ -231,7 +227,7 @@
                                         .getAttributes()), to(request.getControls()),
                                 internalSearchListener);
 
-                return StaticUtils.getResponseResult(internalSO);
+                return getResponseResult(internalSO);
             }
 
             @Override
@@ -241,24 +237,20 @@
 
             @Override
             public Result modifyDN(final ModifyDNRequest request) throws ErrorResultException {
-
                 final ModifyDNOperation modifyDNOperation =
                         icc.processModifyDN(to(valueOf(request.getName())), to(valueOf(request
                                 .getNewRDN())), request.isDeleteOldRDN(),
                                 (request.getNewSuperior() != null ? to(valueOf(request
                                         .getNewSuperior())) : null), to(request.getControls()));
-                return StaticUtils.getResponseResult(modifyDNOperation);
-
+                return getResponseResult(modifyDNOperation);
             }
 
             @Override
             public Result modify(final ModifyRequest request) throws ErrorResultException {
-
                 final ModifyOperation modifyOperation =
                         icc.processModify(to(valueOf(request.getName())), toModifications(request
                                 .getModifications()), to(request.getControls()));
-                return StaticUtils.getResponseResult(modifyOperation);
-
+                return getResponseResult(modifyOperation);
             }
 
             @Override
@@ -280,7 +272,7 @@
                         icc.processExtendedOperation(request.getOID(), to(request.getValue()),
                                 to(request.getControls()));
 
-                final Result result = StaticUtils.getResponseResult(extendedOperation);
+                final Result result = getResponseResult(extendedOperation);
                 final GenericExtendedResult genericExtendedResult =
                         Responses.newGenericExtendedResult(result.getResultCode())
                                 .setDiagnosticMessage(result.getDiagnosticMessage()).setMatchedDN(
@@ -308,21 +300,19 @@
             public Result delete(final DeleteRequest request) throws ErrorResultException {
                 final DeleteOperation deleteOperation =
                         icc.processDelete(to(valueOf(request.getName())), to(request.getControls()));
-                return StaticUtils.getResponseResult(deleteOperation);
-
+                return getResponseResult(deleteOperation);
             }
 
             @Override
             public CompareResult compare(final CompareRequest request) throws ErrorResultException {
-
                 final CompareOperation compareOperation =
                         icc.processCompare(to(valueOf(request.getName())), request
                                 .getAttributeDescription().toString(), to(request
                                 .getAssertionValueAsString()), to(request.getControls()));
 
                 CompareResult result =
-                        Responses.newCompareResult(StaticUtils.getResultCode(compareOperation));
-                result = StaticUtils.getResponseResult(compareOperation, result);
+                        Responses.newCompareResult(getResultCode(compareOperation));
+                result = getResponseResult(compareOperation, result);
                 return result;
             }
 
@@ -364,7 +354,7 @@
                             .newResult(ResultCode.AUTH_METHOD_NOT_SUPPORTED));
                 }
                 BindResult result =
-                        Responses.newBindResult(StaticUtils.getResultCode(bindOperation));
+                        Responses.newBindResult(getResultCode(bindOperation));
                 result.setServerSASLCredentials(from(bindOperation.getSASLCredentials()));
 
                 if (result.isSuccess()) {
@@ -384,7 +374,7 @@
                 final AddOperation addOperation =
                         icc.processAdd(to(valueOf(request.getName())), to(request
                                 .getAllAttributes()), to(request.getControls()));
-                return StaticUtils.getResponseResult(addOperation);
+                return getResponseResult(addOperation);
             }
 
             @Override
diff --git a/opendj3/opendj-server2x-adapter/src/main/java/org/forgerock/opendj/adapter/server2x/StaticUtils.java b/opendj3/opendj-server2x-adapter/src/main/java/org/forgerock/opendj/adapter/server2x/Converters.java
similarity index 64%
rename from opendj3/opendj-server2x-adapter/src/main/java/org/forgerock/opendj/adapter/server2x/StaticUtils.java
rename to opendj3/opendj-server2x-adapter/src/main/java/org/forgerock/opendj/adapter/server2x/Converters.java
index f5fd78e..21e0bba 100644
--- a/opendj3/opendj-server2x-adapter/src/main/java/org/forgerock/opendj/adapter/server2x/StaticUtils.java
+++ b/opendj3/opendj-server2x-adapter/src/main/java/org/forgerock/opendj/adapter/server2x/Converters.java
@@ -62,27 +62,51 @@
 /**
  * Common utility methods.
  */
-final class StaticUtils {
+public final class Converters
+{
 
     // Prevent instantiation.
-    private StaticUtils() {
+    private Converters() {
         throw new AssertionError();
     }
 
+    /**
+     * Converts from OpenDJ LDAP SDK {@link DereferenceAliasesPolicy} to OpenDJ
+     * server {@link DereferencePolicy}.
+     *
+     * @param dereferenceAliasesPolicy
+     *          value to convert
+     * @return the converted value
+     */
     static final org.opends.server.types.DereferencePolicy to(
             final DereferenceAliasesPolicy dereferenceAliasesPolicy) {
         return DereferencePolicy.values()[dereferenceAliasesPolicy.intValue()];
     }
 
+    /**
+     * Converts from OpenDJ LDAP SDK {@link DN} to OpenDJ server
+     * {@link org.opends.server.types.DN}.
+     *
+     * @param userDn
+     *          value to convert
+     * @return the converted value
+     */
     static final org.opends.server.types.DN to(final DN userDn) {
         try {
             return org.opends.server.types.DN.decode(userDn.toString());
         } catch (Exception e) {
             throw new IllegalStateException(e.getMessage());
         }
-
     }
 
+    /**
+     * Converts from OpenDJ LDAP SDK {@link ByteString} to OpenDJ server
+     * {@link org.opends.server.types.ByteString}.
+     *
+     * @param value
+     *          value to convert
+     * @return the converted value
+     */
     static final org.opends.server.types.ByteString to(ByteString value) {
         if (value != null) {
             return org.opends.server.types.ByteString.wrap(value.toByteArray());
@@ -90,11 +114,27 @@
         return null;
     }
 
+    /**
+     * Converts from OpenDJ LDAP SDK {@link org.forgerock.opendj.ldap.SearchScope}
+     * to OpenDJ server {@link org.opends.server.types.SearchScope}.
+     *
+     * @param searchScope
+     *          value to convert
+     * @return the converted value
+     */
     static final org.opends.server.types.SearchScope to(
             final org.forgerock.opendj.ldap.SearchScope searchScope) {
         return SearchScope.values()[searchScope.intValue()];
     }
 
+    /**
+     * Converts from OpenDJ LDAP SDK {@link org.forgerock.opendj.ldap.Filter} to
+     * OpenDJ server {@link org.opends.server.types.RawFilter}.
+     *
+     * @param filter
+     *          value to convert
+     * @return the converted value
+     */
     static final org.opends.server.types.RawFilter to(final org.forgerock.opendj.ldap.Filter filter) {
         org.opends.server.protocols.ldap.LDAPFilter ldapFilter = null;
         try {
@@ -105,20 +145,54 @@
         return ldapFilter;
     }
 
+    /**
+     * Converts from OpenDJ LDAP SDK
+     * {@link org.forgerock.opendj.ldap.responses.SearchResultReference} to OpenDJ
+     * server {@link org.opends.server.types.SearchResultReference}.
+     *
+     * @param searchResultReference
+     *          value to convert
+     * @return the converted value
+     */
     static final org.opends.server.types.SearchResultReference to(
             final org.forgerock.opendj.ldap.responses.SearchResultReference searchResultReference) {
         return new SearchResultReference(searchResultReference.getURIs(), to(searchResultReference
                 .getControls()));
     }
 
+    /**
+     * Converts from OpenDJ LDAP SDK {@link String} to OpenDJ server
+     * {@link org.opends.server.types.ByteString}.
+     *
+     * @param value
+     *          value to convert
+     * @return the converted value
+     */
     static final org.opends.server.types.ByteString to(final String value) {
         return org.opends.server.types.ByteString.valueOf(value);
     }
 
+    /**
+     * Converts from OpenDJ LDAP SDK {@link Control} to OpenDJ server
+     * {@link org.opends.server.protocols.ldap.LDAPControl}.
+     *
+     * @param control
+     *          value to convert
+     * @return the converted value
+     */
     static final org.opends.server.protocols.ldap.LDAPControl to(final Control control) {
         return new LDAPControl(control.getOID(), control.isCritical(), to(control.getValue()));
     }
 
+    /**
+     * Converts from a <code>List</code> of OpenDJ LDAP SDK
+     * {@link org.forgerock.opendj.ldap.controls.Control} to a <code>List</code>
+     * of OpenDJ server {@link org.opends.server.types.Control}.
+     *
+     * @param listOfControl
+     *          value to convert
+     * @return the converted value
+     */
     static final List<org.opends.server.types.Control> to(
             final List<org.forgerock.opendj.ldap.controls.Control> listOfControl) {
         List<org.opends.server.types.Control> toListofControl =
@@ -129,6 +203,14 @@
         return toListofControl;
     }
 
+    /**
+     * Converts from OpenDJ LDAP SDK {@link org.forgerock.opendj.ldap.Attribute}
+     * to OpenDJ server {@link org.opends.server.types.RawAttribute}.
+     *
+     * @param attribute
+     *          value to convert
+     * @return the converted value
+     */
     static final org.opends.server.types.RawAttribute to(
             final org.forgerock.opendj.ldap.Attribute attribute) {
         ArrayList<org.opends.server.types.ByteString> listAttributeValues =
@@ -141,6 +223,15 @@
         return new LDAPAttribute(attribute.getAttributeDescriptionAsString(), listAttributeValues);
     }
 
+    /**
+     * Converts from an <code>Iterable</code> of OpenDJ LDAP SDK
+     * {@link org.forgerock.opendj.ldap.Attribute} to a <code>List</code> of
+     * OpenDJ server {@link org.opends.server.types.RawAttribute}.
+     *
+     * @param listOfAttributes
+     *          value to convert
+     * @return the converted value
+     */
     static final List<org.opends.server.types.RawAttribute> to(
             final Iterable<org.forgerock.opendj.ldap.Attribute> listOfAttributes) {
         List<org.opends.server.types.RawAttribute> toListofAttributes =
@@ -152,12 +243,30 @@
         return toListofAttributes;
     }
 
+    /**
+     * Converts from OpenDJ LDAP SDK
+     * {@link org.forgerock.opendj.ldap.Modification} to OpenDJ server
+     * {@link org.opends.server.types.RawModification}.
+     *
+     * @param modification
+     *          value to convert
+     * @return the converted value
+     */
     static final org.opends.server.types.RawModification to(
             final org.forgerock.opendj.ldap.Modification modification) {
         return new LDAPModification(to(modification.getModificationType()), to(modification
                 .getAttribute()));
     }
 
+    /**
+     * Converts from a <code>List</code> of OpenDJ LDAP SDK
+     * {@link org.forgerock.opendj.ldap.Modification} to a <code>List</code> of
+     * OpenDJ server {@link org.opends.server.types.RawModification}.
+     *
+     * @param listOfModifications
+     *          value to convert
+     * @return the converted value
+     */
     static final List<org.opends.server.types.RawModification> toModifications(
             final List<org.forgerock.opendj.ldap.Modification> listOfModifications) {
         List<org.opends.server.types.RawModification> toListofModifications =
@@ -168,11 +277,28 @@
         return toListofModifications;
     }
 
+    /**
+     * Converts from OpenDJ LDAP SDK
+     * {@link org.forgerock.opendj.ldap.ModificationType} to OpenDJ server
+     * {@link org.opends.server.types.ModificationType}.
+     *
+     * @param modificationType
+     *          value to convert
+     * @return the converted value
+     */
     static final org.opends.server.types.ModificationType to(
             final org.forgerock.opendj.ldap.ModificationType modificationType) {
         return ModificationType.values()[modificationType.intValue()];
     }
 
+    /**
+     * Converts from OpenDJ server {@link org.opends.server.types.ByteString} to
+     * OpenDJ LDAP SDK {@link ByteString}.
+     *
+     * @param value
+     *          value to convert
+     * @return the converted value
+     */
     static final ByteString from(final org.opends.server.types.ByteString value) {
         if (value != null) {
             return ByteString.wrap(value.toByteArray());
@@ -180,11 +306,28 @@
         return null;
     }
 
+    /**
+     * Converts from OpenDJ server
+     * {@link org.opends.server.protocols.ldap.LDAPControl} to OpenDJ LDAP SDK
+     * {@link Control}.
+     *
+     * @param ldapControl
+     *          value to convert
+     * @return the converted value
+     */
     static final Control from(final org.opends.server.protocols.ldap.LDAPControl ldapControl) {
         return GenericControl.newControl(ldapControl.getOID(), ldapControl.isCritical(),
                 from(ldapControl.getValue()));
     }
 
+    /**
+     * Converts from OpenDJ server {@link org.opends.server.types.Control} to
+     * OpenDJ LDAP SDK {@link Control}.
+     *
+     * @param control
+     *          value to convert
+     * @return the converted value
+     */
     static final Control from(final org.opends.server.types.Control control) {
 
         String oid = null;
@@ -207,8 +350,6 @@
         try {
             sdkReaderASN1.readStartSequence();
             oid = sdkReaderASN1.readOctetStringAsString();
-            isCritical = false;
-            value = null;
             if (sdkReaderASN1.hasNextElement()
                     && (sdkReaderASN1.peekType() == org.forgerock.opendj.asn1.ASN1.UNIVERSAL_BOOLEAN_TYPE)) {
                 isCritical = sdkReaderASN1.readBoolean();
@@ -227,6 +368,15 @@
         return GenericControl.newControl(oid, isCritical, value);
     }
 
+    /**
+     * Converts from a <code>List</code> of OpenDJ server
+     * {@link org.opends.server.types.Control} to a <code>List</code> of OpenDJ
+     * LDAP SDK {@link org.forgerock.opendj.ldap.controls.Control}.
+     *
+     * @param listOfControl
+     *          value to convert
+     * @return the converted value
+     */
     static final List<org.forgerock.opendj.ldap.controls.Control> from(
             final List<org.opends.server.types.Control> listOfControl) {
         List<org.forgerock.opendj.ldap.controls.Control> fromListofControl =
@@ -237,11 +387,28 @@
         return fromListofControl;
     }
 
+    /**
+     * Converts from OpenDJ server
+     * {@link org.opends.server.types.SearchResultReference} to OpenDJ LDAP SDK
+     * {@link org.forgerock.opendj.ldap.responses.SearchResultReference}.
+     *
+     * @param srvResultReference
+     *          value to convert
+     * @return the converted value
+     */
     static final org.forgerock.opendj.ldap.responses.SearchResultReference from(
             final org.opends.server.types.SearchResultReference srvResultReference) {
         return Responses.newSearchResultReference(srvResultReference.getReferralURLString());
     }
 
+    /**
+     * Converts from OpenDJ server {@link org.opends.server.types.Attribute} to
+     * OpenDJ LDAP SDK {@link org.forgerock.opendj.ldap.Attribute}.
+     *
+     * @param attribute
+     *          value to convert
+     * @return the converted value
+     */
     static final org.forgerock.opendj.ldap.Attribute from(
             final org.opends.server.types.Attribute attribute) {
         Attribute sdkAttribute = new LinkedAttribute(attribute.getNameWithOptions());
@@ -251,6 +418,15 @@
         return sdkAttribute;
     }
 
+    /**
+     * Converts from an <code>Iterable</code> of OpenDJ server
+     * {@link org.opends.server.types.Attribute} to a <code>List</code> of OpenDJ
+     * LDAP SDK {@link org.forgerock.opendj.ldap.Attribute}.
+     *
+     * @param listOfAttributes
+     *          value to convert
+     * @return the converted value
+     */
     static final List<org.forgerock.opendj.ldap.Attribute> from(
             final Iterable<org.opends.server.types.Attribute> listOfAttributes) {
         List<org.forgerock.opendj.ldap.Attribute> fromListofAttributes =
@@ -262,6 +438,15 @@
         return fromListofAttributes;
     }
 
+    /**
+     * Converts from OpenDJ server
+     * {@link org.opends.server.types.SearchResultEntry} to OpenDJ LDAP SDK
+     * {@link org.forgerock.opendj.ldap.responses.SearchResultEntry}.
+     *
+     * @param srvResultEntry
+     *          value to convert
+     * @return the converted value
+     */
     static final org.forgerock.opendj.ldap.responses.SearchResultEntry from(
             final org.opends.server.types.SearchResultEntry srvResultEntry) {
 
@@ -282,6 +467,22 @@
         return searchResultEntry;
     }
 
+    /**
+     * Populates the result object with the operation details and return the
+     * result object if it was successful. Otherwise, it throws an
+     * {@link ErrorResultException}.
+     *
+     * @param <T>
+     *          the type of the result object
+     * @param operation
+     *          used to populate the result
+     * @param result
+     *          the result object to populate from the Operation
+     * @return the result if successful, an {@link ErrorResultException} is thrown
+     *         otherwise
+     * @throws ErrorResultException
+     *           when an error occurs
+     */
     static final <T extends Result> T getResponseResult(final Operation operation, final T result)
             throws ErrorResultException {
         if (operation.getReferralURLs() != null) {
@@ -305,15 +506,41 @@
         }
     }
 
+    /**
+     * Converts the OpenDJ server {@link Operation} object into an OpenDJ LDAP SDK
+     * {@link Result} object.
+     *
+     * @param operation
+     *          value to convert
+     * @return the converted value
+     * @throws ErrorResultException
+     *           when an error occurs
+     */
     static final Result getResponseResult(final Operation operation) throws ErrorResultException {
         Result result = Responses.newResult(getResultCode(operation));
         return getResponseResult(operation, result);
     }
 
+    /**
+     * Returns the OpenDJ LDAP SDK {@link ResultCode} extracted out of the OpenDJ
+     * server {@link Operation}.
+     *
+     * @param operation
+     *          value to convert
+     * @return the converted value
+     */
     static final ResultCode getResultCode(final Operation operation) {
         return ResultCode.valueOf(operation.getResultCode().getIntValue());
     }
 
+    /**
+     * Converts from <code>byte[]</code> to OpenDJ server
+     * {@link org.opends.server.types.ByteString}.
+     * 
+     * @param authenticationValue
+     *          value to convert
+     * @return the converted value
+     */
     static final org.opends.server.types.ByteString getCredentials(final byte[] authenticationValue) {
         final org.opends.server.protocols.asn1.ASN1Reader reader =
                 ASN1.getReader(authenticationValue);
diff --git a/opendj3/opendj-server2x-adapter/src/test/java/org/forgerock/opendj/adapter/server2x/StaticUtilsTestCase.java b/opendj3/opendj-server2x-adapter/src/test/java/org/forgerock/opendj/adapter/server2x/ConvertersTestCase.java
similarity index 97%
rename from opendj3/opendj-server2x-adapter/src/test/java/org/forgerock/opendj/adapter/server2x/StaticUtilsTestCase.java
rename to opendj3/opendj-server2x-adapter/src/test/java/org/forgerock/opendj/adapter/server2x/ConvertersTestCase.java
index a39aa11..ccd7856 100644
--- a/opendj3/opendj-server2x-adapter/src/test/java/org/forgerock/opendj/adapter/server2x/StaticUtilsTestCase.java
+++ b/opendj3/opendj-server2x-adapter/src/test/java/org/forgerock/opendj/adapter/server2x/ConvertersTestCase.java
@@ -25,7 +25,8 @@
  */
 package org.forgerock.opendj.adapter.server2x;
 
-import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Assertions.*;
+import static org.forgerock.opendj.adapter.server2x.Converters.*;
 
 import java.net.InetAddress;
 import java.net.UnknownHostException;
@@ -61,10 +62,6 @@
 import org.testng.annotations.BeforeGroups;
 import org.testng.annotations.Test;
 
-import static org.forgerock.opendj.adapter.server2x.StaticUtils.from;
-import static org.forgerock.opendj.adapter.server2x.StaticUtils.to;
-import static org.forgerock.opendj.adapter.server2x.StaticUtils.getCredentials;
-
 /**
  * This class defines a set of tests for the StaticUtils.class.
  * <p>
@@ -77,7 +74,7 @@
  */
 @SuppressWarnings("javadoc")
 @Test()
-public class StaticUtilsTestCase extends ForgeRockTestCase {
+public class ConvertersTestCase extends ForgeRockTestCase {
 
     /**
      * Launched before the tests, this function starts the embedded server.

--
Gitblit v1.10.0