Four Js Development Tools Forum

Discussions by product => GWS => Topic started by: Marco P. on September 02, 2013, 11:06:37 am



Title: HTTP Request and autentication
Post by: Marco P. on September 02, 2013, 11:06:37 am
Hello,
I have an application that needs to do many http requests to the same root host. I have one example attached.

At this moment I'm able to do this, with each request that first authenticate itself an then perform the real request. The requests use all the method (GET, POST, PUT, DELETE) and each request refers to a single object of another application so it's unique.
The operation of authentication slow the entire process so I ask if there is a way to do only once at the start of entire process and use the same autentication (or connection) for all the further requests. I try to use the "keepConnections" instructions, but this seems not to work.
Do I use it in the right way?


Title: Re: HTTP Request and autentication
Post by: Frank G. on September 04, 2013, 11:23:06 am
Hi,

 yes, using the req.setAuthentication() method is correct and should avoid one additional request-response step. Are your sure the login and password are correct ? Can you please set FGLWSDEBUG=3 and execute one request to see if http authentication works as expected in one single step ?

Thanks,
Frank


Title: Re: HTTP Request and autentication
Post by: Marco P. on September 04, 2013, 01:02:11 pm
Hi,
I send you 2 files:
  • 1.out: output of the program
  • fglwsdeb.txt: the results of FGLWSDEBUG
.
As you can see the first call is ok, the others are  Unauthorized

Thanks,
Marco


Title: Re: HTTP Request and autentication
Post by: Frank G. on September 04, 2013, 02:47:36 pm
Hi,
 

  Yes, your first request passes, but all others fail because in the loop of your 4GL program, you create the HTTPRequest object again. You don't have to, as long as URL is the same. Can you please, comment line 50 and retry. It should work.
Or if URL is different, then you have to call the req.setAuthentication() method for each new created HTTPRequest object.

Please, keep me posted

Thanks,

Frank


Title: Re: HTTP Request and autentication
Post by: Marco P. on September 08, 2013, 07:11:29 pm
Ok, so you confirm what I was thinking.
I have to do many different requests so I need to call different autentication's call.

I was looking for a single connection element that is used for all request.

Thanks
Marco


Title: Re: HTTP Request and autentication
Post by: Reuben B. on September 09, 2013, 11:45:58 pm
Is a FormEncodedRequest a possibility.  Something like ...

Code
  1. LET req = com.HTTPRequest.Create("http://10.1.6.42/opencrx-rest-OSCRM/org.opencrx.kernel.account1/provider/CRX/segment/ITA/account")
  2. CALL req.setAuthentication(...)
  3. WHILE TRUE
  4.  -- Replace admin-ITA with variable populated differently for each request
  5.   CALL req.doFormEncodedRequest("position=0&size=1&queryType=org:opencrx:kernel:account1:Contact&query=thereExistsFullName().startsWith(\"admin-ITA\")", FALSE))
  6.   ...
  7. END WHILE

Frank: with a typical RESTful Web Service, wouldn't the base URL remain constant, and the query parameters after the ? change with each call.  Is it necessary to create a new HTTPRequest object for each call?


Reuben



Title: Re: HTTP Request and autentication
Post by: Frank G. on September 10, 2013, 09:24:49 am
Hi,

  Yes what you propose could work, but formEncodedRequest() is used to simulate an HTML formular submit, with some specific encoding rules. 

  Today the HTTPRequest API works per URL, so you will have to define the authentication for any new URL. I have filled a feature to allow it globally. (bz#24546)