use of com.fasterxml.jackson.core.JacksonException in project ksan by infinistor.
the class DeleteObjects method process.
@Override
public void process() throws GWException {
logger.info(GWConstants.LOG_DELETE_OBJECTS_START);
String bucket = s3Parameter.getBucketName();
initBucketInfo(bucket);
S3Bucket s3Bucket = new S3Bucket();
s3Bucket.setCors(getBucketInfo().getCors());
s3Bucket.setAccess(getBucketInfo().getAccess());
s3Parameter.setBucket(s3Bucket);
GWUtils.checkCors(s3Parameter);
if (s3Parameter.isPublicAccess() && GWUtils.isIgnorePublicAcls(s3Parameter)) {
throw new GWException(GWErrorCode.ACCESS_DENIED, s3Parameter);
}
checkGrantBucketOwner(s3Parameter.isPublicAccess(), String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_WRITE);
DataDeleteObjects dataDeleteObjects = new DataDeleteObjects(s3Parameter);
dataDeleteObjects.extract();
String deleteXml = dataDeleteObjects.getDeleteXml();
XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
try {
DeleteMultipleObjectsRequest deleteMultipleObjectsRequest = new XmlMapper().readValue(deleteXml, DeleteMultipleObjectsRequest.class);
Collection<Objects> objectNames = new ArrayList<>();
if (deleteMultipleObjectsRequest.objects != null) {
for (DeleteMultipleObjectsRequest.S3Object s3Object : deleteMultipleObjectsRequest.objects) {
Objects object = new Objects();
object.objectName = s3Object.key;
if (Strings.isNullOrEmpty(s3Object.versionId)) {
object.versionId = GWConstants.VERSIONING_DISABLE_TAIL;
} else if (GWConstants.VERSIONING_DISABLE_TAIL.equalsIgnoreCase(s3Object.versionId)) {
object.versionId = GWConstants.VERSIONING_DISABLE_TAIL;
} else {
object.versionId = s3Object.versionId;
}
objectNames.add(object);
}
}
Writer writer = s3Parameter.getResponse().getWriter();
s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
XMLStreamWriter xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(writer);
xmlStreamWriter.writeStartDocument();
xmlStreamWriter.writeStartElement(GWConstants.DELETE_RESULT);
xmlStreamWriter.writeDefaultNamespace(GWConstants.AWS_XMLNS);
logger.debug(GWConstants.LOG_DELETE_OBJECTS_SIZE, objectNames.size());
for (Objects object : objectNames) {
deleteObject(s3Parameter, object.objectName, object.versionId, xmlStreamWriter, deleteMultipleObjectsRequest.quiet);
// xmlStreamWriter.flush(); // In Tomcat, if you use flush(), you lose connection. jakarta, need to check
}
xmlStreamWriter.writeEndElement();
xmlStreamWriter.flush();
} catch (JsonParseException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
} catch (JacksonException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
} catch (IOException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
} catch (XMLStreamException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
use of com.fasterxml.jackson.core.JacksonException in project briar by briar.
the class MailboxApiImpl method getContacts.
@Override
public Collection<ContactId> getContacts(MailboxProperties properties) throws IOException, ApiException {
if (!properties.isOwner())
throw new IllegalArgumentException();
Response response = sendGetRequest(properties, "/contacts");
if (response.code() != 200)
throw new ApiException();
ResponseBody body = response.body();
if (body == null)
throw new ApiException();
try {
JsonNode node = mapper.readTree(body.string());
ArrayNode contactsNode = getArray(node, "contacts");
List<ContactId> list = new ArrayList<>();
for (JsonNode contactNode : contactsNode) {
if (!contactNode.isNumber())
throw new ApiException();
int id = contactNode.intValue();
if (id < 1)
throw new ApiException();
list.add(new ContactId(id));
}
return list;
} catch (JacksonException e) {
throw new ApiException();
}
}
use of com.fasterxml.jackson.core.JacksonException in project briar by briar.
the class MailboxApiImpl method getFiles.
@Override
public List<MailboxFile> getFiles(MailboxProperties properties, MailboxFolderId folderId) throws IOException, ApiException {
String path = "/files/" + folderId;
Response response = sendGetRequest(properties, path);
if (response.code() != 200)
throw new ApiException();
ResponseBody body = response.body();
if (body == null)
throw new ApiException();
try {
JsonNode node = mapper.readTree(body.string());
ArrayNode filesNode = getArray(node, "files");
List<MailboxFile> list = new ArrayList<>();
for (JsonNode fileNode : filesNode) {
if (!fileNode.isObject())
throw new ApiException();
ObjectNode objectNode = (ObjectNode) fileNode;
JsonNode nameNode = objectNode.get("name");
JsonNode timeNode = objectNode.get("time");
if (nameNode == null || !nameNode.isTextual()) {
throw new ApiException();
}
if (timeNode == null || !timeNode.isNumber()) {
throw new ApiException();
}
String name = nameNode.asText();
long time = timeNode.asLong();
if (time < 1)
throw new ApiException();
list.add(new MailboxFile(MailboxFileId.fromString(name), time));
}
Collections.sort(list);
return list;
} catch (JacksonException | InvalidMailboxIdException e) {
throw new ApiException();
}
}
use of com.fasterxml.jackson.core.JacksonException in project briar by briar.
the class MailboxApiImpl method getFolders.
@Override
public List<MailboxFolderId> getFolders(MailboxProperties properties) throws IOException, ApiException {
if (!properties.isOwner())
throw new IllegalArgumentException();
Response response = sendGetRequest(properties, "/folders");
if (response.code() != 200)
throw new ApiException();
ResponseBody body = response.body();
if (body == null)
throw new ApiException();
try {
JsonNode node = mapper.readTree(body.string());
ArrayNode filesNode = getArray(node, "folders");
List<MailboxFolderId> list = new ArrayList<>();
for (JsonNode fileNode : filesNode) {
if (!fileNode.isObject())
throw new ApiException();
ObjectNode objectNode = (ObjectNode) fileNode;
JsonNode idNode = objectNode.get("id");
if (idNode == null || !idNode.isTextual()) {
throw new ApiException();
}
String id = idNode.asText();
list.add(MailboxFolderId.fromString(id));
}
return list;
} catch (JacksonException | InvalidMailboxIdException e) {
throw new ApiException();
}
}
use of com.fasterxml.jackson.core.JacksonException in project tracdap by finos.
the class JsonDecoder method decodeChunk.
@Override
protected void decodeChunk(ByteBuf chunk) {
try {
var bytes = new byte[chunk.readableBytes()];
chunk.readBytes(bytes);
parser.feedInput(bytes, 0, bytes.length);
JsonToken token;
while ((token = parser.nextToken()) != JsonToken.NOT_AVAILABLE) parser.acceptToken(token);
} catch (JacksonException e) {
// This exception is a "well-behaved" parse failure, parse location and message should be meaningful
var errorMessage = String.format("JSON decoding failed on line %d: %s", e.getLocation().getLineNr(), e.getOriginalMessage());
log.error(errorMessage, e);
throw new EDataCorruption(errorMessage, e);
} catch (IOException e) {
// Decoders work on a stream of buffers, "real" IO exceptions should not occur
// IO exceptions here indicate parse failures, not file/socket communication errors
// This is likely to be a more "badly-behaved" failure, or at least one that was not anticipated
var errorMessage = "JSON decoding failed, content is garbled: " + e.getMessage();
log.error(errorMessage, e);
throw new EDataCorruption(errorMessage, e);
} catch (Throwable e) {
// Ensure unexpected errors are still reported to the Flow API
log.error("Unexpected error during decoding", e);
throw new EUnexpected(e);
} finally {
chunk.release();
}
}
Aggregations