Exemplo assíncrono de SOAPMessageV2

  • Versão de lançamento: Yokohama
  • Atualizado 30 de jan. de 2025
  • 1 min. de leitura
  • Você pode enviar uma mensagem SOAP de saída de forma assíncrona.

    Quando você envia uma mensagem assíncrona, a instância não espera por uma resposta antes de prosseguir. Você deve lidar com a espera de uma resposta em seu código.

    
    var requestBody;
    var responseBody;
    var status;
    var sm;
    try{
    	sm = new sn_ws.SOAPMessageV2("StockQuote", "GetQuote");  // Might throw exception if message doesn't exist or not visible due to scope
    	sm.setBasicAuth("admin","admin");
    	sm.setStringParameter("symbol", "NOW");
    	sm.setStringParameterNoEscape("xml_data","<data>test</data>");
    	response = sm.executeAsync(); //Might throw exception if http connection timed out or some issue with sending request itself because of encryption/decryption of password
    
    	response.waitForResponse(60);// In Seconds, Wait at most 60 seconds to get response from ECC Queue/Mid Server //Might throw exception timing out waiting for response in ECC queue
    
    	responseBody = response.haveError() ? response.getErrorMessage() : response.getBody();
    	status = response.getStatusCode();
    } catch(ex) {
    	responseBody = ex.getMessage();
    	status = '500';
    } finally {
    	requestBody = sm ? sm.getRequestBody():null;
    }
    gs.info("Request Body: " + requestBody);
    gs.info("Response: " + responseBody);
    gs.info("HTTP Status: " + status);