REST API를 사용하여 의사결정 서비스 호출

사용 중인 클라이언트는 Operational Decision Manager의 REST API를 통해 의사결정 서비스를 호출합니다. 클라이언트는 원격 서버와 상호 작용 시 웹 브라우저에서 사용하는 표준 HTTP GET, POST, PUT 및 DELETE 명령을 사용하여 의사결정 서비스를 호출합니다.

이 태스크 정보

Operational Decision Manager는 의사결정 서비스로 알려진 재사용 가능한 오퍼레이션으로 비즈니스 의사결정을 제공합니다. 클라이언트 애플리케이션은 서버와의 보안 연결을 작성한 후 REST API를 통해 의사결정 서비스를 호출하여 의사결정 서비스를 호출합니다.
Operational Decision Manager 서버에서 의사결정 서비스의 엔드포인트 URI는 다음 형식을 사용합니다.
http://<host>:<port>/DecisionService/rest/v1/<ruleset_path>

다음 목록은 URI의 부분을 설명합니다.

  • <host>: 의사결정 서비스에 대한 호스트의 이름으로 제공됩니다.
  • <port>: 포트 번호
  • <ruleset_path>: 의사결정 서비스 규칙 실행을 위한 경로를 제공하며 다음 형식 중 하나를 사용해야 합니다.
    • ruleAppName/rulesetName
    • ruleAppName/ruleAppVersion/rulesetName
    • ruleAppName/ruleAppVersion/rulesetName/rulesetVersion
다음 예는 MiniloanServiceRuleset에 대한 URI를 보여 줍니다.
http://localhost:9080/DecisionService/rest/v1/
MiniloanService/MiniloanServiceRuleset
의사결정 서비스 규칙 세트는 지정된 엔드포인트 URI에서 HTTP POST를 통해 수행됩니다.

예

다음 예는 Operational Decision Manager 서버에서 MiniloanService 의사결정 서비스를 호출하는 Java™ 코드를 보여줍니다. 예제에서는 Apache HTTPClient v4.3를 사용합니다.

import java.io.IOException;

import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class DecisionServiceExecution {

	public static void main(String[] args) throws ClientProtocolException, IOException {
		
		// Replace <host> and <port>
		String endpointURI = "http://<host>:<port>/DecisionService/rest/v1/MiniloanService/MiniloanServiceRuleset";

		String contentType = "application/json";

		// Set the borrower and the loan
		String payload = "{\"borrower\": {" +
				"\"name\": \"John\"," +
				"\"creditScore\": 600," +
				"\"yearlyIncome\": 80000" +
				"}," +
				"\"loan\": {" +
				"\"amount\": 500000," +
				"\"duration\": 240," +
				"\"yearlyInterestRate\": 0.05" +
				"}" +
				"}";
		
		CloseableHttpClient client = HttpClients.createDefault();
		
		try {
			HttpPost httpPost = new HttpPost(endpointURI);
			httpPost.setEntity(new StringEntity(payload));
			CloseableHttpResponse response = client.execute(httpPost);
			try {
				if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
					System.err.println("Status Code: " + response.getStatusLine().getStatusCode());
					System.err.println("Status Line: " + response.getStatusLine());
					String responseEntity = EntityUtils.toString(response.getEntity());
					System.err.println("Response Entity: " + responseEntity);

					throw new RuntimeException(
							"An error occurred when invoking Decision Service at: "
									+ endpointURI
									+ "\n"
									+ response.getStatusLine() + ": " + responseEntity);
				}  else {
					String result = EntityUtils.toString(response.getEntity());
					System.out.println("Result: " + result);
				}
			} finally {
				if (response != null) {
					response.close();
				}
			}
		} finally {
			client.close();
		}
	}
	
}