URI appsURI = targetURI.resolve(appsUrl);
GetMethod getAppsMethod = new GetMethod(appsURI.toString());
HttpUtil.configureHttpMethod(getAppsMethod, target);
getAppsMethod.setQueryString("q=name:" + appName + "&inline-relations-depth=1"); //$NON-NLS-1$ //$NON-NLS-2$
ServerStatus appsStatus = HttpUtil.executeMethod(getAppsMethod);
if (!appsStatus.isOK())
return appsStatus;
JSONObject apps = appsStatus.getJsonData();
if (!apps.has("resources") || apps.getJSONArray("resources").length() == 0) //$NON-NLS-1$//$NON-NLS-2$
return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "Application not found", null);
appMetadata = apps.getJSONArray("resources").getJSONObject(0).getJSONObject("metadata"); //$NON-NLS-1$ //$NON-NLS-2$
appEntity = apps.getJSONArray("resources").getJSONObject(0).getJSONObject("entity"); //$NON-NLS-1$ //$NON-NLS-2$
if (application.getGuid() == null) {
String summaryAppUrl = appMetadata.getString("url") + "/summary"; //$NON-NLS-1$ //$NON-NLS-2$
URI summaryAppURI = targetURI.resolve(summaryAppUrl);
GetMethod getSummaryMethod = new GetMethod(summaryAppURI.toString());
HttpUtil.configureHttpMethod(getSummaryMethod, target);
ServerStatus getStatus = HttpUtil.executeMethod(getSummaryMethod);
if (!getStatus.isOK())
return getStatus;
JSONObject summaryJSON = getStatus.getJsonData();
/* set known application GUID */
application.setGuid(summaryJSON.getString(CFProtocolConstants.V2_KEY_GUID));
}
/* gather application service bindings */
ArrayList<String> serviceInstances = new ArrayList<String>();
JSONArray appServiceBindings = appEntity.getJSONArray("service_bindings"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
for (int i = 0; i < appServiceBindings.length(); ++i) {
JSONObject binding = appServiceBindings.getJSONObject(i).getJSONObject("entity"); //$NON-NLS-1$
serviceInstances.add(binding.getString("service_instance_url")); //$NON-NLS-1$
}
/* delete the application */
URI appURI = targetURI.resolve("/v2/apps/" + application.getGuid()); //$NON-NLS-1$
DeleteMethod deleteAppMethod = new DeleteMethod(appURI.toString());
HttpUtil.configureHttpMethod(deleteAppMethod, target);
deleteAppMethod.setQueryString("recursive=true"); //$NON-NLS-1$
ServerStatus status = HttpUtil.executeMethod(deleteAppMethod);
return status;
} catch (Exception e) {
String msg = NLS.bind("An error occured when performing operation {0}", commandName);
logger.error(msg, e);
return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
}
}