// *****************************
// RESPONSE DEFINITION
// *****************************
ApiDocResponse apiResponse = new ApiDocResponse();
// Building a JSON RESPONSE example
try {
JSONObject jsonResponseObject = new JSONObject();
JSONObject jsonResultObject = new JSONObject();
jsonResultObject
.put("success",
"Some informative coaching message. If success isn't a value, then maybe you have a 'fail' message.");
jsonResultObject.put(ServiceConfigurationAPI.API_SERVICE_ID,
"1234");
jsonResultObject.put(ServiceConfigurationAPI.API_SERVICE_NAME,
"Some service name");
jsonResultObject.put(
ServiceConfigurationAPI.API_SERVICE_SCHEMA,
"JSON Schema");
jsonResultObject
.put(ServiceConfigurationAPI.API_SERVICE_SCENARIO_ID,
"5678");
jsonResultObject.put(
ServiceConfigurationAPI.API_SERVICE_SCENARIO_NAME,
"Some scenario name");
jsonResultObject
.put(ServiceConfigurationAPI.API_SERVICE_RESPONSE_TYPE,
ServiceConfigurationAPI.API_SERVICE_RESPONSE_TYPE_VALUE_PROXY);
jsonResultObject.put(
ServiceConfigurationAPI.API_SERVICE_HANGTIME, "500");
jsonResultObject.put(
ServiceConfigurationAPI.API_TRANSIENT_STATE, "true");
jsonResponseObject.put("result", jsonResultObject);
apiResponse.setExample(jsonResponseObject.toString());
} catch (Exception e) {
log.error("Unabel to build a sample JSON message. ", e);
}
// Response attribute 'planId'
ApiDocAttribute resAttributePlanId = new ApiDocAttribute();
resAttributePlanId
.setFieldName(ServiceConfigurationAPI.API_SERVICE_ID);
resAttributePlanId.setFieldDescription("Identifier of a Service");
apiResponse.addAttribute(resAttributePlanId);
// Response attribute 'planName'
ApiDocAttribute resAttributePlanName = new ApiDocAttribute();
resAttributePlanName
.setFieldName(ServiceConfigurationAPI.API_SERVICE_NAME);
resAttributePlanName.setFieldDescription("Name of a Service");
apiResponse.addAttribute(resAttributePlanName);
// Response attribute 'success'
ApiDocAttribute resAttributeSuccess = new ApiDocAttribute();
resAttributeSuccess.setFieldName("success");
resAttributeSuccess
.setFieldDescription("Successfully set, deleted, or saved a plan. You get 'fail' or 'success', not both.");
apiResponse.addAttribute(resAttributeSuccess);
ApiDocAttribute resAttributeFail = new ApiDocAttribute();
resAttributeFail.setFieldName("fail");
resAttributeFail
.setFieldDescription("Failed to set, delete, or save a plan. You get 'fail' or 'success', not both.");
apiResponse.addAttribute(resAttributeFail);
apiDocService.setApiResponse(apiResponse);
apiStore.saveOrUpdateService(apiDocService);
}
}