use of au.gov.asd.tac.constellation.webserver.restapi.RestServiceUtilities.HttpMethod in project constellation by constellation-app.
the class GetServiceDescription method callService.
@Override
public void callService(final PluginParameters parameters, InputStream in, OutputStream out) throws IOException {
final String serviceName = parameters.getStringValue(SERVICE_NAME_PARAMETER_ID);
final HttpMethod httpMethod = HttpMethod.getValue(parameters.getStringValue(METHOD_NAME_PARAMETER_ID));
try {
final ObjectMapper mapper = new ObjectMapper();
final ObjectNode root = mapper.createObjectNode();
final RestService rs = RestServiceRegistry.get(serviceName, httpMethod);
root.put("name", rs.getName());
root.put("http_method", httpMethod.name());
root.put("description", rs.getDescription());
root.put("mimetype", rs.getMimeType());
final ArrayNode tags = root.putArray("tags");
for (final String tag : rs.getTags()) {
tags.add(tag);
}
final ObjectNode params = root.putObject("parameters");
rs.createParameters().getParameters().entrySet().forEach(entry -> {
final PluginParameter<?> pp = entry.getValue();
final ObjectNode param = params.putObject(entry.getKey());
param.put("name", pp.getName());
param.put("type", pp.getType().getId());
param.put("description", pp.getDescription());
if (pp.getObjectValue() != null) {
param.put("value", pp.getObjectValue().toString());
}
});
mapper.writeValue(out, root);
} catch (final IllegalArgumentException ex) {
throw new RestServiceException(HTTP_UNPROCESSABLE_ENTITY, ex.getMessage());
}
}
use of au.gov.asd.tac.constellation.webserver.restapi.RestServiceUtilities.HttpMethod in project constellation by constellation-app.
the class FileListener method parseAndExecute.
/**
* Execute a REST endpoint.
*
* @param node A JSON node representing the input parameters.
*
* @throws Exception because of AutoCloseable
*/
private void parseAndExecute(final String verb, final String endpoint, final String path, final JsonNode args) throws Exception {
if ("/v2/service".equals(endpoint)) {
final HttpMethod httpMethod = HttpMethod.getValue(verb);
// Get an instance of the service (if it exists).
//
final RestService rs = RestServiceRegistry.get(path, httpMethod);
// Convert the arguments to PluginParameters.
//
final PluginParameters parameters = rs.createParameters();
RestServiceUtilities.parametersFromJson((ObjectNode) args, parameters);
try (final InStream ins = new InStream(restPath, CONTENT_IN, true);
final OutputStream out = outStream(restPath, CONTENT_OUT)) {
rs.callService(parameters, ins.in, out);
} catch (final IOException | RuntimeException ex) {
throw new RestServiceException(ex);
}
} else {
unrec(ENDPOINT, endpoint);
}
}
Aggregations