use of org.codehaus.jackson.node.ObjectNode in project exhibitor by soabase.
the class ClusterResource method makeRemoteRequest.
private String makeRemoteRequest(String methodName, String hostname, boolean responseIsJson, Callable<String> proc, Object... values) throws Exception {
String remoteResponse;
String errorMessage;
if (hostname.equals("localhost") || hostname.equals(context.getExhibitor().getThisJVMHostname())) {
remoteResponse = proc.call();
errorMessage = "";
} else {
try {
RemoteInstanceRequest request = new RemoteInstanceRequest(context.getExhibitor(), hostname);
RemoteInstanceRequest.Result result = request.makeRequest(context.getExhibitor().getRemoteInstanceRequestClient(), methodName, values);
remoteResponse = result.remoteResponse;
errorMessage = result.errorMessage;
} catch (Exception e) {
remoteResponse = "{}";
errorMessage = e.getMessage();
if (errorMessage == null) {
errorMessage = "Unknown";
}
}
}
ObjectMapper mapper = new ObjectMapper();
ObjectNode node = JsonNodeFactory.instance.objectNode();
if (responseIsJson) {
node.put("response", mapper.readTree(mapper.getJsonFactory().createJsonParser(remoteResponse)));
} else {
node.put("response", remoteResponse);
}
node.put("errorMessage", errorMessage);
node.put("success", errorMessage.length() == 0);
return JsonUtil.writeValueAsString(node);
}
use of org.codehaus.jackson.node.ObjectNode in project exhibitor by soabase.
the class ClusterResource method getClusterAsJson.
@Path("list")
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getClusterAsJson() throws Exception {
InstanceConfig config = context.getExhibitor().getConfigManager().getConfig();
ObjectNode node = JsonNodeFactory.instance.objectNode();
ArrayNode serversNode = JsonNodeFactory.instance.arrayNode();
ServerList serverList = new ServerList(config.getString(StringConfigs.SERVERS_SPEC));
for (ServerSpec spec : serverList.getSpecs()) {
serversNode.add(spec.getHostname());
}
node.put("servers", serversNode);
node.put("port", config.getInt(IntConfigs.CLIENT_PORT));
return JsonUtil.writeValueAsString(node);
}
use of org.codehaus.jackson.node.ObjectNode in project modules.playframework.org by playframework.
the class FeaturedModules method delete.
public static Result delete() {
Map<String, String[]> postParams = request().body().asFormUrlEncoded();
String[] ids = postParams.get("id");
Result result;
if (ids.length != 1) {
result = badRequest("A featured module must be defined");
} else {
FeaturedModule featuredModule = FeaturedModule.FIND.byId(Long.parseLong(ids[0]));
featuredModule.delete();
ObjectNode node = Json.newObject();
node.put("id", featuredModule.id);
result = ok(node);
}
return result;
}
use of org.codehaus.jackson.node.ObjectNode in project pinot by linkedin.
the class IngraphMetricConfigResource method viewMetricConfig.
@GET
@Path("/list")
@Produces(MediaType.APPLICATION_JSON)
public String viewMetricConfig(@NotNull @QueryParam("dashboardName") String dashboardName, @DefaultValue("0") @QueryParam("jtStartIndex") int jtStartIndex, @DefaultValue("100") @QueryParam("jtPageSize") int jtPageSize) {
List<IngraphMetricConfigDTO> ingraphMetricConfigDTOs = ingraphMetricConfigDao.findByDashboard(dashboardName);
List<IngraphMetricConfigDTO> subList = Utils.sublist(ingraphMetricConfigDTOs, jtStartIndex, jtPageSize);
ObjectNode rootNode = JsonResponseUtil.buildResponseJSON(subList);
return rootNode.toString();
}
use of org.codehaus.jackson.node.ObjectNode in project pinot by linkedin.
the class MetricConfigResource method viewMetricConfig.
@GET
@Path("/list")
@Produces(MediaType.APPLICATION_JSON)
public String viewMetricConfig(@NotNull @QueryParam("dataset") String dataset, @DefaultValue("0") @QueryParam("jtStartIndex") int jtStartIndex, @DefaultValue("100") @QueryParam("jtPageSize") int jtPageSize) {
Map<String, Object> filters = new HashMap<>();
filters.put("dataset", dataset);
List<MetricConfigDTO> metricConfigDTOs = metricConfigDao.findByParams(filters);
List<MetricConfigDTO> subList = Utils.sublist(metricConfigDTOs, jtStartIndex, jtPageSize);
ObjectNode rootNode = JsonResponseUtil.buildResponseJSON(subList);
return rootNode.toString();
}
Aggregations