-2

There might be a silly mistake am doing it. but am trying to load a jpeg photo to ldap via java and facing small issue.

Currently in mule-3 we use invoke java and store it in ldap and when we download from ldap we get actual image. this is how its getting stored

enter image description here

and here is high level java code

enter image description here

In Mule-4 there is no event context and java module itself got changed. so am using similar java program and trying to load to ldap. its getting loaded but when i download its not an image.

this is how its storing in ldap, some extra content in the beginning it seems. below is my java code

enter image description here

enter image description here

     %dw 2.0
    import java!imaging::UploadPhotoToAD
    import * from dw::core::Binaries
    import * from dw::core::Numbers
output application/java
---
UploadPhotoToAD::updateEntry(ldap.image as Binary, ldap.userDN, ldap.usersDN, ldap.url, ldap.authDN, ldap.authPassword)

Any idea what am missing here or anything needs to be changed

Learner
  • 157
  • 2
  • 17
  • 1
    Don't post pics of your code. – JonR85 Jan 25 '22 at 00:41
  • Is `ba` your file? If so you are treating it as a String not binary – Scary Wombat Jan 25 '22 at 01:03
  • no sensitive information on that. same java code is present here too https://docs.oracle.com/javase/tutorial/jndi/ops/modattrs.html https://docs.oracle.com/javase/tutorial/jndi/ops/examples/ModAttrs.java https://docs.oracle.com/javase/jndi/tutorial/ldap/security/ldap.html – Learner Jan 25 '22 at 01:04
  • Don't post code as screenshots because it is against Stackoverflow policies. In https://stackoverflow.com/help/how-to-ask search "DO NOT post images of code, data, error messages, etc." for more details and and extended explanation in https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question/285557#285557. Basically it makes more difficult to help you. – aled Jan 25 '22 at 02:14
  • Also please share the flow -as XML text obviously- to understand from where the image is being read and how it reaches whatever component you are using to invoke the Java code. Is it a Java Module or DataWeave? Do you see that we are guessing here? Make it easier for others to help you. – aled Jan 25 '22 at 02:21
  • In addition to the 10+ reasons mentioned in the link above the images are making my browser very unhappy for some weird reason. Avoid using images for code. – aled Jan 25 '22 at 02:30
  • @aled I know you answer most of my questions. Thanks for that and i will make a note of not posting images. here is the scenario: loading the jpeg file via sftp and pass to ldap via bytes. is there a simple way to do that in mule4 ?? – Learner Jan 25 '22 at 03:00
  • Also please do not use links for code. – aled Jan 25 '22 at 03:16

1 Answers1

1

The problem is using String for binaries. You are having the same problem mentioned at https://stackoverflow.com/a/6544206/721855 because of using Strings for binaries. You should not use Strings at any point of reading or processing the image. Nor in the flow nor in Java.

Try in the flow use as Binary {class: "byte[]"} to force the -already- binary to be a byte array and set the type of ba also as a byte array (byte[]).

I'm not sure what happens with the file read before it ends in ldap.image so ensure it is not transformed in any way, even implicitly in an expression. Remember that in Mule 4 expressions are DataWeave transformation.

aled
  • 21,330
  • 3
  • 27
  • 34
  • Great great great thank you. I know this statement as Binary {class: "byte[]"} . But the i was using in dw output application/java and then passing to java method as ByteArrayInputStream going all over the places. Thank you once again – Learner Jan 25 '22 at 03:37