src/share/classes/com/sun/jndi/ldap/LdapRequest.java

changeset 14206
ab2e99db6702
parent 13707
b4522ab88a12
child 14222
5a272e10d7e7
     1.1 --- a/src/share/classes/com/sun/jndi/ldap/LdapRequest.java	Wed Sep 09 14:18:45 2020 -0400
     1.2 +++ b/src/share/classes/com/sun/jndi/ldap/LdapRequest.java	Wed Sep 09 14:19:14 2020 -0400
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -29,11 +29,14 @@
    1.11  import java.util.concurrent.BlockingQueue;
    1.12  import java.util.concurrent.LinkedBlockingQueue;
    1.13  import javax.naming.CommunicationException;
    1.14 +import javax.naming.NamingException;
    1.15  import java.util.concurrent.TimeUnit;
    1.16  
    1.17  final class LdapRequest {
    1.18  
    1.19      private final static BerDecoder EOF = new BerDecoder(new byte[]{}, -1, 0);
    1.20 +    private final static String CLOSE_MSG = "LDAP connection has been closed";
    1.21 +    private final static String TIMEOUT_MSG_FMT = "LDAP response read timed out, timeout used: %d ms.";
    1.22  
    1.23      LdapRequest next;   // Set/read in synchronized Connection methods
    1.24      final int msgId;          // read-only
    1.25 @@ -95,14 +98,22 @@
    1.26          return pauseAfterReceipt;
    1.27      }
    1.28  
    1.29 -    BerDecoder getReplyBer(long millis) throws CommunicationException,
    1.30 +    /**
    1.31 +     * Read reply BER
    1.32 +     * @param millis timeout, infinite if the value is negative
    1.33 +     * @return BerDecoder if reply was read successfully
    1.34 +     * @throws CommunicationException request has been canceled and request does not need to be abandoned
    1.35 +     * @throws NamingException request has been closed or timed out. Request does need to be abandoned
    1.36 +     * @throws InterruptedException LDAP operation has been interrupted
    1.37 +     */
    1.38 +    BerDecoder getReplyBer(long millis) throws NamingException,
    1.39                                                 InterruptedException {
    1.40          if (cancelled) {
    1.41              throw new CommunicationException("Request: " + msgId +
    1.42                  " cancelled");
    1.43          }
    1.44          if (isClosed()) {
    1.45 -            return null;
    1.46 +            throw new NamingException(CLOSE_MSG);
    1.47          }
    1.48  
    1.49          BerDecoder result = millis > 0 ?
    1.50 @@ -113,7 +124,15 @@
    1.51                  " cancelled");
    1.52          }
    1.53  
    1.54 -        return result == EOF ? null : result;
    1.55 +        // poll from 'replies' blocking queue ended-up with timeout
    1.56 +        if (result == null) {
    1.57 +            throw new NamingException(String.format(TIMEOUT_MSG_FMT, millis));
    1.58 +        }
    1.59 +        // Unexpected EOF can be caused by connection closure or cancellation
    1.60 +        if (result == EOF) {
    1.61 +            throw new NamingException(CLOSE_MSG);
    1.62 +        }
    1.63 +        return result;
    1.64      }
    1.65  
    1.66      boolean hasSearchCompleted() {

mercurial