REST Services and Cookies

Posted by heicomarkl on 03-Jul-2018 07:53

I am brand new to REST - needed to state that straight off.  I have created a REST service that will need to read cookies that are being sent from a foreign application into the rest service.  I have used the samples that are available all over to create the REST service and it is responding to requests from the foreign application.

My big problem is accessing the cookies.  I have searched and found the code that gets the cookies into the EXTENT variable:

DEFINE VARIABLE oClient AS IHttpClient NO-UNDO.
DEFINE VARIABLE oReq AS IHttpRequest NO-UNDO.
DEFINE VARIABLE oResp AS IHttpResponse NO-UNDO.
DEFINE VARIABLE oCookies AS Cookie EXTENT NO-UNDO.

oResp:GetCookies(oCookies).

My question is - how do I get the IHttpRequest or IHttpResponse information.  How is it available to the server session?  If I just run the above code in the Read method of the BusinessEntity that I have created, I get invalid handle messages in the log files and there is nothing in the cookie information obviously.

Can someone please share some code that will help me establish the connection to the session so I can retrieve the cookies and the information in them?

Thanks very muich

Mark

All Replies

Posted by egarcia on 03-Jul-2018 14:07

Hello,

There are multiple ways that you can create REST services with PDSOE:

- REST with visual editor to map parameters (REST transport)

- REST with WebHandler (Web transport)

- REST with Progress Data Service (with catalog file)

   - This option can use REST or Web transport

The following link provides info on these type of services:

- community.progress.com/.../97595

Which type of service are you using?

A possible approach to read cookies would be to have a custom WebHandler.

The WebHandler could do the operation that you need with the cookies directly or call a Business Entity:

- knowledgebase.progress.com/.../Sample-WEB-Handler-code-to-access-a-Business-Entity

You can have multiple WebHandlers in the same service and map to different URLs.

I hope this helps.

Posted by heicomarkl on 03-Jul-2018 14:16

Edsel

Thanks for the response.  I am using rest with HTTP and I have managed to establish a session now with the following:

       DEFINE VARIABLE oClient         AS IHttpClient NO-UNDO.

       DEFINE VARIABLE oReq            AS IHttpRequest NO-UNDO.

       DEFINE VARIABLE oResp           AS IHttpResponse NO-UNDO.

       DEFINE VARIABLE oCookies        AS Cookie EXTENT NO-UNDO.

       oClient = ClientBuilder:Build()

                   :Client.

       oReq = RequestBuilder:Get('URIPath')

              :Request.      

       oResp = oClient:Execute(oReq).

       oResp:GetCookies(oCookies).

I am able to see that there is one cookie available for me which is what I am expecting.  Now I just need to get the contents of it :)

Thanks

Mark

Posted by Peter Judge on 05-Jul-2018 14:27

Now that you have an array of cookies, you can inspect them.

Do loop = 1 to extent(oCookies):

   message

     oCookies[loop]:Name

     oCookies[loop]:Path

     oCookies[loop]:Value

    // etc

  .

end.

If you know the name of the cookie, you can call GetCookie(<name>) on the response.

There's information about the Cookie class in PDSOE's Class Browser and at  documentation.progress.com/.../OpenEdge.Net.HTTP.Cookie.html

This thread is closed