use of com.fasterxml.jackson.databind.JsonMappingException in project JMRI by JMRI.
the class PanelServlet method getJsonPanel.
@Override
protected String getJsonPanel(String name) {
log.debug("Getting {} for {}", getPanelType(), name);
try {
PanelEditor editor = (PanelEditor) getEditor(name);
ObjectNode root = this.mapper.createObjectNode();
ObjectNode panel = root.putObject("panel");
JFrame frame = editor.getTargetFrame();
panel.put("name", name);
panel.put("height", frame.getContentPane().getHeight());
panel.put("width", frame.getContentPane().getWidth());
panel.put("panelheight", frame.getContentPane().getHeight());
panel.put("panelwidth", frame.getContentPane().getWidth());
panel.put("showtooltips", editor.showTooltip());
panel.put("controlling", editor.allControlling());
if (editor.getBackgroundColor() != null) {
ObjectNode color = panel.putObject("backgroundColor");
color.put("red", editor.getBackgroundColor().getRed());
color.put("green", editor.getBackgroundColor().getGreen());
color.put("blue", editor.getBackgroundColor().getBlue());
}
// include contents
log.debug("N elements: {}", editor.getContents().size());
for (Positionable sub : editor.getContents()) {
try {
// TODO: get all panel contents as JSON
// I tried using JavaBean Introspection to simply build the contents using Jackson Databindings,
// but when a panel element has a reference to the panel or to itself as a property, this leads
// to infinite recursion
} catch (Exception ex) {
log.error("Error storing panel element: " + ex, ex);
}
}
return this.mapper.writeValueAsString(root);
} catch (NullPointerException ex) {
log.warn("Requested Panel [" + name + "] does not exist.");
return "ERROR Requested panel [" + name + "] does not exist.";
} catch (JsonGenerationException e) {
log.error("Error generating JSON", e);
return "ERROR " + e.getLocalizedMessage();
} catch (JsonMappingException e) {
log.error("Error mapping JSON", e);
return "ERROR " + e.getLocalizedMessage();
} catch (IOException e) {
log.error("IOException", e);
return "ERROR " + e.getLocalizedMessage();
}
}
use of com.fasterxml.jackson.databind.JsonMappingException in project jena by apache.
the class JsonLDWriter method serialize.
private void serialize(Writer writer, DatasetGraph dataset, PrefixMap prefixMap, String baseURI, Context jenaContext) {
try {
Object obj = toJsonLDJavaAPI(getVariant(), dataset, prefixMap, baseURI, jenaContext);
if (getVariant().isPretty()) {
JsonUtils.writePrettyPrint(writer, obj);
} else {
JsonUtils.write(writer, obj);
}
writer.write("\n");
} catch (JsonLdError | JsonMappingException | JsonGenerationException e) {
throw new RiotException(e);
} catch (IOException e) {
IO.exception(e);
}
}
use of com.fasterxml.jackson.databind.JsonMappingException in project asterixdb by apache.
the class TestExecutor method cleanup.
public void cleanup(String testCase, List<String> badtestcases) throws Exception {
try {
ArrayList<String> toBeDropped = new ArrayList<>();
InputStream resultStream = executeQueryService("select dv.DataverseName from Metadata.`Dataverse` as dv;", getEndpoint(Servlets.QUERY_SERVICE), OutputFormat.CLEAN_JSON);
String out = IOUtils.toString(resultStream);
ObjectMapper om = new ObjectMapper();
om.setConfig(om.getDeserializationConfig().with(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT));
JsonNode result;
try {
result = om.readValue(out, ObjectNode.class).get("results");
} catch (JsonMappingException e) {
result = om.createArrayNode();
}
for (int i = 0; i < result.size(); i++) {
JsonNode json = result.get(i);
if (json != null) {
String dvName = json.get("DataverseName").asText();
if (!dvName.equals("Metadata") && !dvName.equals("Default")) {
toBeDropped.add(dvName);
}
}
}
if (!toBeDropped.isEmpty()) {
badtestcases.add(testCase);
LOGGER.warning("Last test left some garbage. Dropping dataverses: " + StringUtils.join(toBeDropped, ','));
StringBuilder dropStatement = new StringBuilder();
for (String dv : toBeDropped) {
dropStatement.append("drop dataverse ");
dropStatement.append(dv);
dropStatement.append(";\n");
}
resultStream = executeQueryService(dropStatement.toString(), getEndpoint(Servlets.QUERY_SERVICE), OutputFormat.CLEAN_JSON);
ResultExtractor.extract(resultStream);
}
} catch (Throwable th) {
th.printStackTrace();
throw th;
}
}
use of com.fasterxml.jackson.databind.JsonMappingException in project hadoop by apache.
the class RemoteAuthorizerResponse method authorize.
@Override
public boolean authorize(String wasbAbsolutePath, String accessType, String delegationToken) throws WasbAuthorizationException, IOException {
try {
URIBuilder uriBuilder = new URIBuilder(remoteAuthorizerServiceUrl);
uriBuilder.setPath("/" + CHECK_AUTHORIZATION_OP);
uriBuilder.addParameter(WASB_ABSOLUTE_PATH_QUERY_PARAM_NAME, wasbAbsolutePath);
uriBuilder.addParameter(ACCESS_OPERATION_QUERY_PARAM_NAME, accessType);
uriBuilder.addParameter(DELEGATION_TOKEN_QUERY_PARAM_NAME, delegationToken);
String responseBody = remoteCallHelper.makeRemoteGetRequest(new HttpGet(uriBuilder.build()));
ObjectMapper objectMapper = new ObjectMapper();
RemoteAuthorizerResponse authorizerResponse = objectMapper.readValue(responseBody, RemoteAuthorizerResponse.class);
if (authorizerResponse == null) {
throw new WasbAuthorizationException("RemoteAuthorizerResponse object null from remote call");
} else if (authorizerResponse.getResponseCode() == REMOTE_CALL_SUCCESS_CODE) {
return authorizerResponse.getAuthorizationResult();
} else {
throw new WasbAuthorizationException("Remote authorization" + " service encountered an error " + authorizerResponse.getResponseMessage());
}
} catch (URISyntaxException | WasbRemoteCallException | JsonParseException | JsonMappingException ex) {
throw new WasbAuthorizationException(ex);
}
}
use of com.fasterxml.jackson.databind.JsonMappingException in project bamboobsc by billchen198318.
the class ApplicationSiteUtils method checkTestConnection.
private static boolean checkTestConnection(String host, String contextPath, HttpServletRequest request) {
boolean test = false;
String basePath = request.getScheme() + "://" + host + "/" + contextPath;
String urlStr = basePath + "/pages/system/testJsonResult.action";
try {
logger.info("checkTestConnection , url=" + urlStr);
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(urlStr);
HttpClientParams params = new HttpClientParams();
params.setConnectionManagerTimeout(TEST_JSON_HTTP_TIMEOUT);
client.setParams(params);
client.executeMethod(method);
byte[] responseBody = method.getResponseBody();
if (null == responseBody) {
test = false;
return test;
}
String content = new String(responseBody, Constants.BASE_ENCODING);
ObjectMapper mapper = new ObjectMapper();
@SuppressWarnings("unchecked") Map<String, Object> dataMap = (Map<String, Object>) mapper.readValue(content, HashMap.class);
if (YesNo.YES.equals(dataMap.get("success"))) {
test = true;
}
} catch (JsonParseException e) {
logger.error(e.getMessage().toString());
} catch (JsonMappingException e) {
logger.error(e.getMessage().toString());
} catch (Exception e) {
e.printStackTrace();
} finally {
if (!test) {
logger.warn("checkTestConnection : " + String.valueOf(test));
} else {
logger.info("checkTestConnection : " + String.valueOf(test));
}
}
return test;
}
Aggregations