직접 RESTMessageV2 예시
아웃바운드 REST 메시지를 엔드포인트로 직접 보낼 수 있습니다.
이 예에서 스크립트는 주식 시세를 요청하는 REST 메시지를 보내고 응답을 기다립니다. 웹 서비스 제공자로부터 응답이 없거나 지정된 REST 메시지 레코드를 사용할 수 없는 경우, 스크립트는 오류를 발생시키며, 이 예에서는 try-catch 블록에 의해 처리됩니다.
var requestBody;
var responseBody;
var status;
var sm;
try{
sm = new sn_ws.RESTMessageV2("Yahoo Finance", "get"); // 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 milliseconds. 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.
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);