Search in sources :

Example 51 with JsonParseException

use of com.fasterxml.jackson.core.JsonParseException in project hbase by apache.

the class ScannerResource method update.

Response update(final ScannerModel model, final boolean replace, final UriInfo uriInfo) {
    servlet.getMetrics().incrementRequests(1);
    if (servlet.isReadOnly()) {
        return Response.status(Response.Status.FORBIDDEN).type(MIMETYPE_TEXT).entity("Forbidden" + CRLF).build();
    }
    byte[] endRow = model.hasEndRow() ? model.getEndRow() : null;
    RowSpec spec = null;
    if (model.getLabels() != null) {
        spec = new RowSpec(model.getStartRow(), endRow, model.getColumns(), model.getStartTime(), model.getEndTime(), model.getMaxVersions(), model.getLabels());
    } else {
        spec = new RowSpec(model.getStartRow(), endRow, model.getColumns(), model.getStartTime(), model.getEndTime(), model.getMaxVersions());
    }
    try {
        Filter filter = ScannerResultGenerator.buildFilterFromModel(model);
        String tableName = tableResource.getName();
        ScannerResultGenerator gen = new ScannerResultGenerator(tableName, spec, filter, model.getCaching(), model.getCacheBlocks(), model.getLimit());
        String id = gen.getID();
        ScannerInstanceResource instance = new ScannerInstanceResource(tableName, id, gen, model.getBatch());
        scanners.put(id, instance);
        if (LOG.isTraceEnabled()) {
            LOG.trace("new scanner: " + id);
        }
        UriBuilder builder = uriInfo.getAbsolutePathBuilder();
        URI uri = builder.path(id).build();
        servlet.getMetrics().incrementSucessfulPutRequests(1);
        return Response.created(uri).build();
    } catch (Exception e) {
        LOG.error("Exception occurred while processing " + uriInfo.getAbsolutePath() + " : ", e);
        servlet.getMetrics().incrementFailedPutRequests(1);
        if (e instanceof TableNotFoundException) {
            return Response.status(Response.Status.NOT_FOUND).type(MIMETYPE_TEXT).entity("Not found" + CRLF).build();
        } else if (e instanceof RuntimeException || e instanceof JsonMappingException | e instanceof JsonParseException) {
            return Response.status(Response.Status.BAD_REQUEST).type(MIMETYPE_TEXT).entity("Bad request" + CRLF).build();
        }
        return Response.status(Response.Status.SERVICE_UNAVAILABLE).type(MIMETYPE_TEXT).entity("Unavailable" + CRLF).build();
    }
}
Also used : JsonParseException(com.fasterxml.jackson.core.JsonParseException) URI(java.net.URI) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) Filter(org.apache.hadoop.hbase.filter.Filter) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) UriBuilder(org.apache.hbase.thirdparty.javax.ws.rs.core.UriBuilder)

Example 52 with JsonParseException

use of com.fasterxml.jackson.core.JsonParseException in project openstack4j by ContainX.

the class TelemetryDateDeserializer method deserialize.

@Override
public Date deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    String date = jsonParser.getText();
    SimpleDateFormat sdf = new SimpleDateFormat(MILLIS_DATE_FORMAT);
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    try {
        return sdf.parse(getParseableDate(date));
    } catch (ParseException e) {
        throw new JsonParseException(jsonParser, "Could not process telemetry date", e);
    }
}
Also used : ParseException(java.text.ParseException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 53 with JsonParseException

use of com.fasterxml.jackson.core.JsonParseException in project OpenRefine by OpenRefine.

the class DatabaseUtils method getSavedConnections.

/**
 * GET saved connections
 * @return
 */
public static List<DatabaseConfiguration> getSavedConnections() {
    ObjectMapper mapper = new ObjectMapper();
    try {
        String filename = getExtensionFilePath();
        File file = new File(filename);
        if (!file.exists()) {
            // logger.debug("saved connections file not found, creating new: {}", filename);
            String dirPath = getExtensionFolder();
            File dirFile = new File(dirPath);
            boolean dirExists = true;
            if (!dirFile.exists()) {
                dirExists = dirFile.mkdir();
            }
            if (dirExists) {
                SavedConnectionContainer sc = new SavedConnectionContainer(new ArrayList<DatabaseConfiguration>());
                mapper.writerWithDefaultPrettyPrinter().writeValue(new File(filename), sc);
                return sc.getSavedConnections();
            // return decryptAll(sc.getSavedConnections());
            }
        }
        // logger.debug("saved connections file  found {}", filename);
        SavedConnectionContainer savedConnectionContainer = mapper.readValue(new File(filename), SavedConnectionContainer.class);
        // return decryptAll(savedConnectionContainer.getSavedConnections());
        return savedConnectionContainer.getSavedConnections();
    } catch (JsonParseException e) {
        logger.error("JsonParseException: {}", e);
    } catch (JsonMappingException e) {
        logger.error("JsonMappingException: {}", e);
    } catch (IOException e) {
        logger.error("IOException: {}", e);
    }
    return null;
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 54 with JsonParseException

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

the class JCloudsAppStorageService method installApp.

@Override
public App installApp(File file, String filename, Cache<App> appCache) {
    App app = new App();
    log.info("Installing new app: " + filename);
    try (ZipFile zip = new ZipFile(file)) {
        // -----------------------------------------------------------------
        // Parse ZIP file and it's manifest.webapp file.
        // -----------------------------------------------------------------
        ZipEntry entry = zip.getEntry(MANIFEST_FILENAME);
        if (entry == null) {
            log.error("Failed to install app: Missing manifest.webapp in zip");
            app.setAppState(AppStatus.MISSING_MANIFEST);
            return app;
        }
        InputStream inputStream = zip.getInputStream(entry);
        app = jsonMapper.readValue(inputStream, App.class);
        app.setFolderName(APPS_DIR + File.separator + filename.substring(0, filename.lastIndexOf('.')));
        app.setAppStorageSource(AppStorageSource.JCLOUDS);
        if (!this.validateApp(app, appCache)) {
            return app;
        }
        String namespace = app.getActivities().getDhis().getNamespace();
        // -----------------------------------------------------------------
        // Unzip the app
        // -----------------------------------------------------------------
        String dest = APPS_DIR + File.separator + filename.substring(0, filename.lastIndexOf('.'));
        zip.stream().forEach((Consumer<ZipEntry>) zipEntry -> {
            log.debug("Uploading zipEntry: " + zipEntry);
            try {
                InputStream input = zip.getInputStream(zipEntry);
                Blob blob = blobStore.blobBuilder(dest + File.separator + zipEntry.getName()).payload(input).contentLength(zipEntry.getSize()).build();
                blobStore.putBlob(config.container, blob);
                input.close();
            } catch (IOException e) {
                log.error("Unable to store app file '" + zipEntry.getName() + "'", e);
            }
        });
        log.info(String.format("" + "New app '%s' installed" + "\n\tInstall path: %s" + (namespace != null && !namespace.isEmpty() ? "\n\tNamespace reserved: %s" : ""), app.getName(), dest, namespace));
        // -----------------------------------------------------------------
        // Installation complete.
        // -----------------------------------------------------------------
        app.setAppState(AppStatus.OK);
        return app;
    } catch (ZipException e) {
        log.error("Failed to install app: Invalid ZIP format", e);
        app.setAppState(AppStatus.INVALID_ZIP_FORMAT);
    } catch (JsonParseException e) {
        log.error("Failed to install app: Invalid manifest.webapp", e);
        app.setAppState(AppStatus.INVALID_MANIFEST_JSON);
    } catch (IOException e) {
        log.error("Failed to install app: Could not save app", e);
        app.setAppState(AppStatus.INSTALLATION_FAILED);
    }
    return app;
}
Also used : HttpRequest(org.jclouds.http.HttpRequest) Arrays(java.util.Arrays) ConfigurationKey(org.hisp.dhis.external.conf.ConfigurationKey) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) LocalBlobRequestSigner(org.jclouds.blobstore.LocalBlobRequestSigner) PreDestroy(javax.annotation.PreDestroy) BlobStoreContext(org.jclouds.blobstore.BlobStoreContext) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) Blob(org.jclouds.blobstore.domain.Blob) ZipFile(java.util.zip.ZipFile) URI(java.net.URI) ZipEntry(java.util.zip.ZipEntry) JsonParseException(com.fasterxml.jackson.core.JsonParseException) HttpResponseException(org.jclouds.http.HttpResponseException) Resource(org.springframework.core.io.Resource) Builder.prefix(org.jclouds.blobstore.options.ListContainerOptions.Builder.prefix) ZipException(java.util.zip.ZipException) RequestSigningUnsupported(org.jclouds.blobstore.internal.RequestSigningUnsupported) FileSystemResource(org.springframework.core.io.FileSystemResource) LocationBuilder(org.jclouds.domain.LocationBuilder) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Cache(org.hisp.dhis.cache.Cache) Credentials(org.jclouds.domain.Credentials) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Minutes(org.joda.time.Minutes) LocationManager(org.hisp.dhis.external.location.LocationManager) UrlResource(org.springframework.core.io.UrlResource) HashMap(java.util.HashMap) S3Constants(org.jclouds.s3.reference.S3Constants) Location(org.jclouds.domain.Location) ArrayList(java.util.ArrayList) AuthorizationException(org.jclouds.rest.AuthorizationException) Service(org.springframework.stereotype.Service) Properties(java.util.Properties) BlobStore(org.jclouds.blobstore.BlobStore) DhisConfigurationProvider(org.hisp.dhis.external.conf.DhisConfigurationProvider) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) File(java.io.File) ContextBuilder(org.jclouds.ContextBuilder) Consumer(java.util.function.Consumer) DebugUtils(org.hisp.dhis.commons.util.DebugUtils) BlobRequestSigner(org.jclouds.blobstore.BlobRequestSigner) LocationScope(org.jclouds.domain.LocationScope) FilesystemConstants(org.jclouds.filesystem.reference.FilesystemConstants) StorageMetadata(org.jclouds.blobstore.domain.StorageMetadata) LocationManagerException(org.hisp.dhis.external.location.LocationManagerException) InputStream(java.io.InputStream) Blob(org.jclouds.blobstore.domain.Blob) ZipFile(java.util.zip.ZipFile) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException)

Example 55 with JsonParseException

use of com.fasterxml.jackson.core.JsonParseException in project graphhopper by graphhopper.

the class PathDetailDeserializer method deserialize.

@Override
public PathDetail deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonNode pathDetail = jp.readValueAsTree();
    if (pathDetail.size() != 3)
        throw new JsonParseException(jp, "PathDetail array must have exactly 3 entries but was " + pathDetail.size());
    JsonNode from = pathDetail.get(0);
    JsonNode to = pathDetail.get(1);
    JsonNode val = pathDetail.get(2);
    PathDetail pd;
    if (val.isBoolean())
        pd = new PathDetail(val.asBoolean());
    else if (val.isDouble())
        pd = new PathDetail(val.asDouble());
    else if (val.canConvertToLong())
        pd = new PathDetail(val.asLong());
    else if (val.isTextual())
        pd = new PathDetail(val.asText());
    else
        throw new JsonParseException(jp, "Unsupported type of PathDetail value " + pathDetail.getNodeType().name());
    pd.setFirst(from.asInt());
    pd.setLast(to.asInt());
    return pd;
}
Also used : PathDetail(com.graphhopper.util.details.PathDetail) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonParseException(com.fasterxml.jackson.core.JsonParseException)

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