private boolean addPendingRequest(final RequestContextImpl<?, ?> requestContext) {
      final Integer messageID = requestContext.getMessageID();

      if (isClosed.get()) {
        final LocalizableMessage message = INFO_CLIENT_CONNECTION_CLOSING.get();
        requestContext.handleException(
            newLdapException(ResultCode.UNWILLING_TO_PERFORM, message.toString()));
        return false;
      } else if (pendingRequests.putIfAbsent(messageID, requestContext) != null) {
        final LocalizableMessage message =
            WARN_CLIENT_DUPLICATE_MESSAGE_ID.get(requestContext.getMessageID());
        requestContext.handleException(
            newLdapException(ResultCode.PROTOCOL_ERROR, message.toString()));
        return false;
      } else if (isClosed.get()) {
        /*
         * A concurrent close may have already removed the pending
         * request but it will have only been notified for cancellation.
         */
        pendingRequests.remove(messageID);

        final LocalizableMessage message = INFO_CLIENT_CONNECTION_CLOSING.get();
        requestContext.handleException(
            newLdapException(ResultCode.UNWILLING_TO_PERFORM, message.toString()));
        return false;
      } else {
        /*
         * If the connection is closed now then we just have to pay the
         * cost of invoking the request in the request handler.
         */
        return true;
      }
    }
 /** {@inheritDoc} */
 @Override
 public void checkIfCancelled(final boolean signalTooLate) throws CancelledResultException {
   synchronized (stateLock) {
     switch (state) {
       case PENDING:
         /* No cancel request, so no handlers, just switch state. */
         if (signalTooLate) {
           cancelRequestListeners = null;
           state = RequestState.TOO_LATE;
         }
         break;
       case CANCEL_REQUESTED:
         /*
          * Don't change state: let the handler ack the cancellation
          * request.
          */
         throw (CancelledResultException)
             newLdapException(ResultCode.CANCELLED, cancelRequestReason.toString());
       case TOO_LATE:
         /* Already too late. Nothing to do. */
         break;
       case RESULT_SENT:
       case CANCELLED:
         /*
          * This should not happen - could throw an illegal state
          * exception?
          */
         break;
     }
   }
 }
Ejemplo n.º 3
0
  /**
   * Test to show that reporting an error about an uninitialized variable when generating templates
   * reports the correct line.
   */
  @Test
  public void testParseTemplate() throws Exception {
    String[] lines = {
      /* 0 */ "template: template",
      /* 1 */ "a: {missingVar}",
      /* 2 */ "a: b",
      /* 3 */ "a: c",
      /* 4 */ "",
      /* 5 */ "template: template2",
    };

    // Test must show "missingVar" missing on line 1.
    // Previous behaviour showed "missingVar" on line 5.

    TemplateFile templateFile = new TemplateFile(resourcePath);
    List<LocalizableMessage> warns = new ArrayList<>();

    try {
      templateFile.parse(lines, warns);
    } catch (InitializationException e) {
      String msg = e.getMessage();
      LocalizableMessage msg_locale = ERR_MAKELDIF_TAG_UNDEFINED_ATTRIBUTE.get("missingVar", 1);
      assertEquals(msg, msg_locale.toString(), msg);
    }
  }
Ejemplo n.º 4
0
 /**
  * Performs validation on the specified file to make sure that it is an actual OpenDJ
  * installation.
  *
  * @param rootDirectory File directory candidate
  * @throws IllegalArgumentException if root directory does not appear to be an OpenDJ installation
  *     root. The thrown exception contains a localized message indicating the reason why <code>
  *     rootDirectory</code> is not a valid OpenDJ install root.
  */
 public static void validateRootDirectory(File rootDirectory) throws IllegalArgumentException {
   LocalizableMessage failureReason = null;
   if (rootDirectory == null) {
     failureReason = INFO_ERROR_INSTALL_ROOT_DIR_NULL.get();
   } else if (!rootDirectory.exists()) {
     failureReason = INFO_ERROR_INSTALL_ROOT_DIR_NO_EXIST.get(Utils.getPath(rootDirectory));
   } else if (!rootDirectory.isDirectory()) {
     failureReason = INFO_ERROR_INSTALL_ROOT_DIR_NOT_DIR.get(Utils.getPath(rootDirectory));
   } else {
     String[] children = rootDirectory.list();
     if (children != null) {
       Set<String> childrenSet = CollectionUtils.newHashSet(children);
       for (String dir : REQUIRED_DIRECTORIES) {
         if (!childrenSet.contains(dir)) {
           failureReason =
               INFO_ERROR_INSTALL_ROOT_DIR_NO_DIR.get(Utils.getPath(rootDirectory), dir);
         }
       }
     } else {
       failureReason = INFO_ERROR_INSTALL_ROOT_DIR_EMPTY.get(Utils.getPath(rootDirectory));
     }
   }
   if (failureReason != null) {
     throw new IllegalArgumentException(failureReason.toString());
   }
 }
 /** {@inheritDoc} */
 @Override
 public void removeMember(DN userDN) throws UnsupportedOperationException, DirectoryException {
   // Virtual static groups don't support altering the member list.
   LocalizableMessage message =
       ERR_VIRTUAL_STATIC_GROUP_ALTERING_MEMBERS_NOT_SUPPORTED.get(groupEntryDN);
   throw new UnsupportedOperationException(message.toString());
 }
 /** {@inheritDoc} */
 @Override
 public void removeNestedGroup(DN nestedGroupDN)
     throws UnsupportedOperationException, DirectoryException {
   // Virtual static groups don't support nesting.
   LocalizableMessage message = ERR_VIRTUAL_STATIC_GROUP_NESTING_NOT_SUPPORTED.get();
   throw new UnsupportedOperationException(message.toString());
 }