0

I am developing an LDAP web application, which access active directory information. I am using unboundid java sdk for interacting with AD through java code. Now, i am trying to export active directory information in the format of LDIF from AD server to client. Here is the sample code.

File file = new File(filePath + "\\export.ldif");

    // Write all of the matching entries to LDIF.
    LDIFWriter ldifWriter;
    try {
        OutputStream output = new FileOutputStream(file, true);
        ldifWriter = new LDIFWriter(output);
        for (SearchResultEntry entry : searchResult) {
            ldifWriter.writeEntry(entry);
        }

        ldifWriter.close();
        output.close();
    } catch (IOException e) {
        throw new LDAPApplicationException(
                "Error writing to file, try again", e);
    }

As of now, I am creating a new LDIF file for each client request and writing necessary LDAP records to it and sending it to client. I can send this file to client through HTTP response, but for each new request I have to create a new file. I don't think it is feasible solution. My question is how to send the LDIF data from server to client without creating new file for every request on server side? Please suggest me other best approaches for reading LDAP records from AD, convert them to LDIF format and send this file to client. And also is there any MIME type for LDIF? Thanks in advance !!!

user207421
  • 305,947
  • 44
  • 307
  • 483
Anudeep
  • 25
  • 2
  • 9

1 Answers1

0

So your question is on how to write the LDIF content directly to the http response instead of having a temporary output file.

Instead of writing this:

OutputStream output = new FileOutputStream(file, true);
ldifWriter = new LDIFWriter(output);

You can do

ServletOutputStream sos = response.getOutputStream();
ldifWriter = new LDIFWriter(sos);

I don't there is a MIME type specifically for ldif.

This is a rather old post.Hope it helps someone else out there.