Search in sources :

Example 76 with JsonParseException

use of com.fasterxml.jackson.core.JsonParseException 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 77 with JsonParseException

use of com.fasterxml.jackson.core.JsonParseException 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 78 with JsonParseException

use of com.fasterxml.jackson.core.JsonParseException 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)

Example 79 with JsonParseException

use of com.fasterxml.jackson.core.JsonParseException in project dhis2-core by dhis2.

the class DefaultAppManager method installApp.

@Override
public AppStatus installApp(File file, String fileName) {
    try {
        // -----------------------------------------------------------------
        // Parse ZIP file and it's manifest.webapp file.
        // -----------------------------------------------------------------
        ZipFile zip = new ZipFile(file);
        ZipEntry entry = zip.getEntry(MANIFEST_FILENAME);
        InputStream inputStream = zip.getInputStream(entry);
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        App app = mapper.readValue(inputStream, App.class);
        // -----------------------------------------------------------------
        // Check for namespace and if it's already taken by another app
        // -----------------------------------------------------------------
        String namespace = app.getActivities().getDhis().getNamespace();
        if (namespace != null && (this.appNamespaces.containsKey(namespace) && !app.equals(appNamespaces.get(namespace)))) {
            zip.close();
            return AppStatus.NAMESPACE_TAKEN;
        }
        // -----------------------------------------------------------------
        // Delete if app is already installed, assuming app update so no 
        // data is deleted
        // -----------------------------------------------------------------
        deleteApp(app.getName(), false);
        // -----------------------------------------------------------------
        // Unzip the app
        // -----------------------------------------------------------------
        log.info("Installing app, namespace: " + namespace);
        String dest = getAppFolderPath() + File.separator + fileName.substring(0, fileName.lastIndexOf('.'));
        Unzip unzip = new Unzip();
        unzip.setSrc(file);
        unzip.setDest(new File(dest));
        unzip.execute();
        log.info("Installed app: " + app);
        // -----------------------------------------------------------------
        // Installation complete. Closing zip, reloading apps and return OK
        // -----------------------------------------------------------------
        zip.close();
        reloadApps();
        return AppStatus.OK;
    } catch (ZipException e) {
        return AppStatus.INVALID_ZIP_FORMAT;
    } catch (JsonParseException e) {
        return AppStatus.INVALID_MANIFEST_JSON;
    } catch (JsonMappingException e) {
        return AppStatus.INVALID_MANIFEST_JSON;
    } catch (IOException e) {
        return AppStatus.INSTALLATION_FAILED;
    }
}
Also used : ZipFile(java.util.zip.ZipFile) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Unzip(org.apache.ant.compress.taskdefs.Unzip) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ZipFile(java.util.zip.ZipFile) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 80 with JsonParseException

use of com.fasterxml.jackson.core.JsonParseException in project irontest by zheng-wang.

the class JSONEqualAssertionVerifier method _verify.

/**
 * @param assertion
 * @param input the JSON string that the assertion is verified against
 * @return
 */
@Override
public AssertionVerificationResult _verify(Assertion assertion, Object input) {
    JSONEqualAssertionProperties assertionProperties = (JSONEqualAssertionProperties) assertion.getOtherProperties();
    // validate arguments
    if (assertionProperties.getExpectedJSON() == null) {
        throw new IllegalArgumentException("Expected JSON is null.");
    } else if (input == null) {
        throw new IllegalArgumentException("Actual JSON is null.");
    }
    String expectedJSON = assertionProperties.getExpectedJSON().replaceAll(JSON_UNIT_PLACEHOLDER_REGEX, JSON_UNIT_PLACEHOLDER_DELIMITER_REPLACEMENT);
    MessageEqualAssertionVerificationResult result = new MessageEqualAssertionVerificationResult();
    try {
        assertJsonEquals(expectedJSON, input);
    } catch (IllegalArgumentException e) {
        Throwable c = e.getCause();
        if (c instanceof JsonParseException) {
            throw new IllegalArgumentException(e.getMessage() + " " + c.getMessage());
        } else {
            throw e;
        }
    } catch (AssertionError ae) {
        result.setDifferences(ae.getMessage());
    }
    if (result.getDifferences() == null) {
        result.setResult(TestResult.PASSED);
    } else {
        result.setResult(TestResult.FAILED);
    }
    return result;
}
Also used : JSONEqualAssertionProperties(io.irontest.models.assertion.JSONEqualAssertionProperties) JsonParseException(com.fasterxml.jackson.core.JsonParseException) MessageEqualAssertionVerificationResult(io.irontest.models.assertion.MessageEqualAssertionVerificationResult)

Aggregations

JsonParseException (com.fasterxml.jackson.core.JsonParseException)143 IOException (java.io.IOException)73 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)58 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)35 JsonParser (com.fasterxml.jackson.core.JsonParser)23 JsonNode (com.fasterxml.jackson.databind.JsonNode)18 Map (java.util.Map)18 JsonToken (com.fasterxml.jackson.core.JsonToken)15 InputStream (java.io.InputStream)15 ArrayList (java.util.ArrayList)14 Test (org.junit.Test)14 File (java.io.File)11 HashMap (java.util.HashMap)11 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 JsonFactory (com.fasterxml.jackson.core.JsonFactory)7 JsonLocation (com.fasterxml.jackson.core.JsonLocation)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 InputStreamReader (java.io.InputStreamReader)5 Date (java.util.Date)5 GZIPInputStream (java.util.zip.GZIPInputStream)5