PAS4OE + WEBSPEED + Cookie

Posted by Valeriy Bashkatov on 26-May-2016 09:42

Hello,

I am looking for complete examples for using cookies in WebSpeed and PAS for OpenEdge. In ideal I need ABL source code that use cookie, sports database and some instructions how it all deploy in PAS4OE.

I did not find anything like it in the Knowledge Base or documentation

In such an example, I would like to explore this dark side for me )

Is there something like that?

Regards,
Valeriy

All Replies

Posted by Peter Judge on 26-May-2016 10:00

I can give a very quick outline
 
Your HandleGet() method will (in 11.6.2 and beyond) be generated to look something like the below.
 
In there you can change the oResponse object y adding cookies. You can also read them off the poRequest object.
 
 
       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.
           
        /* The WebResponse body is a wrapper around an entire HTTP response message.
           It contains a status code and reason; headers; cookies and a message body.
          
           API-level doc for this and related classes can be found at
        ASSIGN
            oResponse            = NEW OpenEdge.Web.WebResponse()
            oResponse:StatusCode = INTEGER(StatusCodeEnum:OK)
            .
        /* This body object can be a string or something else (JsonObject for instance) */              
        ASSIGN
            oBody = NEW OpenEdge.Core.String(
                             'Hello pjudge'
                           + '~r~n':u   /*CRLF */
                           + 'This message was returned by HandleGet in starnovaHandler.'
                           ).
       
        ASSIGN
            oResponse:Entity        = oBody
            /* HTTP messages require a content type */
            oResponse:ContentType   = 'text/plain':u
            /* ContentLength is good too */
            oResponse:ContentLength = oBody:Size
            .
       
        /* The WebResponseWriter ensures that the status line and
           all headers are writted out before the message body/entity. */
        ASSIGN
            oWriter = NEW WebResponseWriter(oResponse).
        oWriter:Open().
       
        /** HTTP MESSAGE ENTITY APPROACH **/
        /* The Progress.IO.OutputStream Write() methods take multiple overloads, for
           a variety of data types. See the doc for more information. */
        oWriter:Write(oBody:Value).
       
        /* Finish writing the response message */
        oWriter:Close().
       
        /* A response of 0 means that this handler will build the entire response;
           a non-zero value is mapped to a static handler in the webapp's /static/error folder.
           The mappings are maintained in the webapps's WEB-INF/web.xml
           A predefined set of HTTP status codes is provided in the OpenEdge.Net.HTTP.StatusCodeEnum
           enumeration */
        RETURN 0.
       
       END METHOD.
 
  po
 

Posted by scott_auge on 26-May-2016 13:25

Generally the idea is to have one cookie with a random value act as the key into a database table.  The first article of www.oehive.org/.../ezine2.pdf talks about that.  It makes no use of .Net libraries so if you're on UNIX, it is far more portable.

Setting a cookie and reading the cookie can be found here (pure 4GL and no .Net stuff ) knowledgebase.progress.com/.../17305

Posted by Peter Judge on 26-May-2016 13:30

Just for reference the "Net" in the code sample I sent refers to "Network" (similar to java.net.*). It has nothing to do with Microsoft .NET.
 

Posted by scott_auge on 26-May-2016 14:01

Ah, my mistake.  Thanks for the heads up.

Posted by Peter Judge on 26-May-2016 14:08

It's confusing as anything (and I know, I named it thus) … but no better alternatives  presented themselves …
 

Posted by marian.edu on 27-May-2016 00:05

Hey Peter, I have to say things are now so much easier than the old wrap-cgi api :)

Wonder what the difference is between OE.Net.HTTP and OE.Web, other than that I would have been expecting to don't even see the WebResponseWriter and only work with the WebResponse object but that might also be possible so pardon my ignorance ;)

All in all the sample looks good, wonder though how easy one could migrate from old webspeed api...

Posted by Bill Wood on 27-May-2016 00:10

Wrt

> >>> have to say things are now so much easier than the old wrap-cgi api

+1.

Posted by Valeriy Bashkatov on 27-May-2016 02:53

Wow! Thank you all.

Posted by Peter Judge on 27-May-2016 08:36

OpenEdge.Net.* contains the HTTP client (ie caller) and more general HTTP stuff (like URI's , request and response definitions).
OpenEdge.Web.* contains the HTTP server-side stuff that's intended to run in PASOE.
 
They're currently in the same procedure library but that will probably change (we want to make OE.Net.* part of the 'base install' since the ability to call REST/HTTP-based services is so central to many apps).
 

Posted by Peter Judge on 27-May-2016 08:38

All in all the sample looks good, wonder though how easy one could migrate from old webspeed api...

<marketing-ish hat>
Well you can run 'classic' WebSpeed apps in PASOE without changes* . The ability to define a handler for a specific URI means that you can incrementally move single services to the newer approach without a big bang.
 
I think, though, that if you wanted to do a complete change to the newer approach you'd have do a fair amount of manual rewrite (and am happy to be proven wrong :)
 
* usually
 
 

This thread is closed