public void startReceiver() { Response response = client.target(apiPath + "/v2/admin/system/request-receiver/actions/execute") .request(MediaType.APPLICATION_JSON_TYPE) .post(Entity.entity("", MediaType.WILDCARD_TYPE)); HttpStatusCode statusCode = HttpStatusCode.findByCode(response.getStatus()); if (statusCode != HttpStatusCode.NO_CONTENT) { throw ApiException.fromCode(statusCode, "Start of request receiver failed: " + response.getStatusInfo()); } }
public static ApiException fromCode(int code) { return fromCode(toHttpStatusCode(code)); } public static ApiException fromCode(HttpStatusCode httpStatusCode) {
public static ApiException fromCode(int code, String message, Throwable ex, String...traits) { return fromCode(toHttpStatusCode(code), message, ex, traits); } public static ApiException fromCode(HttpStatusCode httpStatusCode, String message, Throwable ex, String...traits) {
public static ApiException fromCode(int code, FineMessageSet messageSet) { return fromCode(toHttpStatusCode(code), messageSet); } public static ApiException fromCode(HttpStatusCode httpStatusCode, FineMessageSet messageSet) {
public static ApiException fromCode(int code, Throwable ex, String...traits) { return fromCode(toHttpStatusCode(code), ex, traits); } public static ApiException fromCode(HttpStatusCode httpStatusCode, Throwable ex, String...traits) {
public void checkStatus() throws Exception { Response response = client.target(apiPath + "/v2/status") .request(MediaType.APPLICATION_JSON_TYPE) .get(); HttpStatusCode statusCode = HttpStatusCode.findByCode(response.getStatus()); if (statusCode != HttpStatusCode.OK) { throw ApiException.fromCode(statusCode, "Get of tasks FAILED: " + response.getStatusInfo()); } String json = response.readEntity(String.class); JOptionPane.showMessageDialog(null, json, "Status: " + statusCode, JOptionPane.INFORMATION_MESSAGE); }
public void startProcessor() { Response response = client.target(apiPath + "/v2/admin/system/task-processor/actions/execute") .request(MediaType.APPLICATION_JSON_TYPE) .post(Entity.entity("", MediaType.WILDCARD_TYPE)); HttpStatusCode statusCode = HttpStatusCode.findByCode(response.getStatus()); if (statusCode != HttpStatusCode.NO_CONTENT) { throw ApiException.fromCode(statusCode, "Start of task processor failed: " + response.getStatusInfo()); } } }
public static ApiException fromCode(int code, FineMessage richMessage) { return fromCode(toHttpStatusCode(code), richMessage); } public static ApiException fromCode(HttpStatusCode httpStatusCode, FineMessage richMessage) {
public static ApiException fromCode(int code, String message, String...traits) { return fromCode(toHttpStatusCode(code), message, traits); } public static ApiException fromCode(HttpStatusCode httpStatusCode, String message, String...traits) {
public static ApiException fromCode(int code, FineMessage richMessage, Throwable ex) { return fromCode(toHttpStatusCode(code), richMessage, ex); } public static ApiException fromCode(HttpStatusCode httpStatusCode, FineMessage richMessage, Throwable ex) {
public static ApiException fromCode(int code, FineMessageSet messageSet, Throwable ex) { return fromCode(toHttpStatusCode(code), messageSet, ex); } public static ApiException fromCode(HttpStatusCode httpStatusCode, FineMessageSet messageSet, Throwable ex) {
public void deleteNotification(String domainName, Notification notification) { Response response = client.target(apiPath + "/v2/admin/domains").path(domainName).path("notifications").path(notification.getNotificationId()) .request(MediaType.APPLICATION_JSON_TYPE) .delete(); HttpStatusCode statusCode = HttpStatusCode.findByCode(response.getStatus()); if (statusCode != HttpStatusCode.NO_CONTENT) { throw ApiException.fromCode(statusCode, "Delete of notification FAILED: " + response.getStatusInfo()); } }
public void deleteRequest(String domainName, NotificationRequest request) { Response response = client.target(apiPath + "/v2/admin/domains").path(domainName).path("requests").path(request.getRequestId()) .request(MediaType.APPLICATION_JSON_TYPE) .delete(); HttpStatusCode statusCode = HttpStatusCode.findByCode(response.getStatus()); if (statusCode != HttpStatusCode.NO_CONTENT) { throw ApiException.fromCode(statusCode, "Delete of request FAILED: " + response.getStatusInfo()); } }
public void deleteTask(String domainName, Task task) { Response response = client.target(apiPath + "/v2/admin/domains").path(domainName).path("tasks").path(task.getTaskId()) .request(MediaType.APPLICATION_JSON_TYPE) .delete(); HttpStatusCode statusCode = HttpStatusCode.findByCode(response.getStatus()); if (statusCode != HttpStatusCode.NO_CONTENT) { throw ApiException.fromCode(statusCode, "Delete of tasks FAILED: " + response.getStatusInfo()); } }
private void updateCatalog() throws Exception { File currentDir = new File("").getAbsoluteFile(); File configDir = new File(currentDir, "/runtime/config/"); String fileName = String.format("route-catalog-%s.json", domainName); File jsonFile = new File(configDir, fileName); String json = IoUtils.toString(jsonFile); Response response = client.target(apiPath + "/v2/admin/domains").path(domainName).path("route-catalog") .request(MediaType.APPLICATION_JSON_TYPE) .put(Entity.entity(json, MediaType.APPLICATION_JSON_TYPE)); HttpStatusCode statusCode = HttpStatusCode.findByCode(response.getStatus()); if (statusCode != HttpStatusCode.OK) { throw ApiException.fromCode(statusCode, "Update of route catalog FAILED: " + response.getStatusInfo()); } JOptionPane.showMessageDialog(null, "The catalog has been updated:\n" + jsonFile, "Catalog Updated", JOptionPane.INFORMATION_MESSAGE); }
@Override public void validateWithThrow(Object object, HttpStatusCode statusCode, Class<?>... groups) { Set<ConstraintViolation<Object>> violations = validator.validate(object, groups); FineMessageSet messageSet = newFineMessageSet(violations); if (messageSet.isNotEmpty()) { throw ApiException.fromCode(statusCode, messageSet); } }
@SuppressWarnings("unchecked") public QueryResult<Task> getTasks(TaskStatus taskStatus) throws IOException { Response response = client.target(apiPath + "/v2/admin/domains").path(domainName).path("tasks") .queryParam("taskStatus", taskStatus) .request(MediaType.APPLICATION_JSON_TYPE) .get(); HttpStatusCode statusCode = HttpStatusCode.findByCode(response.getStatus()); if (statusCode != HttpStatusCode.OK) { throw ApiException.fromCode(statusCode, "Get of tasks FAILED: " + response.getStatusInfo()); } String json = response.readEntity(String.class); NotifyObjectMapper objectMapper = new NotifyObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return objectMapper.readValue(json, QueryResult.class); }
@SuppressWarnings("unchecked") public QueryResult<Notification> getNotifications(String domainName) throws IOException { Response response = client.target(apiPath + "/v2/admin/domains").path(domainName).path("notifications") .request(MediaType.APPLICATION_JSON_TYPE) .get(); HttpStatusCode statusCode = HttpStatusCode.findByCode(response.getStatus()); if (statusCode != HttpStatusCode.OK) { throw ApiException.fromCode(statusCode, "Get of tasks FAILED: " + response.getStatusInfo()); } String json = response.readEntity(String.class); NotifyObjectMapper objectMapper = new NotifyObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return objectMapper.readValue(json, QueryResult.class); }
public DomainProfile getOrCreateDomainProfile(Client client, String domainName) throws IOException { Response response = client.target(apiPath + "/v2/admin/domains").path(domainName) .request(MediaType.APPLICATION_JSON_TYPE) .put(Entity.entity("", MediaType.WILDCARD_TYPE)); HttpStatusCode statusCode = HttpStatusCode.findByCode(response.getStatus()); if (statusCode != HttpStatusCode.OK) { String msg = String.format("Put of domain \"%s\" FAILED: %s", domainName, response.getStatusInfo()); throw ApiException.fromCode(statusCode, msg); } String json = response.readEntity(String.class); NotifyObjectMapper objectMapper = new NotifyObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return objectMapper.readValue(json, DomainProfile.class); }
protected void assertResponse(int status) { HttpStatusCode statusCode = HttpStatusCode.findByCode(status); if (statusCode.isSuccess() == false) { String msg = String.format("Unexpected response: %s %s", status, statusCode.getReason()); throw ApiException.fromCode(statusCode, msg); } }