Is there a way I can access HTTP Header in a incoming HTTP Request for an OE REST service call ? - Forum - OpenEdge Development - Progress Community

Is there a way I can access HTTP Header in a incoming HTTP Request for an OE REST service call ?

 Forum

Is there a way I can access HTTP Header in a incoming HTTP Request for an OE REST service call ?

This question is not answered

I need to extract username and password for user authentication. 

All Replies
  • For the REST transport you can map the header you’re interested in to an input parameter.
     
  • As suggested I tried adding ReqHeader  to the Service_Interface code, but when I tried to map the HTTP GET once more

    I am getting the following error:

    Rest file include Invocation file generation failed. The procedure  includes unsupported data types "openedge.net.http.httpheader". Remove the unsupported parameter data types from the following procedures(s):

    "Read1"  to successfully generate REST invocation file.

    Any ideas on how to recover the userid/password  from the request  header since I am sending it to  the OEPAS instance ?

    /* Code from Service_Interface

    block-level on error undo, throw.

    using Progress.Lang.*.

    /* ***************************  Definitions  ************************** */

    define variable CustInfoInstanceRead as AppServer.CustomerDispatcher no-undo.

    define input parameter CustId as integer no-undo.

    define input parameter ReqHeader as OpenEdge.Net.HTTP.HttpHeader no-undo.

    define temp-table custrecord like Customer.

    define output parameter TABLE  for custrecord.

    define output parameter reason as character no-undo.

    CustInfoInstanceRead= new AppServer.CustomerDispatcher().

    CustInfoInstanceRead:Read1(input CustId,input ReqHeader,output TABLE custrecord,output reason).

    return.

    ---------------------------------------------------------------------------------------------------------------

    /* Snippet from CustomerDispatcher Class */

    @openapi.openedge.export(type="REST", useReturnValue="false", writeDataSetBeforeImage="false").

    method public integer Read1(input custId as integer, input ReqHeader as OpenEdge.Net.HTTP.HttpHeader, output TABLE custRecord, output httpReason as character):

    define variable httpStatus as integer initial 200.

           /* Assume 200 status code */

           empty temp-table custRecord.

           find first Customer where Customer.CustNum = custId no-error.

           if available Customer then do:

               create custRecord.

               buffer-copy Customer to custRecord.

           end.

           else do:

               httpStatus = 404.

               httpReason = "ERROR: Customer " + STRING(custId) + " not found]".

           end.

           release Customer.

           return httpStatus.

    end method.

  • Pretty sure only simple parameter types like Character and Integer etc. are supported for REST interfaces.

    Sent from Nine

    Von: Walter Mangra <bounce-wmangra@community.progress.com>
    Gesendet: Montag, 14. Mai 2018 02:56
    An: TU.OE.Development@community.progress.com
    Betreff: RE: [Technical Users - OE Development] Is there a way I can access HTTP Header in a incoming HTTP Request for an OE REST service call ?

    Update from Progress Community
    Walter Mangra

    As suggested I tried adding ReqHeader  to the Service_Interface code, but when I tried to map the HTTP GET once more

    I am getting the following error:

    Rest file include Invocation file generation failed. The procedure  includes unsupported data types "openedge.net.http.httpheader". Remove the unsupported parameter data types from the following procedures(s):

    "Read1"  to successfully generate REST invocation file.

    Any ideas on how to recover the userid/password  from the request  header since I am sending it to  the OEPAS instance ?

    /* Code from Service_Interface

    block-level on error undo, throw.

    using Progress.Lang.*.

    /* ***************************  Definitions  ************************** */

    define variable CustInfoInstanceRead as AppServer.CustomerDispatcher no-undo.

    define input parameter CustId as integer no-undo.

    define input parameter ReqHeader as OpenEdge.Net.HTTP.HttpHeader no-undo.

    define temp-table custrecord like Customer.

    define output parameter TABLE  for custrecord.

    define output parameter reason as character no-undo.

    CustInfoInstanceRead= new AppServer.CustomerDispatcher().

    CustInfoInstanceRead:Read1(input CustId,input ReqHeader,output TABLE custrecord,output reason).

    return.

    ---------------------------------------------------------------------------------------------------------------

    /* Snippet from CustomerDispatcher Class */

    @openapi.openedge.export(type="REST", useReturnValue="false", writeDataSetBeforeImage="false").

    method public integer Read1(input custId as integer, input ReqHeader as OpenEdge.Net.HTTP.HttpHeader, output TABLE custRecord, output httpReason as character):

    define variable httpStatus as integer initial 200.

           /* Assume 200 status code */

           empty temp-table custRecord.

           find first Customer where Customer.CustNum = custId no-error.

           if available Customer then do:

               create custRecord.

               buffer-copy Customer to custRecord.

           end.

           else do:

               httpStatus = 404.

               httpReason = "ERROR: Customer " + STRING(custId) + " not found]".

           end.

           release Customer.

           return httpStatus.

    end method.

    View online

     

    You received this notification because you subscribed to the forum.  To unsubscribe from only this thread, go here.

    Flag this post as spam/abuse.

    Architect of the SmartComponent Library and WinKit

    Consultingwerk Ltd.

  • We do this by mapping the Authorization header, then we get the value through an CHARACTER input parameter.

    Using Basic authentification scheme, the first entry (separated by " ") must be "Basic" and the second one is a base64 encoded string that you must pass through base64-decode in order to get the string "user:password".

  • Thank for you response. No sure I am doing this correctly. I tried to  select  'Authorization' under the input  "Headers" tag of the URI editor, but only 'Content-Type' was available to choose from  once I click and selected the 'Add Node'.option.

    I am aware of the need to base64-decode,  the base64 encoded once I retrieve it, but my show stopper is how to get to that string...