RESTMessageV2 MID 서버 예시

  • 릴리스 버전: Zurich
  • 업데이트 날짜 2025년 07월 31일
  • 소요 시간: 2분
  • MID 서버를 통해 아웃바운드 REST 메시지를 보낼 수 있습니다.

    MID 서버를 통해 메시지를 보내면 방화벽 뒤나 개인 네트워크 내에 있는 엔드포인트에 액세스할 수 있습니다. MID Server를 통해 전송되는 모든 REST 메시지는 비동기적입니다.

    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.setMIDServer('mid_server_name');
    	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);
    주:
    이 예제에서는 waitForResponse 를 사용하여 응답을 일시 중지한 다음 응답 처리 방법을 자세히 설명합니다. 그러나 executeAsync를 사용하는 경우 waitForResponse를 사용하는 대신 비동기 호출을 활용하도록 별도의 비즈니스 규칙에서 응답 본문을 처리하는 것이 좋습니다.