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

changeset 14206
ab2e99db6702
parent 13833
c9e76bc2aae1
child 14211
ccf97104b8ea
     1.1 --- a/src/share/classes/com/sun/jndi/ldap/Connection.java	Wed Sep 09 14:18:45 2020 -0400
     1.2 +++ b/src/share/classes/com/sun/jndi/ldap/Connection.java	Wed Sep 09 14:19:14 2020 -0400
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1999, 2018, 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 @@ -454,22 +454,34 @@
    1.11      BerDecoder readReply(LdapRequest ldr) throws IOException, NamingException {
    1.12          BerDecoder rber;
    1.13  
    1.14 +        NamingException namingException = null;
    1.15          try {
    1.16              // if no timeout is set so we wait infinitely until
    1.17 -            // a response is received
    1.18 +            // a response is received OR until the connection is closed or cancelled
    1.19              // http://docs.oracle.com/javase/8/docs/technotes/guides/jndi/jndi-ldap.html#PROP
    1.20              rber = ldr.getReplyBer(readTimeout);
    1.21          } catch (InterruptedException ex) {
    1.22              throw new InterruptedNamingException(
    1.23                  "Interrupted during LDAP operation");
    1.24 +        } catch (CommunicationException ce) {
    1.25 +            // Re-throw
    1.26 +            throw ce;
    1.27 +        } catch (NamingException ne) {
    1.28 +            // Connection is timed out OR closed/cancelled
    1.29 +            namingException = ne;
    1.30 +            rber = null;
    1.31          }
    1.32  
    1.33          if (rber == null) {
    1.34              abandonRequest(ldr, null);
    1.35 -            throw new NamingException(
    1.36 -                    "LDAP response read timed out, timeout used:"
    1.37 -                            + readTimeout + "ms." );
    1.38 -
    1.39 +        }
    1.40 +        // namingException can be not null in the following cases:
    1.41 +        //  a) The response is timed-out
    1.42 +        //  b) LDAP request connection has been closed or cancelled
    1.43 +        // The exception message is initialized in LdapRequest::getReplyBer
    1.44 +        if (namingException != null) {
    1.45 +            // Re-throw NamingException after all cleanups are done
    1.46 +            throw namingException;
    1.47          }
    1.48          return rber;
    1.49      }
    1.50 @@ -888,15 +900,6 @@
    1.51                      inbuf = Arrays.copyOf(inbuf, offset + left.length);
    1.52                      System.arraycopy(left, 0, inbuf, offset, left.length);
    1.53                      offset += left.length;
    1.54 -/*
    1.55 -if (dump > 0) {
    1.56 -System.err.println("seqlen: " + seqlen);
    1.57 -System.err.println("bufsize: " + offset);
    1.58 -System.err.println("bytesleft: " + bytesleft);
    1.59 -System.err.println("bytesread: " + bytesread);
    1.60 -}
    1.61 -*/
    1.62 -
    1.63  
    1.64                      try {
    1.65                          retBer = new BerDecoder(inbuf, 0, offset);
    1.66 @@ -1004,36 +1007,4 @@
    1.67          }
    1.68          return buf;
    1.69      }
    1.70 -
    1.71 -    // This code must be uncommented to run the LdapAbandonTest.
    1.72 -    /*public void sendSearchReqs(String dn, int numReqs) {
    1.73 -        int i;
    1.74 -        String attrs[] = null;
    1.75 -        for(i = 1; i <= numReqs; i++) {
    1.76 -            BerEncoder ber = new BerEncoder(2048);
    1.77 -
    1.78 -            try {
    1.79 -            ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR);
    1.80 -                ber.encodeInt(i);
    1.81 -                ber.beginSeq(LdapClient.LDAP_REQ_SEARCH);
    1.82 -                    ber.encodeString(dn == null ? "" : dn);
    1.83 -                    ber.encodeInt(0, LdapClient.LBER_ENUMERATED);
    1.84 -                    ber.encodeInt(3, LdapClient.LBER_ENUMERATED);
    1.85 -                    ber.encodeInt(0);
    1.86 -                    ber.encodeInt(0);
    1.87 -                    ber.encodeBoolean(true);
    1.88 -                    LdapClient.encodeFilter(ber, "");
    1.89 -                    ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR);
    1.90 -                        ber.encodeStringArray(attrs);
    1.91 -                    ber.endSeq();
    1.92 -                ber.endSeq();
    1.93 -            ber.endSeq();
    1.94 -            writeRequest(ber, i);
    1.95 -            //System.err.println("wrote request " + i);
    1.96 -            } catch (Exception ex) {
    1.97 -            //System.err.println("ldap.search: Caught " + ex + " building req");
    1.98 -            }
    1.99 -
   1.100 -        }
   1.101 -    } */
   1.102  }

mercurial