REST Adapter and "complete" URL as input parameter

Posted by Mike Fechner on 16-Jan-2015 03:11

Hi, the REST Adapter allows to map the "Complete URL" to an input parameter of an ABL method. 

However, the QueryString portion of the URL is not part of this. According to http://en.wikipedia.org/wiki/Uniform_resource_locator I was under the impression that the Query String is part of the URL.

I was trying to be able to parse the Query String in the ABL and not have to map every possible query string parameter to a disctinct input parameter of the ABL method. 

Is my understanding of the term "Complete URL" wrong? Is this a bug? Or is there another was to send the complete Query String (including all the name/value pairs) to the ABL method.

Still on OpenEdge 11.4 for this customer. 

All Replies

Posted by bronco on 16-Jan-2015 03:27

Hi Mike,

you could use "servlet request" from the "servlet contexts" in the mapping dialog.

hth

Posted by Donicello Lampe on 16-Jan-2015 03:33
Posted by bronco on 16-Jan-2015 05:00

Btw, if you don't want to program parsing the servlet request, take a look at:

bitbucket.org/.../pug2014

to more precise, the ServletRequestParser class:

bitbucket.org/.../ServletRequestParser.cls

and the ServletRequestInfo class:

bitbucket.org/.../ServletRequestInfo.cls

Posted by Mike Fechner on 17-Jan-2015 12:10

Nice work, Bronco!
Von: bronco [mailto:bounce-bfvo@community.progress.com]
Gesendet: Freitag, 16. Januar 2015 12:01
An: TU.OE.Development@community.progress.com
Betreff: RE: [Technical Users - OE Development] REST Adapter and "complete" URL as input parameter?
 
Reply by bronco

Btw, if you don't want to program parsing the servlet request, take a look at:

bitbucket.org/.../pug2014

to more precise, the ServletRequestParser class:

bitbucket.org/.../ServletRequestParser.cls

and the ServletRequestInfo class:

bitbucket.org/.../ServletRequestInfo.cls

Stop receiving emails on this subject.

Flag this post as spam/abuse.

Posted by Mike Fechner on 18-Jan-2015 10:32

Bronco, is there a particular reason why you map the rest request info property "method" to "HttpMethod" in your parser? I just tried and 11.5 at least does allow a property called "Method".

I'm not saying it's wise to do in general ... but in this case where you just transform data from REST into an ABL class, I'm tempted to leave the property name in the ABL as it was in the Json string.

Posted by bronco on 18-Jan-2015 13:33

Well, I was pretty sure it gave a compile error. I just checked however and there's no error in 11.3/11.4 either so I guess the mapping from Method to HttpMethod is superfluous...

Posted by bronco on 18-Jan-2015 13:42

... on the other hand, "Method" is a bit ambiguous.

Posted by pedrorodriguez on 05-May-2017 11:10

Sorry to bring back an old thread, but I am trying to achieve same idea to parse whole URL to a single parameter to process the query string, these two classes are very useful but they still leave the query string unparsed.

Do you know if there are a library or class in Openedge.Net package maybe to parse the query string to get the list of key/values?

Cheers,

Posted by bronco on 05-May-2017 11:42

Don't know, but it's not rocket science. The query string is just a '&' delimited string. You can add somthing like the to the requestinfo class:

  define private variable queryStringProcessed as logical no-undo.


  method public character GetQueryParameter(parameterName as character):
    
    /* lazy parsing: don't parse until needed */    
    if (not queryStringProcessed) then do:
      processQueryString().
      queryStringProcessed = true.
    end.
    
    return KeyValueStore:Get("RequestQueryString", parameterName).
        
  end method.
  
  
  method private void processQueryString():
    
    define variable i as integer no-undo.
    define variable numEntries as integer no-undo.
    define variable currentEntry as character no-undo.
    
    if (QueryString = "" or QueryString = ?) then 
      return.
      
    numEntries = num-entries(QueryString, "&").
    do i = 1 to numEntries:
      currentEntry = entry(i, QueryString, "&"). 
      /* key = entry(1, currentEntry, "="). */
/* value = entry(2, currentEntry, "=")). */ end. end method.

Posted by bronco on 05-May-2017 11:43

Now you have to make something yourself for the KeyValueStore class, but you get the drift.

Posted by pedrorodriguez on 05-May-2017 11:47

Thanks bronco, yes I understand is not rocket science, but just wondered if there was an already working version of it in some of the new Openedge.net classes.

Your code would work for the most basic cases, but there will be, at least URI encode values that would need processing, and not sure if some other edge case that needs to be considered.

Appreciate your code, if there is nothing already available it will be a good head start.

Posted by Derek Lord on 05-May-2017 12:25

An alternative if you have the URI -  Method with INPUT poURI AS URI:

     DEFINE VARIABLE cNamesArray    AS CHARACTER  EXTENT NO-UNDO.

     DEFINE VARIABLE iNamesArray    AS INTEGER    NO-UNDO.

     DEFINE VARIABLE iIdx           AS INTEGER    NO-UNDO.

     ASSIGN iNamesArray = poURI:GetQueryNames(OUTPUT cNamesArray).

     DO iIdx = 1 TO iNamesArray:

        MESSAGE cNamesArray[iIdx].

        MESSAGE poUri:GetQueryValue(cNamesArray[iIdx]).

     END.

Posted by Peter Judge on 06-May-2017 04:42

Make sure the $DLC/tty/OpenEdge.Net.pl is in propath (from 11.6 on)
 
USING OpenEdge.Net.URI.
 
DEF VAR myURI AS URI.
DEF VAR qryNames AS CHARACTER EXTENT.
DEF VAR numQryParam AS INT.
DEF VAR qryValue aS CHAR.
 
myURI = URI:Parse(“example.com
 
numQryParam = myURI:GetQureyNames(OUTPUT qryNames).
DO loop = 1 to numQryParams:
   qryVal = myURI:GetQueryValue(qryNames[loop]).
END.
 

Posted by pedrorodriguez on 08-May-2017 02:13

Thanks, that's exactly what I was looking for.

Posted by pedrorodriguez on 08-May-2017 06:16

I thought we were in 11.6 but still in 11.5.1, I assume that there are not Openedge.net classes available for 11.5.1, right?

Posted by Peter Judge on 08-May-2017 11:20

There are. They should work the same as 11.6.0+
 
 

This thread is closed