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

changeset 14206
ab2e99db6702
parent 13833
c9e76bc2aae1
child 14211
ccf97104b8ea
equal deleted inserted replaced
14205:9deaed6c4a0f 14206:ab2e99db6702
1 /* 1 /*
2 * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this 7 * published by the Free Software Foundation. Oracle designates this
452 * Reads a reply; waits until one is ready. 452 * Reads a reply; waits until one is ready.
453 */ 453 */
454 BerDecoder readReply(LdapRequest ldr) throws IOException, NamingException { 454 BerDecoder readReply(LdapRequest ldr) throws IOException, NamingException {
455 BerDecoder rber; 455 BerDecoder rber;
456 456
457 NamingException namingException = null;
457 try { 458 try {
458 // if no timeout is set so we wait infinitely until 459 // if no timeout is set so we wait infinitely until
459 // a response is received 460 // a response is received OR until the connection is closed or cancelled
460 // http://docs.oracle.com/javase/8/docs/technotes/guides/jndi/jndi-ldap.html#PROP 461 // http://docs.oracle.com/javase/8/docs/technotes/guides/jndi/jndi-ldap.html#PROP
461 rber = ldr.getReplyBer(readTimeout); 462 rber = ldr.getReplyBer(readTimeout);
462 } catch (InterruptedException ex) { 463 } catch (InterruptedException ex) {
463 throw new InterruptedNamingException( 464 throw new InterruptedNamingException(
464 "Interrupted during LDAP operation"); 465 "Interrupted during LDAP operation");
466 } catch (CommunicationException ce) {
467 // Re-throw
468 throw ce;
469 } catch (NamingException ne) {
470 // Connection is timed out OR closed/cancelled
471 namingException = ne;
472 rber = null;
465 } 473 }
466 474
467 if (rber == null) { 475 if (rber == null) {
468 abandonRequest(ldr, null); 476 abandonRequest(ldr, null);
469 throw new NamingException( 477 }
470 "LDAP response read timed out, timeout used:" 478 // namingException can be not null in the following cases:
471 + readTimeout + "ms." ); 479 // a) The response is timed-out
472 480 // b) LDAP request connection has been closed or cancelled
481 // The exception message is initialized in LdapRequest::getReplyBer
482 if (namingException != null) {
483 // Re-throw NamingException after all cleanups are done
484 throw namingException;
473 } 485 }
474 return rber; 486 return rber;
475 } 487 }
476 488
477 //////////////////////////////////////////////////////////////////////////// 489 ////////////////////////////////////////////////////////////////////////////
886 // read in seqlen bytes 898 // read in seqlen bytes
887 byte[] left = readFully(in, seqlen); 899 byte[] left = readFully(in, seqlen);
888 inbuf = Arrays.copyOf(inbuf, offset + left.length); 900 inbuf = Arrays.copyOf(inbuf, offset + left.length);
889 System.arraycopy(left, 0, inbuf, offset, left.length); 901 System.arraycopy(left, 0, inbuf, offset, left.length);
890 offset += left.length; 902 offset += left.length;
891 /*
892 if (dump > 0) {
893 System.err.println("seqlen: " + seqlen);
894 System.err.println("bufsize: " + offset);
895 System.err.println("bytesleft: " + bytesleft);
896 System.err.println("bytesread: " + bytesread);
897 }
898 */
899
900 903
901 try { 904 try {
902 retBer = new BerDecoder(inbuf, 0, offset); 905 retBer = new BerDecoder(inbuf, 0, offset);
903 906
904 if (traceFile != null) { 907 if (traceFile != null) {
1002 } 1005 }
1003 nread += count; 1006 nread += count;
1004 } 1007 }
1005 return buf; 1008 return buf;
1006 } 1009 }
1007
1008 // This code must be uncommented to run the LdapAbandonTest.
1009 /*public void sendSearchReqs(String dn, int numReqs) {
1010 int i;
1011 String attrs[] = null;
1012 for(i = 1; i <= numReqs; i++) {
1013 BerEncoder ber = new BerEncoder(2048);
1014
1015 try {
1016 ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR);
1017 ber.encodeInt(i);
1018 ber.beginSeq(LdapClient.LDAP_REQ_SEARCH);
1019 ber.encodeString(dn == null ? "" : dn);
1020 ber.encodeInt(0, LdapClient.LBER_ENUMERATED);
1021 ber.encodeInt(3, LdapClient.LBER_ENUMERATED);
1022 ber.encodeInt(0);
1023 ber.encodeInt(0);
1024 ber.encodeBoolean(true);
1025 LdapClient.encodeFilter(ber, "");
1026 ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR);
1027 ber.encodeStringArray(attrs);
1028 ber.endSeq();
1029 ber.endSeq();
1030 ber.endSeq();
1031 writeRequest(ber, i);
1032 //System.err.println("wrote request " + i);
1033 } catch (Exception ex) {
1034 //System.err.println("ldap.search: Caught " + ex + " building req");
1035 }
1036
1037 }
1038 } */
1039 } 1010 }

mercurial