Search in sources :

Example 81 with JsonMappingException

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();
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JFrame(javax.swing.JFrame) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Positionable(jmri.jmrit.display.Positionable) IOException(java.io.IOException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) PanelEditor(jmri.jmrit.display.panelEditor.PanelEditor) IOException(java.io.IOException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Example 82 with JsonMappingException

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);
    }
}
Also used : RiotException(org.apache.jena.riot.RiotException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) JsonLdError(com.github.jsonldjava.core.JsonLdError)

Example 83 with JsonMappingException

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;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 84 with JsonMappingException

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);
    }
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) URISyntaxException(java.net.URISyntaxException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 85 with JsonMappingException

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;
}
Also used : HashMap(java.util.HashMap) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) HttpClient(org.apache.commons.httpclient.HttpClient) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) GetMethod(org.apache.commons.httpclient.methods.GetMethod) HttpClientParams(org.apache.commons.httpclient.params.HttpClientParams) HashMap(java.util.HashMap) Map(java.util.Map) HttpMethod(org.apache.commons.httpclient.HttpMethod) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)140 IOException (java.io.IOException)68 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)54 JsonParseException (com.fasterxml.jackson.core.JsonParseException)52 Test (org.junit.Test)31 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)19 HashMap (java.util.HashMap)16 ArrayList (java.util.ArrayList)14 Map (java.util.Map)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)11 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)10 File (java.io.File)9 InputStream (java.io.InputStream)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 List (java.util.List)7 Writer (org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer)7 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)6 Response (javax.ws.rs.core.Response)6 SimpleFilterProvider (com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)5