From dev-return-42745-apmail-directory-dev-archive=directory.apache.org@directory.apache.org Mon Apr 1 14:56:19 2013 Return-Path: X-Original-To: apmail-directory-dev-archive@www.apache.org Delivered-To: apmail-directory-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9AA66FEF1 for ; Mon, 1 Apr 2013 14:56:19 +0000 (UTC) Received: (qmail 99865 invoked by uid 500); 1 Apr 2013 14:56:19 -0000 Delivered-To: apmail-directory-dev-archive@directory.apache.org Received: (qmail 99542 invoked by uid 500); 1 Apr 2013 14:56:13 -0000 Mailing-List: contact dev-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Apache Directory Developers List" Delivered-To: mailing list dev@directory.apache.org Received: (qmail 99141 invoked by uid 99); 1 Apr 2013 14:56:08 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Apr 2013 14:56:08 +0000 X-ASF-Spam-Status: No, hits=2.9 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [81.169.146.161] (HELO mo-p00-ob.rzone.de) (81.169.146.161) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Apr 2013 14:56:04 +0000 X-RZG-AUTH: :P3gBc0GmW/MphhhpU4BSj2bmx/Zwgz97J2mNwJqPPUavZ2Rk665HbedlK4A= X-RZG-CLASS-ID: mo00 Received: from [192.168.2.104] (p57A7EB5D.dip.t-dialin.net [87.167.235.93]) by smtp.strato.de (josoe mo28) (RZmta 31.23 DYNA|AUTH) with ESMTPA id 3039acp31D4VUR for ; Mon, 1 Apr 2013 16:55:40 +0200 (CEST) Message-ID: <51599FE2.60009@labeo.de> Date: Mon, 01 Apr 2013 16:55:30 +0200 From: Stefan Zoerner User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130307 Thunderbird/17.0.4 MIME-Version: 1.0 To: Apache Directory Developers List Subject: Re: Retrieving binary data from LDAP server using Groovy References: In-Reply-To: Content-Type: multipart/alternative; boundary="------------030908070707000708090903" X-Virus-Checked: Checked by ClamAV on apache.org This is a multi-part message in MIME format. --------------030908070707000708090903 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi Jess! The problem here is that that Groovy LDAP uses JNDI under the hood. The same probem would occur with JNDI. See: http://docs.oracle.com/javase/jndi/tutorial/ldap/misc/attrs.html (to be more precise: "Specifying Additional Nonstring Attributes") Groovy LDAP works fine with binary attributes which are binary for JNDI by default (e.g. jpegphoto). "image" is not in the list, you have to add it manually. In JNDI, you would set a property to specify which attributes are binary: ... env.put("java.naming.ldap.attributes.binary", "image"); ... Later create JNDI InitialContext with env The problem is that LDAP Groovy hides the creation of both the env and InitialContexts. I see two (fast) options: a) change Groovy LDAP source by yourself and add the env property in class LDAP (file LDAP.java, method createEnvironment()) b) add a jndi.properties file to the classpath, which would be mixed with the env Groovy LDAP uses content of the file for b) only one line: java.naming.ldap.attributes.binary=image Please let me know if workaround b) works for you, or if you need more help. We can add a feature to Groovy LDAP for that, which would make perfect sense to me. Greetings from Hamburg, StefanZ Am 29.03.2013 06:19, schrieb Jess Johnson: > I'm having difficulty retrieving binary data from an OpenLDAP server > and was hoping someone could point me in the right direction. I read > on the message board that binary data comes back as incomplete or > corrupted unless the client specifies what attribute is binary. > > I wrote similar functionality in another language to test and > everything worked as expected. I'm able to retrieve all other values > (Strings) except binary data. > > def ldap = > org.apache.directory.groovyldap.LDAP.newInstance('ldap://some.server.com/ou=People,o=Acme > ') > ldap.eachEntry (filter: 'id=1234567') { entry -> > def image = entry.image.getBytes() > new File('/var/dir/something.jpg').withOutputStream { > it.write image > } > } > > Where would I specify the attribute "image" is binary? > > Thanks, > Jess --------------030908070707000708090903 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit
Hi Jess!

The problem here is that that Groovy LDAP uses JNDI under the hood. The same probem would occur with JNDI.
See: http://docs.oracle.com/javase/jndi/tutorial/ldap/misc/attrs.html (to be more precise: "Specifying Additional Nonstring Attributes")

Groovy LDAP works fine with binary attributes which are binary for JNDI by default (e.g. jpegphoto). "image" is not in the list, you have to add it manually.
In JNDI, you would set a property to specify which attributes are binary:

...
env.put("java.naming.ldap.attributes.binary", "image");
...
Later create JNDI InitialContext with env

The problem is that LDAP Groovy hides the creation of both the env and InitialContexts.

I see two (fast) options:
a) change Groovy LDAP source by yourself and add the env property in class LDAP (file LDAP.java, method createEnvironment())
b) add a jndi.properties file to the classpath, which would be mixed with the env Groovy LDAP uses

content of the file for b) only one line:

java.naming.ldap.attributes.binary=image

Please let me know if workaround b) works for you, or if you need more help.
We can add a feature to Groovy LDAP for that, which would make perfect sense to me.

Greetings from Hamburg,
    StefanZ




Am 29.03.2013 06:19, schrieb Jess Johnson:
I'm having difficulty retrieving binary data from an OpenLDAP server and was hoping someone could point me in the right direction. I read on the message board that binary data comes back as incomplete or corrupted unless the client specifies what attribute is binary.

I wrote similar functionality in another language to test and everything worked as expected. I'm able to retrieve all other values (Strings) except binary data.

def ldap = org.apache.directory.groovyldap.LDAP.newInstance('ldap://some.server.com/ou=People,o=Acme')
ldap.eachEntry (filter: 'id=1234567') { entry ->
            
  def image = entry.image.getBytes()
  
new File('/var/dir/something.jpg').withOutputStream {
it.write image
}
}

Where would I specify the attribute "image" is binary?

Thanks,
Jess

--------------030908070707000708090903--