엔티티 작성

서버에 REST API POST 요청을 전송하여 엔티티를 작성하고 삽입할 수 있습니다.

이 태스크 정보

POST 요청을 사용하여, URI에 의해 표시되는 솔루션 위치의 엔티티를 저장하도록 서버에 지시할 수 있습니다. 엔티티가 존재하지 않는 경우, 서버는 POST 요청에서 제공되는 엔티티 컨텐츠를 사용하여 자원을 작성합니다. 엔티티가 존재하는 경우, 요청이 실패하며 상태 코드 409 충돌이 리턴된 응답에 표시됩니다. POST 요청은 기존 엔티티를 겹쳐쓰거나 업데이트하지 않습니다. 브라우저에서 작동하는 REST 클라이언트 도구에서 또는 Jython과 같은 스크립트를 사용하여 서버에 POST 요청을 전송합니다.

프로시저

  1. 브라우저 주소 필드에 일반 REST URL을 입력하여 Insight Server에 액세스할 수 있는지 확인하십시오. REST URL의 예는 엔티티 관리를 참조하십시오.
  2. 예에 표시된 구문을 사용하여 POST 요청을 작성하십시오.

    시스템에서 server.xml 파일의 httpEndpoint 설정 값에 따라, 요청 URL의 첫 번째 파트는 http://hostname:9080(httpPort 연결의 경우) 또는 https://hostname:9443(httpsPort 연결의 경우)입니다.

    .../solutions/solution_name/entity-types/entity_type/entities
    여기서 solution_name은 기호 솔루션 이름(예: BankingSolution)이며, entity_type은 person 또는 customer와 같은 엔티티의 카테고리입니다.

결과

성공적인 POST 요청의 응답에는 상태 코드 201 작성됨 및 새 엔티티의 경로를 제공하는 위치 헤더가 포함됩니다. 엔티티 삽입에 실패한 경우에는 엔티티의 존재를 표시할 수 있도록 상태 코드 409 Conflict이 리턴됩니다.

예

다음 예는 스크립트에 임베디드된 POST 요청을 표시합니다.
public void doPOSTUsingRESTRequest() throws Exception {
TestDriver driver = new TestDriver();
ConceptFactory cf = driver.getConceptFactory(ConceptFactory.class);

// Create a recipient entity in the hello_world solution
Recipient recp1 = cf.createRecipient("REP003");
recp1.setHelloCount(10000);

String solutionName = "hello_world";
String entityType = recp1.get$TypeName(); 

// com.ibm.ia.test.helloworld.Recipient
DriverProperties properties = new DriverProperties();
String runtimeHostName = properties.getproperty(
DriverProperties.RUNTIME_HOST_NAME, "localhost");

String url = "https://" + runtimeHostName
+ ":9443/ibm/ia/rest/solutions/" + solutionName
+ "/entity-types/" + entityType;
System.out.println(url);

HttpsURLConnection connection = getConnection(url, "POST", "application/xml");
driver.getModelSerializer().serializeEntity(DataFormat.GENERIC_XML,
connection.getOutputStream(), recp1, null);
connection.connect();
String content = getContent(connection, HttpURLConnection.HTTP_OK);
System.out.println(content);
connection.disconnect();
}