GetMethod getRoutesMethod = new GetMethod(routesURI.toString());
HttpUtil.configureHttpMethod(getRoutesMethod, target);
getRoutesMethod.setQueryString("inline-relations-depth=1"); //$NON-NLS-1$
ServerStatus getRouteStatus = HttpUtil.executeMethod(getRoutesMethod);
if (!getRouteStatus.isOK())
return getRouteStatus;
/* extract available routes */
JSONObject routesJSON = getRouteStatus.getJsonData();
if (routesJSON.getInt(CFProtocolConstants.V2_KEY_TOTAL_RESULTS) < 1) {
return new ServerStatus(IStatus.OK, HttpServletResponse.SC_OK, null, null);
}
JSONObject result = new JSONObject();
routes = new ArrayList<Route>();
JSONArray resources = routesJSON.getJSONArray(CFProtocolConstants.V2_KEY_RESOURCES);
for (int k = 0; k < resources.length(); ++k) {
JSONObject routeJSON = resources.getJSONObject(k);
Route route = new Route();
route.setCFJSON(routeJSON);
if (domainName == null || (domainName.equals(route.getDomainName()) && (hostName == null || hostName.equals(route.getHost())))) {
if (!orphaned || route.getCFJSON().getJSONObject(CFProtocolConstants.V2_KEY_ENTITY).getJSONArray(CFProtocolConstants.V2_KEY_APPS).length() == 0) {
routes.add(route);
result.append("Routes", route.toJSON());
}
}
}
return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, result);
} catch (Exception e) {
String msg = NLS.bind("An error occured when performing operation {0}", commandName); //$NON-NLS-1$
logger.error(msg, e);
return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
}
}