Page 1 of 1

How to download zip file from a public URL

Posted: Wed Dec 16, 2020 7:31 pm
by Jimmy_J
Dear colleagues,
While I am changing the source code of one reusable part (LANSA V13), I found that there is an executable (none Lansa) has been used to download a zip file from a public URL. I am wondering if it is possible to download this zip file with Lansa code only. If that is possible, would you please furnish me with a code example.
Thank you

Re: How to download zip file from a public URL

Posted: Thu Dec 17, 2020 12:39 am
by Dino
If you have LANSA Integrator, Service HTTPSERVICE, you can do this using GET and indicating content ZIP, as example this RDMLX Function, (but could also work an RDML Function with minimum change):

Code: Select all

Function Options(*DIRECT)

* Open service
Use Builtin(JSMX_OPEN) To_Get(#JSMXSTS #JSMXMSG #JSMXHDLE1)
Execute Subroutine(CHECK) With_Parms(#JSMXSTS #JSMXMSG)
* Load service
Change Field(#JSMXCMD) To('SERVICE_LOAD SERVICE(HTTPSERVICE) TRACE(*YES)')
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMXSTS #JSMXMSG)
Execute Subroutine(CHECK) With_Parms(#JSMXSTS #JSMXMSG)

* Go to the URL address for example http://3.14.15.926:5359/images/temp/test.zip
Change Field(#JSMXCMD) To('SEND HOST(3.14.15.926:5359) CONTENT(*ZIP) URI(/images/temp/test.zip) HANDLER(OutboundFile) METHOD(GET) WAIT(*YES)')
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMXSTS #JSMXMSG)
Execute Subroutine(CHECK) With_Parms(#JSMXSTS #JSMXMSG)

Change Field(#JSMXCMD) To('GET PROPERTY(STATUS-MESSAGE)')
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMXSTS #JSMXMSG)
Execute Subroutine(CHECK) With_Parms(#JSMXSTS #JSMXMSG)

* Receive the content and put it in a file in the IFS of the IBM
* Change Field(#JSMXCMD) To('RECEIVE HANDLER(IFILE) TO(/tmp/test.zip)')
* Receive the content and put it in a folder in Windows:
Change Field(#JSMXCMD) To('RECEIVE HANDLER(IFILE) TO(C:\windows\temp\test.zip)')

Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMXSTS #JSMXMSG)
Execute Subroutine(CHECK) With_Parms(#JSMXSTS #JSMXMSG)

* Unload service
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 'SERVICE_UNLOAD') To_Get(#JSMXSTS #JSMXMSG)
Execute Subroutine(CHECK) With_Parms(#JSMXSTS #JSMXMSG)
* Close service
Use Builtin(JSMX_CLOSE) With_Args(#JSMXHDLE1) To_Get(#JSMXSTS #JSMXMSG)
Execute Subroutine(CHECK) With_Parms(#JSMXSTS #JSMXMSG)

* Check routine
Subroutine Name(CHECK) Parms((#JSMXSTS *RECEIVED) (#JSMXMSG *RECEIVED))
If Cond('#JSMXSTS *NE OK')
Message Msgtxt('Error: ' + #JSMXSTS + ' ' + #JSMXMSG)
Use Builtin(JSMX_CLOSE) With_Args(#JSMXHDLE1) To_Get(#JSMXSTS #JSMXMSG)
Endif
Endroutine

* Subroutine to build JSM commands. existing JSM command
Subroutine Name(KEYWRD) Parms((#W_CMDX *BOTH) (#W_KEYWRD *RECEIVED) (#W_KEYVAL *RECEIVED))
Define Field(#W_CMDX) Reffld(#JSMXCMD)
Define Field(#W_KEYWRD) Reffld(#STD_TEXT)
Define Field(#W_KEYVAL) Reffld(#STD_TEXTL)
#W_CMDX += ' ' + #W_KEYWRD + '(' + #W_KEYVAL + ')'
Endroutine

Re: How to download zip file from a public URL

Posted: Sat Dec 19, 2020 12:13 am
by Jimmy_J
Thank you Dino, it should work as you described. I think I have some issues to solve before it works.
When I am executing this line:
Change Field(#JSMCMDX) To('SEND HOST(https://www.afm.nl) SECURE(*YES) URI(/export.aspx?fdregister=1) HANDLER(OUTBOUNDFILE) CONTENT(*ZIP) METHOD(GET) WAIT(*YES)')
Use Builtin(JSMX_COMMAND) With_Args(#JSMHDLE1 #JSMCMDX) To_Get(#JSMSTS #JSMMSGX)

I get always this error: ERROR Connection timed out: connect
And the rest goes wrong.

The URL for downloading the zip file:
https://www.afm.nl/export.aspx?fdregister=1

I will be thankfull for any more assistance

Re: How to download zip file from a public URL

Posted: Tue Dec 22, 2020 7:57 pm
by Jimmy_J
Thank you Dino,

Your code is working just fine with http, I tried it and it works perfect. But when it comes to https it doesn't work also with some modification like this "HOST(*HOST)" becaouse I couldn't get SNI to find value of "SNISERVER"

Change Field(#JSMCMDX) To('SEND HOST(*HOST) SECURE(*Yes) URI(https://www.afm.nl/export.aspx?fdregister=1) HANDLER(OUTBOUNDFILE) CONTENT(*ZIP) METHOD(GET) WAIT(*YES)')

I appreciate any suggestion

Re: How to download zip file from a public URL

Posted: Wed Dec 23, 2020 12:17 am
by Dino
Hi Jimmy,

It is working fine in my windows installation with just this change:

Code: Select all

* Go to the URL address for example https://www.afm.nl/export.aspx?fdregister=1
Change Field(#JSMXCMD) To('SEND HOST(www.afm.nl) CONTENT(*ZIP) URI(/export.aspx?fdregister=1) HANDLER(OutboundFile) METHOD(GET) WAIT(*YES) SECURE(*YES)')
and working from my IBM server with this additional change:

Code: Select all

Change Field(#JSMXCMD) To('RECEIVE HANDLER(IFILE) TO(/tmp/test122.zip)')
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMXSTS #JSMXMSG)

Re: How to download zip file from a public URL

Posted: Wed Dec 23, 2020 11:23 pm
by Jimmy_J
Thank you very much Dino,

It doesn't work on my Windows Server, I get "ERROR Connection timed out: connect". We have Windows Server 2008 with Lansa V13.
I don't know if there are other considerations related to "Java Virtual Machine" or some security issues.

Thank you very much again and I wish you and all the Community merry Christmis and happy new year.

Re: How to download zip file from a public URL

Posted: Thu Dec 24, 2020 3:05 am
by Dino
Merry Christmas Jimmy and Happy New Year for you too!

Re: How to download zip file from a public URL

Posted: Tue Dec 29, 2020 10:23 am
by Jimmy_J
Hi Dino,
After a good Christmas holiday I could solve the problems:
1- Connection timed out was a firewall issue, after that I got the second issue:
2- Error sun.security.validator.validatorexception. This error accured dou to https lack of certificate in JDK. To resolve this problem:
a- Download the certificate in the browser and save it.
b- Add this certificate to JDK keystore.

That is it. It works now perfect.

Re: How to download zip file from a public URL

Posted: Tue Dec 29, 2020 11:02 am
by Dino
Excellent!