Method GET or method POST with webservices

Posted by wsartorelli on 27-Dec-2017 05:48

I need to do a webservice consumption routine in the POST method. How do I differentiate the POST method from the GET method inside the webservice consumption code? I'm using the Progress 11.7 version.

Thanks.

All Replies

Posted by Irfan on 27-Dec-2017 06:20

Hi,

If you are using WebHandlers then they can determine if the request is of HTTP type GET or POST and execute HTTPGet or HTTPPost methods. All you have to do is write your own logic inside Get and Post metods in WebHandlers.

METHOD OVERRIDE PROTECTED INTEGER HandleGet( INPUT poRequest AS OpenEdge.Web.IWebRequest ):

 END METHOD.

   METHOD OVERRIDE PROTECTED INTEGER HandlePost( INPUT poRequest AS OpenEdge.Web.IWebRequest ):

   END METHOD.

Posted by wsartorelli on 28-Dec-2017 07:42

Hi Irfan,

in the poRequest input, do I put my DATASET in?

The DATASET do I send for webservice consumption?

Tanks.

Posted by Akshay Guleria on 28-Dec-2017 08:28

If you are consuming a POST request then you can get the payload using poRequest:ENTITY.

Posted by Irfan on 28-Dec-2017 08:42

If you are sending a JSON in your POST then you can do something like this

def var JObj as JsonObject no-undo.

JObj = cast(poRequest:Entity,JSONArray).

You can do something similarly XML,text, memptr or any other payload.

If you would like to read this to a dataset then you can do

dataset ds1:read-json('JsonObject',JObj,true).

Posted by wsartorelli on 28-Dec-2017 11:14

Irfan,

250/5000

follow my code, this one with error in the line:

RUN execute IN hWSTransacional (INPUT DATASET executeRequest,

                               OUTPUT DATASET executeResponse).

It is arriving on the vendor server as GET and should arrive as POST.

Please, where am I going wrong?

Code:

DEFINE VARIABLE hWebService     AS HANDLE NO-UNDO.

DEFINE VARIABLE hWSTransacional AS HANDLE NO-UNDO.

DEF VAR err AS LOG NO-UNDO.

&SCOPED-DEFINE xFormated TRUE  

/** REQUEST Group.. START**/

DEFINE TEMP-TABLE arg0 NO-UNDO

   NAMESPACE-URI ""

   FIELD context AS CHARACTER XML-NODE-NAME "context".

DEFINE TEMP-TABLE fieldsRequest NO-UNDO

   NAMESPACE-URI ""

   XML-NODE-NAME "fields"

   FIELD key       AS CHARACTER XML-NODE-NAME "key"

   FIELD value1    AS CHARACTER XML-NODE-NAME "value"

   FIELD arg0_id   AS RECID     XML-NODE-TYPE "HIDDEN" .

DEFINE DATASET executeRequest NAMESPACE-URI "webservice.pamcard.jee.pamcary.com.br"

   XML-NODE-NAME "execute"

   FOR arg0, fieldsRequest

   PARENT-ID-RELATION RELATION1 FOR arg0, fieldsRequest

       PARENT-ID-FIELD arg0_id.

/** REQUEST Group.. END**/

/** RESPOUNCE Group.. START**/

DEFINE TEMP-TABLE returnResponce NO-UNDO

   NAMESPACE-URI ""

   XML-NODE-NAME "return"

   FIELD return1_field AS INTEGER XML-NODE-TYPE "HIDDEN" .

DEFINE TEMP-TABLE fieldsResponce NO-UNDO

   NAMESPACE-URI ""

   XML-NODE-NAME "fields"

   FIELD key           AS CHARACTER    XML-NODE-NAME "key"

   FIELD value1        AS CHARACTER    XML-NODE-NAME "value"

   FIELD return1_id    AS RECID        XML-NODE-TYPE "HIDDEN" .

DEFINE DATASET executeResponse

   NAMESPACE-URI "webservice.pamcard.jee.pamcary.com.br"

   XML-NODE-NAME "executeResponse"

   FOR returnResponce, fieldsResponce

   PARENT-ID-RELATION RELATION1 FOR returnResponce, fieldsResponce

       PARENT-ID-FIELD return1_id  .

/** RESPOUNCE Group.. END**/

CREATE SERVER hWebService.

hWebService:CONNECT("-WSDL 'preproducao.roadcard.com.br/.../WSTransacional " +

                   "-SOAPEndpoint preproducao.roadcard.com.br/sistemapamcardwsdl " +

                   "-sslAuth ssl " +

                   "-sslKeyFile D:\Pamcard\quimicaamparo2017.pfx " +

                   "-sslKeyPwd 12345678 " +

                   "-ssl " +

                   "-nohostverify ").

RUN WSTransacional SET hWSTransacional ON hWebService.      

/*** Create

Create the necessary Temp-tables here.*/

CREATE arg0.

ASSIGN arg0.context = "FindCard".

FIND FIRST arg0 NO-LOCK NO-ERROR.

CREATE fieldsRequest.

ASSIGN fieldsRequest.KEY    = "viagem.contratante.documento.numero"

      fieldsRequest.value1 = "43461789000190"

      fieldsRequest.arg0_id = RECID(arg0).

CREATE fieldsRequest.

ASSIGN fieldsRequest.KEY    = "viagem.cartao.numero"

      fieldsRequest.value1 = "4417819800000860"

      fieldsRequest.arg0_id = RECID(arg0).

/****/

/** debug**/      

DATASET executeRequest:WRITE-XML("file",SESSION:TEMP-DIRECTORY + "/executeRequest.xml":U, {&xFormated} ).  

RUN execute IN hWSTransacional(INPUT  DATASET executeRequest,

                              OUTPUT DATASET executeResponse) .

RUN ErrorInfo (OUTPUT err).

/* IF NOT err THEN DO:                       */

/*     MESSAGE STRING(cResponse) "~n"        */

/*      STRING(MTIME - li) " milisecondes."  */

/*      VIEW-AS ALERT-BOX.                   */

/* END.                                      */

/** debug**/      

DATASET executeResponse:WRITE-XML("file",SESSION:TEMP-DIRECTORY + "/executeResponse.xml":U, {&xFormated} ).  

/** Garbage collection is needed here. i.e. DELETE OBJECT hWebService.**/

PROCEDURE execute:

 DEFINE INPUT PARAMETER DATASET FOR executeRequest.

 DEFINE OUTPUT PARAMETER DATASET FOR executeResponse.

END PROCEDURE.

/*******************************************************************/

PROCEDURE ErrorInfo: /*1*/

 DEFINE OUTPUT PARAMETER errorfound AS LOGICAL INITIAL FALSE.

 DEFINE VARIABLE i                  AS INTEGER NO-UNDO.

 DEFINE VARIABLE hSOAPFault         AS HANDLE NO-UNDO.

 DEFINE VARIABLE hSOAPFaultDetail   AS HANDLE NO-UNDO.

 DEFINE VARIABLE HeaderXML AS LONGCHAR VIEW-AS EDITOR SIZE 70 BY 15 LARGE.

 IF ERROR-STATUS:NUM-MESSAGES > 0 THEN DO:

    errorfound = TRUE.

    DO i = 1 TO ERROR-STATUS:NUM-MESSAGES:

       MESSAGE ERROR-STATUS:GET-MESSAGE(i) VIEW-AS ALERT-BOX.

    END.

/*2*/

    IF VALID-HANDLE(ERROR-STATUS:ERROR-OBJECT-DETAIL) THEN DO:

      hSOAPFault = ERROR-STATUS:ERROR-OBJECT-DETAIL.

      MESSAGE

      "Fault Code: "   hSOAPFault:SOAP-FAULT-CODE        SKIP

      "Fault String: " hSOAPFault:SOAP-FAULT-STRING      SKIP

      "Fault Actor: "  hSOAPFault:SOAP-FAULT-ACTOR       SKIP

      "Error Type: "   hSOAPFault:TYPE  VIEW-AS ALERT-BOX.

/*3*/

      IF VALID-HANDLE(hSOAPFault:SOAP-FAULT-DETAIL) THEN  DO:

           hSOAPFaultDetail = hSOAPFault:SOAP-FAULT-DETAIL.

           MESSAGE  "Error Type: " hSOAPFaultDetail:TYPE

                    VIEW-AS ALERT-BOX.

           HeaderXML = hSOAPFaultDetail:GET-SERIALIZED().

           DISPLAY HeaderXML LABEL "Serialized SOAP fault detail"

                   WITH FRAME a.

       END.

    END.

 END.

END PROCEDURE.

/*******************************************************************/

This thread is closed