One Star

[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
1 ACCEPTED SOLUTION

Accepted Solutions
Fifteen Stars

Re: [resolved] Connect to WebDav with Talend

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....

The tFileInputRaw is configured to read the file you want to send. It reads it as a byte array. Settings are below....

The 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.....


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.....

Ignore 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://www.talendforge.org/forum/viewtopic.php?id=38724). 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.
Rilhia Solutions
6 REPLIES
Fifteen Stars

Re: [resolved] Connect to WebDav with Talend

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.
Rilhia Solutions
One Star

Re: [resolved] Connect to WebDav with Talend

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>
Fifteen Stars

Re: [resolved] Connect to WebDav with Talend

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....

The tFileInputRaw is configured to read the file you want to send. It reads it as a byte array. Settings are below....

The 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.....


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.....

Ignore 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://www.talendforge.org/forum/viewtopic.php?id=38724). 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.
Rilhia Solutions
One Star

Re: [resolved] Connect to WebDav with Talend

This worked! Smiley Very Happy
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.
Fifteen Stars

Re: [resolved] Connect to WebDav with Talend

Glad it worked. Thanks for replying. Now I know I can use this if I'm ever faced with the same problem :-)
Rilhia Solutions
One Star

Re: [resolved] Connect to WebDav with Talend

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.