Search in sources :

Example 86 with JsonMappingException

use of org.apache.flink.shaded.jackson2.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 87 with JsonMappingException

use of org.apache.flink.shaded.jackson2.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 88 with JsonMappingException

use of org.apache.flink.shaded.jackson2.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)

Example 89 with JsonMappingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project cas by apereo.

the class X509CertificateCredentialJsonSerializer method serializeWithType.

@Override
public void serializeWithType(final X509CertificateCredential value, final JsonGenerator generator, final SerializerProvider serializers, final TypeSerializer typeSer) throws IOException {
    try {
        typeSer.writeTypePrefixForObject(value, generator);
        serialize(value, generator, serializers);
        typeSer.writeTypeSuffixForObject(value, generator);
    } catch (final Exception e) {
        throw new JsonMappingException("Unable to serialize X509 certificate", e);
    }
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Example 90 with JsonMappingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project dhis2-core by dhis2.

the class GeoUtils method parseCoordinates.

public static Coordinates parseCoordinates(String coordinatesString, CoordinateOrder from) {
    Coordinates coordinates = new Coordinates();
    try {
        List<?> list = new ObjectMapper().readValue(coordinatesString, List.class);
        if (!list.isEmpty() && from == CoordinateOrder.COORDINATE_LATLNG) {
            coordinates.lat = convertToDouble(list.get(0));
            coordinates.lng = convertToDouble(list.get(1));
        } else if (!list.isEmpty() && from == CoordinateOrder.COORDINATE_LNGLAT) {
            coordinates.lat = convertToDouble(list.get(1));
            coordinates.lng = convertToDouble(list.get(0));
        }
    } catch (JsonMappingException ignored) {
    } catch (JsonParseException ignored) {
    } catch (IOException ignored) {
    }
    return coordinates;
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)185 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)93 IOException (java.io.IOException)80 JsonParseException (com.fasterxml.jackson.core.JsonParseException)57 Test (org.junit.Test)45 ATTest (org.jboss.eap.additional.testsuite.annotations.ATTest)33 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)24 ArrayList (java.util.ArrayList)16 Map (java.util.Map)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 File (java.io.File)15 HashMap (java.util.HashMap)15 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)13 InputStream (java.io.InputStream)11 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 List (java.util.List)8 Writer (org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer)7 Test (org.junit.jupiter.api.Test)6