I'm working in OpenEdge 11.7.2 (on Windows) and attempting to set and get cookies using PASOE WebHandlers via REST requests (using Postman). I put together two simple handlers maps (/MyApp/web/SetCookies and /MyApp/web/GetCookies) that respond to GET requests.
'SetCookies' sets up three cookies (Cookie1, Cookie2, and Cookie3). Using Postman I set the three cookies get set appropriately in the domain and path expected.
When sending a request to 'GetCookies' I am expecting to get back a JSON object with three entries (Cookie1, Cookie2, Cookie3). Using Postman I can see that I am passing in all three cookies. The response I get back is the first cookie only (Cookie1). If in Postman I delete Cookie1, the response I get back will be the new first cookie (Cookie2).
For a minute I thought I could be building the response incorrectly, so I added a message statement in the logic that gets the cookies and spins through them, and only one cookie will appear in the array, no matter how many I have set.
I've tried setting the cookies simply (as the code below) and with the different security settings, all with the same result ... only the first cookie appears. I'm seeing the same result whether I attempt this directly to the PASOE instance or using BonCode AJP13 protocol from IIS to PASOE.
Is this a bug, or am I missing something simple?
Code sample follows.
Thanks,
Brian
METHOD OVERRIDE PROTECTED INTEGER HandleGet( INPUT poRequest AS OpenEdge.Web.IWebRequest ): DEFINE VARIABLE oResponse AS OpenEdge.Net.HTTP.IHttpResponse NO-UNDO. DEFINE VARIABLE oWriter AS OpenEdge.Web.WebResponseWriter NO-UNDO. DEFINE VARIABLE oBody AS OpenEdge.Core.String NO-UNDO. DEFINE VARIABLE oCookies AS OpenEdge.Net.HTTP.Cookie EXTENT NO-UNDO. DEFINE VARIABLE oData AS Progress.Json.ObjectModel.JSONObject NO-UNDO. DEFINE VARIABLE x AS INTEGER NO-UNDO. CASE poRequest:UriTemplate: WHEN "/SetCookies" THEN DO: ASSIGN oResponse = NEW OpenEdge.Web.WebResponse() oResponse:StatusCode = INTEGER(StatusCodeEnum:OK) oBody = NEW OpenEdge.Core.String('[~{"msg":"cookies set"~}]') oResponse:Entity = oBody oResponse:ContentType = 'application/json':u oResponse:ContentLength = oBody:Size . oResponse:SetCookie(NEW OpenEdge.Net.HTTP.Cookie("Cookie1",'.','/',STRING(RANDOM(1,100000)))). oResponse:SetCookie(NEW OpenEdge.Net.HTTP.Cookie("Cookie2",'.','/',STRING(RANDOM(1,100000)))). oResponse:SetCookie(NEW OpenEdge.Net.HTTP.Cookie("Cookie3",'.','/',STRING(RANDOM(1,100000)))). END. WHEN "/GetCookies" THEN DO: poRequest:GetCookies(oCookies). oData = NEW Progress.Json.ObjectModel.JSONObject(). DO x = 1 TO EXTENT(oCookies): oData:Add(oCookies[x]:Name, oCookies[x]:Value). END. ASSIGN oResponse = NEW OpenEdge.Web.WebResponse() oResponse:StatusCode = INTEGER(StatusCodeEnum:OK) oResponse:Entity = oData oResponse:ContentType = 'application/json':u oResponse:ContentLength = LENGTH(oData:GetJsonText()) . END. OTHERWISE DO: RETURN HandleNotImplemented(poRequest). END. END CASE. ASSIGN oWriter = NEW WebResponseWriter(oResponse). oWriter:Open(). oWriter:Close(). RETURN 0. END METHOD.
If you do contact TS, I've created issue PSC00363199 for this. TS can associate your company with the issue.
Peter, how do you feel about porting your code to wrap libcurl and package libcurl with the openedge installation? Wouldn't that solve and avoid lots of issues? Libcurl sees so much hardening that it will always be challenging to do better.
[quote user="jankeir"]
Libcurl sees so much hardening that it will always be challenging to do better.
[/quote]
Couldn't agree more! My assumption is that is would give a better performance as well.
Thank you Peter. I submitted that case and have been told that this will be (or has been) fixed for 11.7.3. While inconvenient, we can get by until that is released.
Glad to hear you are considering a move to libcurl. We started out using openedge.net classes for http, but moved to a custom libcurl wrapper when we needed better performance, it works and we only needed 50 lines of C code, but having stuff like this in the box would be better of course.