pedropeixoto
pedropeixoto

Reputation: 1633

Progress 4GL web service procedure

I'm trying to update our stocks thought the Magento API using Progress 4GL (OpenEdge 10.2B)

So far so good, ie: I can update the stock if the SKU is a match. But if it isn't, it doesn't return an error.

So I looked into how ABL manages SAOP fault errors, and found some examples which I tried to implement. But to no avail.

My new code is as follows:

DEFINE VARIABLE hWebService AS HANDLE NO-UNDO.
DEFINE VARIABLE hMage_Api_Model_Server_V2_HandlerPortType AS HANDLE NO-UNDO.
DEFINE VARIABLE username AS CHARACTER NO-UNDO.
DEFINE VARIABLE apiKey AS CHARACTER NO-UNDO.
DEFINE VARIABLE stock AS CHARACTER NO-UNDO.
DEFINE VARIABLE codigo AS CHARACTER NO-UNDO.
DEFINE VARIABLE loginReturn AS CHARACTER NO-UNDO.
DEFINE VARIABLE product AS CHARACTER NO-UNDO.
DEFINE VARIABLE data AS LONGCHAR NO-UNDO.
DEFINE VARIABLE resultado AS INTEGER NO-UNDO.
DEFINE VARIABLE SOAP-FAULT-CODE AS CHARACTER NO-UNDO.
DEFINE VARIABLE SOAP-FAULT-DETAIL AS CHARACTER NO-UNDO.
DEFINE VARIABLE iError AS INTEGER     NO-UNDO.
DEFINE VARIABLE cError AS CHARACTER   NO-UNDO.

DO ON ERROR UNDO, THROW:
CREATE SERVER hWebService.

 /* TODO: Definir variaveis globais */
username = 'username'.
apiKey  = 'password'.

hWebService:CONNECT(" -WSDL 'http://www.medicalemcasa.com/api/v2_soap?wsdl'").

RUN Mage_Api_Model_Server_V2_HandlerPortType SET hMage_Api_Model_Server_V2_HandlerPortType ON hWebService.
RUN login IN hMage_Api_Model_Server_V2_HandlerPortType(INPUT username, INPUT apiKey, OUTPUT loginReturn).


product = "100asda001a".
data = "
       <data>
       <qty>'250'</qty>
       </data>
       ".

PROCEDURE catalogInventoryStockItemUpdate:
  DEFINE INPUT PARAMETER data AS CHARACTER NO-UNDO.
END PROCEDURE.

RUN catalogInventoryStockItemUpdate IN hMage_Api_Model_Server_V2_HandlerPortType (INPUT loginReturn, INPUT product, INPUT data, OUTPUT resultado).
DISPLAY resultado.

CATCH mySoapErrorObject AS Progress.Lang.SoapFaultError:
    DO iError = 1 TO mySoapErrorObject:NumMessages:
        cError = cError + mySoapErrorObject:getMessage(iError) + "~n".
    END.
    DELETE OBJECT mySoapErrorObject.
END CATCH.

CATCH mySystemErrorObject AS Progress.Lang.SysError:
    DO iError = 1 TO mySystemErrorObject:NumMessages:
        cError = cError + mySystemErrorObject:getMessage(iError) + "~n".
    END.
    DELETE OBJECT mySystemErrorObject.
END CATCH.

FINALLY:
IF cError <> "" THEN DO:
    MESSAGE "Errors occured:" SKIP
        cError
        VIEW-AS ALERT-BOX ERROR.
END.
END FINALLY.
END.

hWebService:DISCONNECT().
DELETE OBJECT hWebService.

Upvotes: 0

Views: 3474

Answers (1)

Jensd
Jensd

Reputation: 8011

In those API's I've worked with SOAP errors only occur when there's a "bigger" error. For instance if the webservice is down, login criteria isn't met, datatypes are wrong etc. Usually a return value is rather in the response and not in the SOAP-envelope.

Could it be that it's simply OK to set a non existent product to inventory 0? What happens if you try to set it to 1? Perhaps you should double check from PHP (or whatever language you usually work with) that the web service actually provides the code you expect in this case?

Otherwise you should look at the wsdl-documentation created - are you 100% sure that the result-parameter (resultado in you code) is an INTEGER and not any form of more complicated xml-document (an object basically)? If it's really a HANDLE it might be that there's no run time error but no value is inserted into the INTEGER.

Also you should remove all your current error handling and replace it with a more general way to handle errors (and make that code more specific if needed rather than working from an example out of the documentation):

DEFINE VARIABLE iError AS INTEGER     NO-UNDO.
DEFINE VARIABLE cError AS CHARACTER   NO-UNDO.

CATCH mySoapErrorObject AS Progress.Lang.SoapFaultError:
    DO iError = 1 TO mySoapErrorObject:NumMessages:
        cError = cError + mySoapErrorObject:getMessage(iError) + "~n".
    END.
    DELETE OBJECT mySoapErrorObject.
END CATCH.

CATCH mySystemErrorObject AS Progress.Lang.SysError:
    DO iError = 1 TO mySystemErrorObject:NumMessages:
        cError = cError + mySystemErrorObject:getMessage(iError) + "~n".
    END.
    DELETE OBJECT mySystemErrorObject.
END CATCH.

And insert in the FINALLY-block:

IF cError <> "" THEN DO:
    MESSAGE "Errors occured:" SKIP
        cError
        VIEW-AS ALERT-BOX ERROR.
END.

Upvotes: 1

Related Questions