직접 SOAPMessageV2 예제
아웃바운드 SOAP 메시지를 엔드포인트로 직접 보낼 수 있습니다.
이 예제에서 스크립트는 주식 시세를 요청하는 SOAP 메시지를 보내고 응답을 기다립니다. 웹 서비스 공급자로부터 응답이 없거나 지정된 SOAP 메시지 레코드를 사용할 수 없는 경우 스크립트에서 오류가 발생하며 이 예제에서 try-catch 블록에 의해 처리됩니다.
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>");
sm.setHttpTimeout(10000) //In Milli seconds. Wait at most 10 seconds for response from http request.
response = sm.execute();//Might throw exception if http connection timed out or some issue with sending request itself because of encryption/decryption of password and stuff
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);