コード例 #1
0
  /**
   * Reads an LDAP message from the associated input stream.
   *
   * @return The LDAP message read from the associated input stream, or <CODE>null</CODE> if the end
   *     of the stream has been reached.
   * @throws IOException If a problem occurs while attempting to read from the input stream.
   * @throws ASN1Exception If a problem occurs while attempting to decode the data read as an ASN.1
   *     sequence.
   * @throws LDAPException If a problem occurs while attempting to decode the LDAP message.
   */
  public LDAPMessage readMessage() throws IOException, ASN1Exception, LDAPException {
    debugInputStream.setRecordingEnabled(debugEnabled());

    if (!asn1Reader.hasNextElement()) {
      // EOF was reached...
      return null;
    }

    LDAPMessage message = org.opends.server.protocols.ldap.LDAPReader.readMessage(asn1Reader);

    if (debugInputStream.isRecordingEnabled()) {
      ByteString bytesRead = debugInputStream.getRecordedBytes();
      debugInputStream.clearRecordedBytes();

      StringBuilder builder = new StringBuilder();
      builder.append("bytes read from wire(len=");
      builder.append(bytesRead.length());
      builder.append("):");
      builder.append(ServerConstants.EOL);
      bytesRead.toHexPlusAscii(builder, 4);

      TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, builder.toString());
      TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, message.toString());
    }

    return message;
  }
コード例 #2
0
  /** Closes this LDAP reader and the underlying socket. */
  public void close() {
    try {
      asn1Reader.close();
    } catch (Exception e) {
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, e);
      }
    }

    if (socket != null) {
      try {
        socket.close();
      } catch (Exception e) {
        if (debugEnabled()) {
          TRACER.debugCaught(DebugLogLevel.ERROR, e);
        }
      }
    }
  }
コード例 #3
0
  /**
   * Tests the ASN.1 encoding for the response control.
   *
   * @throws Exception If an unexpected problem occurs.
   */
  @Test()
  public void testASN1ValueEncoding() throws Exception {
    ByteStringBuilder builder = new ByteStringBuilder();
    ASN1Writer writer = ASN1.getWriter(builder);
    VLVResponseControl vlvResponse =
        new VLVResponseControl(true, 0, 15, 0, ByteString.valueOf("foo"));
    vlvResponse.writeValue(writer);

    ASN1Reader reader = ASN1.getReader(builder.toByteString());
    // Should start as an octet string with a nested sequence
    assertEquals(reader.peekType(), ASN1Constants.UNIVERSAL_OCTET_STRING_TYPE);
    reader.readStartSequence();
    // Should be an sequence start
    assertEquals(reader.peekType(), ASN1Constants.UNIVERSAL_SEQUENCE_TYPE);
    reader.readStartSequence();
    // Should be an integer with targetPosition
    assertEquals(reader.peekType(), ASN1Constants.UNIVERSAL_INTEGER_TYPE);
    assertEquals(reader.readInteger(), 0);
    // Should be an integer with contentCount
    assertEquals(reader.peekType(), ASN1Constants.UNIVERSAL_INTEGER_TYPE);
    assertEquals(reader.readInteger(), 15);
    // Should be an enumerated with virtualListViewResult
    assertEquals(reader.peekType(), ASN1Constants.UNIVERSAL_ENUMERATED_TYPE);
    assertEquals(reader.readEnumerated(), 0);
    // Should be an octet string with contextID
    assertEquals(reader.peekType(), ASN1Constants.UNIVERSAL_OCTET_STRING_TYPE);
    assertEquals(reader.readOctetStringAsString(), "foo");
  }