Issue #57 has been updated by J?r?me Schell.

After some investigation, I'm progressing ;)

I am now setting the jpegPhoto attribute as byte[] in the flat object class 
like that:
<pre>
  private byte[] jpegPhoto;

  public final byte[] getJpegPhoto() {
    return jpegPhoto;
  }

  public final void setJpegPhoto(final byte[] value) {
    this.jpegPhoto = value;
  }
</pre>

The jpegPhoto attribute is of type List<byte[]> in InetOrgPerson class:
<pre>
  private List<byte[]> jpegPhoto;

  public final List<byte[]> getJpegPhoto() {
    return jpegPhoto;
  }

  public final void setJpegPhoto(final List<byte[]> values) {
    jpegPhoto = values;
  }
</pre>

With that setting, the jpegPhoto attribute is not setted in the bean. The 
problem is in the method setUpFromObject of the org.lsc.objects.top class. The 
type byte[] is not handled at all.
I modified the method like that (brute force modification :) ):
<pre>
--- lsc-core-1.1-SNAPSHOT/src/main/java/org/lsc/objects/top.java        
2009-06-04 08:58:19.000000000 +0200
+++ lsc-core/src/main/java/org/lsc/objects/top.java     2009-06-04 
10:00:06.586891780 +0200
@@ -127,35 +127,28 @@
                                                // on a empty value ?
                                                // localMethod.invoke(this, new 
Object[] {});
                                            LOGGER.debug("No need to call a 
method with an empty value ... (" + paramName + ")");
-                                       } else if (returnType == String.class) {
-                                               if (toReturnTypes != null && 
toReturnTypes[0] == String.class) {
-                                                       
localMethod.invoke(this, new Object[] { returnedObject });
-                                               } else if (toReturnTypes != 
null && toReturnTypes[0] == List.class) {
-                                                       paramsToUse = new 
ArrayList<Object>();
-                                                       
paramsToUse.add(returnedObject);
-                                                       
localMethod.invoke(this, new Object[] { paramsToUse });
-                                               } else {
-                                                       LOGGER.error("Unable to 
manage translation from String to "     + toReturnTypes[0] + " for " + 
paramName+ "!");
-                                               }
-                                       } else if (returnType == Date.class) {
-                                               if (toReturnTypes != null && 
toReturnTypes[0] == Date.class) {
-                                                       
localMethod.invoke(this, new Object[] { returnedObject });
-                                               } else if (toReturnTypes != 
null && toReturnTypes[0] == List.class) {
-                                                       paramsToUse = new 
ArrayList<Object>();
-                                                       
paramsToUse.add(returnedObject);
-                                                       
localMethod.invoke(this, new Object[] { paramsToUse });
-                                               } else {
-                                                       LOGGER.error("Unable to 
manage translation from Date to " + toReturnTypes[0] + " for " + paramName+ 
"!");
-                                               }
-                                       } else if (returnType == List.class) {
-                                               if (toReturnTypes != null && 
toReturnTypes[0] == String.class) {
-                                                       LOGGER.error("Unable to 
manage translation from List to String for " + paramName+ "!");
-                                               } else if (toReturnTypes != 
null && toReturnTypes[0] == List.class) {
-                                                       LOGGER.debug("Method 
invocation : " + localMethod.getName());
-                                                       
localMethod.invoke(this, new Object[] { returnedObject });
-                                               } else {
-                                                       LOGGER.error("Unable to 
manage translation from List to " + toReturnTypes[0] + " for " + paramName+ 
"!");
-                                               }
+                                       } else {
+                                         if (toReturnTypes != null && 
toReturnTypes[0] == List.class) {
+              LOGGER.debug("Method invocation: " + localMethod.getName());
+              try {
+                paramsToUse = new ArrayList<Object>();
+                paramsToUse.add(returnedObject);
+                localMethod.invoke(this, new Object[] { paramsToUse });
+              } catch (IllegalArgumentException e) {
+                LOGGER.error("Bad argument invoking " + localMethod.getName() 
+ " for attribute " + paramName);
+                e.printStackTrace();
+              }
+                                         } else if (toReturnTypes != null && 
toReturnTypes[0] == returnType) {
+                                           LOGGER.debug("Method invocation: " 
+ localMethod.getName());
+                                           try {
+                                             localMethod.invoke(this, new 
Object[] { returnedObject });
+                                           } catch (IllegalArgumentException 
e) {
+                                             LOGGER.error("Bad argument 
invoking " + localMethod.getName() + " for attribute " + paramName);
+                                             e.printStackTrace();
+                                           }
+            } else {
+              LOGGER.error("Unable to manage translation from " + returnType + 
" to " + toReturnTypes[0] + " for " + paramName+ "!");
+            }
                                        }
                                } else {
                                        if 
(paramName.compareToIgnoreCase("class") != 0) {
</pre>

Now the attribute is well setted in the bean (with a good size).
Nevertheless the attribute inserted into the destination LDAP does not have the 
right size...

According to 
"this":http://java.sun.com/products/jndi/tutorial/ldap/misc/attrs.html the 
jpegPhoto is automatically handled as binary by JNDI. I can't for now 
understand why my final value is bigger in size than the original one...
----------------------------------------
Bug #57: db2ldap : Binary attribute seems to be corrupted
http://tools.lsc-project.org/issues/show/57

Author: J?r?me Schell
Status: New
Priority: Normal
Assigned to: 
Category: Core
Target version: 


I am in the process of syncing a MySQL database with an openldap directory.
In the MySQL table, there is a blob containing a JPEG picture of the person.
The SQL field is mapped directly to the jpegPhoto LDAP attribute like that:
<pre>
<result property="jpegPhoto" column="photo"/>
</pre>

The synchronization process is working fine except that the JPEG in the LDAP 
directory seems to be invalid.
An export of the field is not a valid JPEG file and no LDAP browser displays 
the picture correctly.

It seems that binary attributes should be handled differently than others. See 
that "forum 
post":http://www.velocityreviews.com/forums/t139104-ldap-character-encoding.html
 for information about this.
The parameter "java.naming.ldap.attributes.binary" should contain a list of 
LDAP attributes to be handled as binary.


-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://tools.lsc-project.org/my/account
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://lists.lsc-project.org/pipermail/lsc-dev/attachments/20090604/84121191/attachment.htm>

Reply via email to