下面列出了怎么用com.mongodb.MongoGridFSException的API类实例代码及写法,或者点击链接到github查看源代码。
@Path("/get/{fileName}")
@GET
@Produces(MediaType.TEXT_PLAIN)
public Response retrieveFile(@PathParam("fileName") String fileName) {
String result = null;
try {
result = producerTemplate.requestBodyAndHeader("mongodb-gridfs:camelMongoClient?database=test&operation=findOne",
null,
Exchange.FILE_NAME, fileName, String.class);
} catch (Exception e) {
if (e.getCause() instanceof MongoGridFSException) {
return Response.status(404).build();
}
}
return Response.ok().entity(result).build();
}
@SuppressWarnings("squid:S2589")
// False positive: file.getMetadata() can return null
private static final String getContentType(final GridFSFile file) {
final Document metadata = file.getMetadata();
String contentType = null;
if (metadata != null) {
contentType = metadata.getString(CONTENT_TYPE);
}
if (contentType == null) {
try {
contentType = file.getContentType();
} catch (final MongoGridFSException e) {
throw new ArtifactStoreException("Could not determine content type for file " + file.getId(), e);
}
}
return contentType;
}