Return-Path: X-Original-To: apmail-directory-api-archive@minotaur.apache.org Delivered-To: apmail-directory-api-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E7CB82475 for ; Thu, 5 May 2011 09:40:55 +0000 (UTC) Received: (qmail 44600 invoked by uid 500); 5 May 2011 09:40:55 -0000 Delivered-To: apmail-directory-api-archive@directory.apache.org Received: (qmail 44583 invoked by uid 500); 5 May 2011 09:40:55 -0000 Mailing-List: contact api-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: api@directory.apache.org Delivered-To: mailing list api@directory.apache.org Received: (qmail 44575 invoked by uid 99); 5 May 2011 09:40:55 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 May 2011 09:40:55 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of ayyagarikiran@gmail.com designates 209.85.220.178 as permitted sender) Received: from [209.85.220.178] (HELO mail-vx0-f178.google.com) (209.85.220.178) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 May 2011 09:40:50 +0000 Received: by vxc11 with SMTP id 11so2603405vxc.37 for ; Thu, 05 May 2011 02:40:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type :content-transfer-encoding; bh=Uyc8YZd3FKHHuS67FQL46DwAF/reU0KD4M5Q5VhHbFE=; b=P9VBLes3WX2UT0C2pd00nbug0wOqxJOT9ZzER9+nWjyQdpMaOT8a5MUIw4/m0cDQqR LY8ZTcLibIRdxqVwqm37PvncwwqvZs3xbSoz/HyDuoUVFWagAK8f+jp2wjlIT61sRjYt uGgqsM7fD9P3b/j3NB+qd+jqEQnyOSu1AC+kU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type :content-transfer-encoding; b=fIpxtFDvYev+J0LRiT9Ouz3WevbTzJun5wZDh3+FOI4TSzENHTDaf+Xu4uC+x18wnJ c/Ir2ckBNb5T+vikAv7nDeXncPk0cLZR8Nty4ZKeVu9upC7MzPvt8HxICxpouMIukCSu rVmTzrUsN2VJBgAfi5mkLLtIuzD5X6wjtVmGQ= MIME-Version: 1.0 Received: by 10.52.98.225 with SMTP id el1mr2601916vdb.174.1304588429750; Thu, 05 May 2011 02:40:29 -0700 (PDT) Sender: ayyagarikiran@gmail.com Received: by 10.52.181.100 with HTTP; Thu, 5 May 2011 02:40:29 -0700 (PDT) In-Reply-To: References: Date: Thu, 5 May 2011 15:10:29 +0530 X-Google-Sender-Auth: nUI4cNXKT9eTTkbBxCCzBnLL1Fo Message-ID: Subject: Re: Reading Binary Attributes From: Kiran Ayyagari To: api@directory.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Thu, May 5, 2011 at 1:16 PM, Pierre-Arnaud Marcelot wr= ote: > Hi Kiran, > > On 4 mai 2011, at 17:13, Kiran Ayyagari wrote: > >> On Wed, May 4, 2011 at 8:24 PM, Daniel Fisher wrote: >>> On Tue, May 3, 2011 at 4:07 PM, Kiran Ayyagari w= rote: >>>> Hi Daniel, >>>> >>>> On Wed, May 4, 2011 at 12:33 AM, Daniel Fisher wrote: >>>>> Hello, >>>>> I'm doing some testing with 1.0.0-M3 and I'm having trouble reading >>>>> binary attributes. >>>>> Specifically for jpegPhoto in OpenLDAP 2.4.23: >>>>> >>>>> # jpegPhoto >>>>> # Used to store one or more images of a person using the JPEG File >>>>> # Interchange Format [JFIF]. >>>>> attributetype ( 0.9.2342.19200300.100.1.60 >>>>> =A0 =A0NAME 'jpegPhoto' >>>>> =A0 =A0DESC 'RFC2798: a JPEG image' >>>>> =A0 =A0SYNTAX 1.3.6.1.4.1.1466.115.121.1.28 ) >>>>> >>>>> the byte[] I get from Attribute#get()#getBytes() is about twice as bi= g >>>>> as I expect. Attribute#isHumanReadable() also returns true. Which >>>>> makes me think the value has been encoded. >>>>> Code snippet of what I'm doing: >>>>> =A0 =A0 =A0 =A0while (cursor.next()) { >>>>> =A0 =A0 =A0 =A0 =A0SearchResultEntry result =3D (SearchResultEntry) c= ursor.get(); >>>>> =A0 =A0 =A0 =A0 =A0Entry e =3D result.getEntry(); >>>>> =A0 =A0 =A0 =A0 =A0Attribute photo =3D e.get("jpegPhoto"); >>>>> =A0 =A0 =A0 =A0 =A0if (photo !=3D null) { >>>>> =A0 =A0 =A0 =A0 =A0 =A0byte[] bytes =3D photo.get().getBytes(); >>>>> =A0 =A0 =A0 =A0 =A0 =A0FileOutputStream fos =3D new FileOutputStream(= "photo.jpg"); >>>>> =A0 =A0 =A0 =A0 =A0 =A0fos.write(bytes); >>>>> =A0 =A0 =A0 =A0 =A0 =A0fos.close(); >>>>> =A0 =A0 =A0 =A0 =A0} >>>>> =A0 =A0 =A0 =A0} >>>>> >>>>> ldapsearch returns the value I expect. Is there some special syntax >>>>> for binary values I'm missing? Thanks >>>>> >>>> this is due to the fact that by default the client connection is not >>>> schema aware, to make it schema aware call loadSchema() method >>>> of the connection before performing any operations. >>>> Let us know if you still have any issues. >>>> Thank you for testing. >>> >>> Thanks. After reviewing the source it appears that binary attributes >>> are only supported with a schema aware connection. If you expose the >>> BinaryAttributeDetector (maybe on LdapConnection) then clients could >>> have some control without dealing with schemas. This would afford the >>> same functionality that JNDI provides via the >>> 'java.naming.ldap.attributes.binary' property. Just a thought. >>> >> don't know how JNDI detects the binary attributes, but in our case it is >> done completely with the help of schema manager >>> I also looked at the NetwokSchemaLoader and it uses a hard coded >>> baseDn and filter. With a litte refactoring that class could also work >>> against OpenLDAP, but currently it looks ApacheDS specific. >>> >> yes it is completely tied to the ApacheDS, the idea behind this loader i= s to >> have the same schema elements that the server currently uses instead >> of loading a >> set of default schemas. >> >> Another schema loader based on the data returned after querying >> cn=3Dsubschema (this is the technique >> which Apache Directory Studio uses) is ideal to make the client schema >> aware while working with other servers. >> >> May be we can port that code from Studio to API, studio folks wdyt? :) > > Unfortunately Studio does not use (yet) the API on this part of the code. > Although a complete Connection Wrapper as been created using the API and = works great, the code responsible for Schema loading in the LDAP Browser is= still our older base source code, when the API didn't exist. > > We should really introduce a "generic" schema loader, based on the Networ= kSchemaLoader, but which first looks into the RootDSE to find the location = of the schema (the value of the 'subSchemaSubentry' attribute), and then, o= n that DN loads all definitions of schema elements. > This would allow to make the LdapConnection schema aware on servers publi= shing their schema that way (most of them). > Definitely, a must have before releasing a final version of the API. > > I created a JIRA for this, DIRAPI-46: > https://issues.apache.org/jira/browse/DIRAPI-46 > great, thanks > Specifying BinaryAttributeDetectors might also be interesting in the case= where the server does not advertise the location of the its schema in the = RootDSE. But it would leave the connection being halfway schema aware, whic= h might be complicated to handle at first sight. > Something we can discuss about though. > yeah, the problem here is to link such a mechanism into the schema manager, but honestly I don't think it is a good idea to let user define some behavior to handle the attribute type apart from what is already defined in the schema through syntax. OTOH this conversation makes me think that we should also make connection schema aware by default, instead of the current choice of letting users call loadSchema() to make it schema aware. > Regards, > Pierre-Arnaud > > --=20 Kiran Ayyagari