Consuming RESTful web service via proxy server

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
Kazunori Kasahara
Posts: 20
Joined: Wed May 25, 2016 5:26 pm

Consuming RESTful web service via proxy server

Post by Kazunori Kasahara »

Our customer would like to consume RESTful web service via Proxy server using XPRIM_HttpRequest from VL Server Module.

They need to through the proxy server with basic access authentication to perform HTTP request from their network.
They need to do the following steps when calling web service URL using browser address bar:
1. Enter RESTful web service URL in browser.
2. Browser opens the authentication dialog prompting for username and password of proxy server.
3. Enter user and password for proxy authentication.
4. RESTful web service is consumed and returns JSON.

They added the http_proxy and https_proxy Windows environment variables (They are executing VL Web application using IIS on Windows).
e.g. http_proxy http://user:password@proxy.domain.com:port
But they couldn't do HTTP request from VL Server Module. XPRIM_HttpRequest returned the WinHttpSendRequest 12002 error meaning time out.

Does anyone have any experience of doing HTTP request via proxy server from VL Server Module?
Any advice would be appreciated.
Thank you.
AmitS
Posts: 3
Joined: Mon Jul 20, 2020 6:49 pm

Re: Consuming RESTful web service via proxy server

Post by AmitS »

Hello,

We are also facing a very similar challenge. Does anyone know how this can be solved?
Any help is very much appreciated. Thank you!
User avatar
Dino
Posts: 472
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: Consuming RESTful web service via proxy server

Post by Dino »

There is one example using basicaauthentication to connect to Twilio in the reusable part XWS_SMS_Provider_Twilio . But I am not sure if this kind of authentication is the same as the proxy authentication you are referring. Is that just a popup window with 2 authentication fields?

Code: Select all

* Construct Request
#UrlBuilder.SetScheme( 'https' )
#UrlBuilder.SetHost( 'api.twilio.com' )
#UrlBuilder.SetPath( '/2010-04-01/Accounts/' )
#UrlBuilder.AddPathComponent( #AccountSID )
#UrlBuilder.AddPathComponent( 'Messages.json' )

*
#COM_SELF.InitializeHttpRequest Httprequest(#Request)

#Request.Content.AddUrlEncodedFormValue Name('Body') Value(#BodyText)
#Request.Content.AddUrlEncodedFormValue Name('From') Value(#Sender)
#Request.Content.AddUrlEncodedFormValue Name('To') Value(#Message.Recipient)

#Request.Options.AddBasicAuthorization Username(#AccountSID) Password(#AuthToken)

#Request.DoPost Url(#UrlBuilder)

#COM_SELF.GetResponseFromHttpRequest Httpresponse(#Request.Response) Status(#Status) Loglabel(SendSMS)
AmitS
Posts: 3
Joined: Mon Jul 20, 2020 6:49 pm

Re: Consuming RESTful web service via proxy server

Post by AmitS »

Thank you Dino for your response.

We have tried using the URIBuilder but it does not work for our case.
We are trying to implement below:

Define_Com Class(#XPRIM_HttpRequest) Name(#Req)
#Req.Content.AddUrlEncodedFormValue Name('grant_type') Value('client_credentials')
#Req.Content.AddUrlEncodedFormValue Name('client_id') Value('**')
#Req.Content.AddUrlEncodedFormValue Name('client_secret') Value('**')
#Req.DoPost Url(<token-URL>)

When we run this from a server with no proxy, it gives us result instantly, Request status returns as TRUE
But when executing same from VDI, which has proxy server, the request wait for 30 seconds and status is FALSE with error message : CONNECTION_ERROR WinHttpRequest: 12002: The operation timed out

We are trying to see how we can embed proxy-server in the HttpRequest but no luck yet.
Hope someone has found way around. Thank you in advance!
AmitS
Posts: 3
Joined: Mon Jul 20, 2020 6:49 pm

Re: Consuming RESTful web service via proxy server

Post by AmitS »

Hello All,
Just an update: We did not find any solution to this issue within LANSA. However, we managed to deliver this functionality by allowing these request to pass the firewall. Ideal situation would have been that httprequest enables us to specify which proxy to be used. Thanks!
Gilamonster
Posts: 11
Joined: Thu Nov 26, 2015 3:11 am
Location: France

Re: Consuming RESTful web service via proxy server

Post by Gilamonster »

Hello All,

Facing a similar issue, when doing #Request.DoPost Url(#UrlBuilder) from an IBM i to an external API server when a Proxy is needed.

The request wait for 30 seconds then a CONNECTION_ERROR status is FALSE with error message : Failed to send outgoing data to the server, AxisTransportException : Cannot open a channel to the remote end. Failed to open connection to the server at host xxxxxxxxxxxxxxxx/oauth2/access_token Error is 3447 - A remote host did not respond within the timeout period;

I was able to replicate a similar error when doing a CURL from IBM i to the remote host without proxy.
But no more timeout error when I indicates the Proxy server to use and I am able to establish HTTP proxy tunnel to host xxxxxxxxxxx

> curl http://proxy.myproxy.local:3128 -v https://xxxxxxxxxxxxxxxxx/oauth2/acces_token

Would like to know if someone has found a solution to indicate a Proxy server when doing a request (XPRIM_HttpRequest) ?

I have triyed using #Req.Options.SetMiscProperty with values 'http_proxy' 'http://proxy.myproxy.local:3128' but without success

Any advices and idea will be welcome
Many thanks

Christophe
Post Reply