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();
}
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations