@Override public HttpResponse handle(SecurityService securityService, HttpApiRequest request) { if (!HttpConstants.METHOD_GET.equals(request.getMethod())) return new HttpResponse(HttpURLConnection.HTTP_BAD_METHOD, HttpConstants.MIME_TEXT_PLAIN, "Expected GET method"); if (request.getUri().equals(apiUri + "/metrics")) return onMessageGetMetricList(securityService); if (request.getUri().startsWith(apiUri + "/metrics")) { String rest = request.getUri().substring(apiUri.length() + "/metrics".length() + 1); if (rest.isEmpty()) return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND); int index = rest.indexOf("/"); String metricId = URIUtils.decodeComponent(index > 0 ? rest.substring(0, index) : rest); if (index < 0) return onMessageGetMetric(securityService, metricId); else if (rest.substring(index).equals("/snapshot")) return onMessageGetMetricValue(securityService, metricId); } return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND); }
@Override public String[] getParameterAll(String name) { return URIUtils.getMultiParameters(request.getParameterValues(name)); }
/** * Registers a web contribution * * @param contribution The web contribution to register */ private void register(WebUIContribution contribution) { List<String> segments = URIUtils.getSegments(contribution.getPrefix()); Folder current = root; for (int i = 0; i != segments.size(); i++) { String name = segments.get(i); if (name.isEmpty() && i == segments.size() - 1) // last segment is empty, break here break; Folder child = current.subs.get(name); if (child == null) { child = new Folder(); current.subs.put(name, child); } current = child; } current.contributions.add(contribution); }
@Override public String getParameter(String name) { return URIUtils.getSingleParameter(request.getParameterValues(name)); }
@Override public HttpResponse handle(SecurityService securityService, HttpApiRequest request) { if (!HttpConstants.METHOD_GET.equals(request.getMethod())) return new HttpResponse(HttpURLConnection.HTTP_BAD_METHOD, HttpConstants.MIME_TEXT_PLAIN, "Expected GET method"); if (request.getUri().equals(apiUri + "/archetypes")) { return onGetArchetypes(); } else if (request.getUri().equals(apiUri + "/schemas")) { return onGetSchemas(); } else if (request.getUri().startsWith(apiUri + "/archetypes")) { String rest = URIUtils.decodeComponent(request.getUri().substring(apiUri.length() + "/archetypes".length() + 1)); if (rest.isEmpty()) return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND); return onGetArchetype(rest); } else if (request.getUri().startsWith(apiUri + "/schemas")) { String rest = URIUtils.decodeComponent(request.getUri().substring(apiUri.length() + "/schemas".length() + 1)); if (rest.isEmpty()) return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND); return onGetSchema(rest); } return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND); }
/** * Gets the resource URL for the requested uri * * @param uri The uri of a resource * @return The corresponding URL, or null if there is none */ private URL doGetResource(String uri) { if (uri.endsWith("/")) uri += "index.html"; List<String> segments = URIUtils.getSegments(uri); if (contributions == null) { synchronized (this) { if (contributions == null) { contributions = Register.getComponents(WebUIContribution.class); for (WebUIContribution contribution : contributions) register(contribution); } } } return doGetResource(root, segments, 0, uri); }
if (!rest.startsWith("/")) return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND); String artifactId = URIUtils.decodeComponent(rest.substring(1)); if (artifactId.isEmpty()) return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND);
if (!rest.startsWith("/")) return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND); String artifactId = URIUtils.decodeComponent(rest.substring(1)); if (artifactId.isEmpty()) return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND);
/** * Responds to a request for the policy resource * * @param request The web API request to handle * @return The HTTP response */ private HttpResponse handleRequestPolicy(HttpApiRequest request) { if (request.getUri().equals(apiUri + "/policy")) { if (!HttpConstants.METHOD_GET.equals(request.getMethod())) return new HttpResponse(HttpURLConnection.HTTP_BAD_METHOD, HttpConstants.MIME_TEXT_PLAIN, "Expected GET method"); return XSPReplyUtils.toHttpResponse(getPolicy().getConfiguration(), null); } if (request.getUri().startsWith(apiUri + "/policy/actions/")) { String rest = request.getUri().substring(apiUri.length() + "/policy/actions/".length()); String actionId = URIUtils.decodeComponent(rest); if (actionId.isEmpty()) return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND); if (!HttpConstants.METHOD_PUT.equals(request.getMethod())) return new HttpResponse(HttpURLConnection.HTTP_BAD_METHOD, HttpConstants.MIME_TEXT_PLAIN, "Expected PUT method"); String definition = new String(request.getContent(), IOUtils.CHARSET); return XSPReplyUtils.toHttpResponse(getPolicy().setPolicy(actionId, definition), null); } return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND); }
return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND); int index = rest.indexOf("/"); String jobId = URIUtils.decodeComponent(index > 0 ? rest.substring(0, index) : rest); if (index < 0) { if (!HttpConstants.METHOD_GET.equals(request.getMethod()))
String neighbourId = URIUtils.decodeComponent(index > 0 ? rest.substring(0, index) : rest); return handleNeighbour(request, neighbourId, index > 0 ? rest.substring(index + 1) : "");
String specId = URIUtils.decodeComponent(index > 0 ? rest.substring(0, index) : rest); if (specId.isEmpty()) return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND);
String specId = URIUtils.decodeComponent(index > 0 ? rest.substring(0, index) : rest); if (specId.isEmpty()) return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND);
String specId = URIUtils.decodeComponent(rest); return XSPReplyUtils.toHttpResponse(getNeighbourInputsFor(neighbourId, specId), null); String specId = URIUtils.decodeComponent(rest); return XSPReplyUtils.toHttpResponse(getNeighbourOutputsFor(neighbourId, specId), null);
return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND); int index = rest.indexOf("/"); String connectorId = URIUtils.decodeComponent(index > 0 ? rest.substring(0, index) : rest); if (index < 0) { switch (request.getMethod()) {
String roleId = URIUtils.decodeComponent(rest.substring(1)); switch (request.getMethod()) { case HttpConstants.METHOD_DELETE:
return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND); int index = rest.indexOf("/"); String addonId = URIUtils.decodeComponent(index > 0 ? rest.substring(0, index) : rest); if (index >= 0) return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND);
return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND); int index = rest.indexOf("/"); String roleId = URIUtils.decodeComponent(index > 0 ? rest.substring(0, index) : rest);
return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND); int index = rest.indexOf("/"); String ruleId = URIUtils.decodeComponent(index > 0 ? rest.substring(0, index) : rest); if (index < 0) { switch (request.getMethod()) {
return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND); int index = rest.indexOf("/"); String userId = URIUtils.decodeComponent(index > 0 ? rest.substring(0, index) : rest);