Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] Connect to WebDav with Talend

Hello,
What is the easiest way to put & get files via WebDav using Talend?
I tried using the component tWebDavPut, which I downloaded from Talend Exchange, but received the error:
java.lang.RuntimeException: Could not generate DH keypair

Caused by: java.security.InvalidAlgorithmParameterException: Prime size must be multiple of 64, and can only range from 512 to 1024 (inclusive)

Stack overflow suggests that this is a bug with JDK 7. (I am not able to post the link because I don't have enough posts on the forum yet.) 
Unfortunately, of course, Talend 5.6 seems to be incompatible with JDK 8, in which this bug was corrected.
My only other solution has been to use a tSystem component & call a command-line utility like curl that can connect to WebDav. But if that's the only solution, why use Talend in the first place?
Thanks,
Porter
Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Sorry, I didn't see your post until I got home. I think I have a bare bones example of how you might be able to achieve this. I've not tested it with WebDav, but it should get you close if it doesn't get you all the way there. The layout can be seen in the below pic....
0683p000009MCSX.png
The tFileInputRaw is configured to read the file you want to send. It reads it as a byte array. Settings are below....

0683p000009MCSc.pngThe data is returned as an Object. The tConvertType is simply used to convert it to a byte[]. I believe this is a Talend *feature* 🙂
In the tSetGlobalVar I am setting the data to a globalMap variable. As seen below.....

0683p000009MCSh.png
The tRest configuration needs to be handled carefully. Unless this is configured precisely, it will not work and can be a real pain to sort out. These are my guesstimate at the best settings for you.....

0683p000009MCSm.pngIgnore the URL. That can be replaced with yours. The HTTP Headers are important. You need to ensure that the Content-Type is set to "application/octet-stream". That will permit binary data to be passed. You then need to use the Http Body field to place the globalMap variable you created with your byte[] data.
In your CURL command I noticed you were using Basic Http Authentication (or that is my assumption). In order to work with that with a tRest component, you will need to follow the example here ( https://community.talend.com/t5/Design-and-Development/resolved-tREST-and-Authentication/td-p/60787). Add a tJava to the job (maybe after the tSetGlobalVar) and use the code explained in the link. Then add an "Authorization" Http Header.
That last part I can't guarantee works (as I haven't tried it), but the first part should do. 
I can't guarantee this will work perfectly first time, but this should enable you to trial and error it out. Good luck.

View solution in original post

9 Replies
Anonymous
Not applicable
Author

Talend 6 is compatible with Java 8. However I think you have many other options using Talend 5.6. You can make use of any Java APIs available to you using tJava, tJavaRow or tJavaFlex components (also routines, etc), you can also make use of HTTP methods. The component that you are currently trying looks very old and is probably not supported anymore. You could take a look at editing that component, but that is a little tricky if you have not edited components before.
Anything you can do with curl, you can do with Talend. You just need to know how. Let us know how you are connecting using curl and someone will be able to tell you how to achieve this using Talend.
Anonymous
Not applicable
Author

Thanks so much for your response! We are on version 5.6 for now, I can ask about upgrading to 6 but not likely to happen immediately.
I agree, that component looks old & janky, better to use something more modern. I don't have experience editing components, but if there's an easy way to do this with tJava or one of the HTTP components that would be ideal.
My curl command looks like this:
curl -T <filename> -u <username>:<password> https://<url>
Anonymous
Not applicable
Author

Sorry, I didn't see your post until I got home. I think I have a bare bones example of how you might be able to achieve this. I've not tested it with WebDav, but it should get you close if it doesn't get you all the way there. The layout can be seen in the below pic....
0683p000009MCSX.png
The tFileInputRaw is configured to read the file you want to send. It reads it as a byte array. Settings are below....

0683p000009MCSc.pngThe data is returned as an Object. The tConvertType is simply used to convert it to a byte[]. I believe this is a Talend *feature* 🙂
In the tSetGlobalVar I am setting the data to a globalMap variable. As seen below.....

0683p000009MCSh.png
The tRest configuration needs to be handled carefully. Unless this is configured precisely, it will not work and can be a real pain to sort out. These are my guesstimate at the best settings for you.....

0683p000009MCSm.pngIgnore the URL. That can be replaced with yours. The HTTP Headers are important. You need to ensure that the Content-Type is set to "application/octet-stream". That will permit binary data to be passed. You then need to use the Http Body field to place the globalMap variable you created with your byte[] data.
In your CURL command I noticed you were using Basic Http Authentication (or that is my assumption). In order to work with that with a tRest component, you will need to follow the example here ( https://community.talend.com/t5/Design-and-Development/resolved-tREST-and-Authentication/td-p/60787). Add a tJava to the job (maybe after the tSetGlobalVar) and use the code explained in the link. Then add an "Authorization" Http Header.
That last part I can't guarantee works (as I haven't tried it), but the first part should do. 
I can't guarantee this will work perfectly first time, but this should enable you to trial and error it out. Good luck.
Anonymous
Not applicable
Author

This worked!  0683p000009MACJ.png
I modified your settings slightly to use PUT instead of POST, and included the "Authorization" header as indicated in the linked article, and was able to upload a file successfully.
Anonymous
Not applicable
Author

Glad it worked. Thanks for replying. Now I know I can use this if I'm ever faced with the same problem 🙂
lvsiva
Contributor
Contributor

Hi Rilhia ans James,
This post saves my half day.
Am also trying to share csv file to webdav server, but not succeeded.
@james: were you added extra authorization header in HTTP Headers?
OR
Replaced the content-type header with Authorization header?
Thanks in Advance.
Siva.
Anonymous
Not applicable
Author

to connect and upload a file to a webdav server with talend, here is the quick method in Curl :

syntax : "curl --anyauth --user : password -T <file to upload> -X PUT <target folder>

"curl --anyauth --user abcd@mail.com:1234 -T /Users/MyPC/Documents/PROJECT/OUTPUT/folder/myfile.xml -X PUT https://webdav url"

Example of url webdav : https://myurl/project.demxxx.net/on/demxxxx.servlet/webdav/SitAA/Imxx/upload/filesUpload/

with Context : 

"curl --anyauth --user "+context.WebDav_User+":"+context.WebDav_password+" -T "+context.Folder_Project+context.Folder_output+context.Folder_output+context.file_name+"*"+" -X PUT "+context.WebDav_host 

 

** Curl Commands Webdav : 
https://www.qed42.com/blog/using-curl-commands-webdav

varun1949
Contributor III
Contributor III

Hello everyone, this post shows how to send data as content/byte but how can we do if we need to send data as .zip files ?

Anonymous
Not applicable
Author

It depends on the API you are working with how you can send it. But a zip file can be read into a byte array this way.