use of org.geowebcache.mime.MimeException in project geowebcache by GeoWebCache.
the class S3BlobStore method put.
@Override
public void put(TileObject obj) throws StorageException {
final Resource blob = obj.getBlob();
checkNotNull(blob);
checkNotNull(obj.getBlobFormat());
final String key = keyBuilder.forTile(obj);
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(blob.getSize());
String blobFormat = obj.getBlobFormat();
String mimeType;
try {
mimeType = MimeType.createFromFormat(blobFormat).getMimeType();
} catch (MimeException me) {
throw new RuntimeException(me);
}
objectMetadata.setContentType(mimeType);
// don't bother for the extra call if there are no listeners
final boolean existed;
ObjectMetadata oldObj;
if (listeners.isEmpty()) {
existed = false;
oldObj = null;
} else {
oldObj = s3Ops.getObjectMetadata(key);
existed = oldObj != null;
}
final ByteArrayInputStream input = toByteArray(blob);
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, input, objectMetadata).withCannedAcl(acl);
log.trace(log.isTraceEnabled() ? ("Storing " + key) : "");
s3Ops.putObject(putObjectRequest);
putParametersMetadata(obj.getLayerName(), obj.getParametersId(), obj.getParameters());
/*
* This is important because listeners may be tracking tile existence
*/
if (!listeners.isEmpty()) {
if (existed) {
long oldSize = oldObj.getContentLength();
listeners.sendTileUpdated(obj, oldSize);
} else {
listeners.sendTileStored(obj);
}
}
}
use of org.geowebcache.mime.MimeException in project geowebcache by GeoWebCache.
the class AzureBlobStore method put.
@Override
public void put(TileObject obj) throws StorageException {
final Resource blob = obj.getBlob();
checkNotNull(blob);
checkNotNull(obj.getBlobFormat());
final String key = keyBuilder.forTile(obj);
BlockBlobURL blobURL = client.getBlockBlobURL(key);
// if there are listeners, gather first the old size with a "head" request
Long oldSize = null;
boolean existed = false;
if (!listeners.isEmpty()) {
try {
BlobGetPropertiesResponse properties = blobURL.getProperties().blockingGet();
oldSize = properties.headers().contentLength();
existed = true;
} catch (RestException e) {
if (e.response().statusCode() != HttpStatus.NOT_FOUND.value()) {
throw new StorageException("Failed to check if the container exists", e);
}
}
}
// then upload
try (InputStream is = blob.getInputStream()) {
byte[] bytes = IOUtils.toByteArray(is);
ByteBuffer buffer = ByteBuffer.wrap(bytes);
String mimeType = MimeType.createFromFormat(obj.getBlobFormat()).getMimeType();
BlobHTTPHeaders headers = new BlobHTTPHeaders().withBlobContentType(mimeType);
int status = blobURL.upload(Flowable.just(buffer), bytes.length, headers, null, null, null).blockingGet().statusCode();
if (!HttpStatus.valueOf(status).is2xxSuccessful()) {
throw new StorageException("Failed to upload tile to Azure on container " + client.getContainerName() + " and key " + key + " got HTTP status " + status);
}
} catch (RestException | IOException | MimeException e) {
throw new StorageException("Failed to upload tile to Azure on container " + client.getContainerName() + " and key " + key, e);
}
// along with the metadata
putParametersMetadata(obj.getLayerName(), obj.getParametersId(), obj.getParameters());
// This is important because listeners may be tracking tile existence
if (!listeners.isEmpty()) {
if (existed) {
listeners.sendTileUpdated(obj, oldSize);
} else {
listeners.sendTileStored(obj);
}
}
}
use of org.geowebcache.mime.MimeException in project geowebcache by GeoWebCache.
the class ArcGISCacheLayer method loadMimeTypes.
private List<MimeType> loadMimeTypes() {
String cacheTileFormat = this.cacheInfo.getTileImageInfo().getCacheTileFormat();
if ("mixed".equalsIgnoreCase(cacheTileFormat) || "jpg".equalsIgnoreCase(cacheTileFormat)) {
cacheTileFormat = "JPEG";
} else if (cacheTileFormat.toLowerCase().startsWith("png")) {
cacheTileFormat = "png";
}
cacheTileFormat = "image/" + cacheTileFormat.toLowerCase();
MimeType format;
try {
format = MimeType.createFromFormat(cacheTileFormat);
} catch (MimeException e) {
throw new RuntimeException(e);
}
return Collections.singletonList(format);
}
use of org.geowebcache.mime.MimeException in project geowebcache by GeoWebCache.
the class TileBreeder method createTileRange.
/**
* Find the tile range for a Seed Request.
*/
public static TileRange createTileRange(SeedRequest req, TileLayer tl) throws GeoWebCacheException {
int zoomStart = req.getZoomStart().intValue();
int zoomStop = req.getZoomStop().intValue();
MimeType mimeType = null;
String format = req.getMimeFormat();
if (format == null) {
mimeType = tl.getMimeTypes().get(0);
} else {
try {
mimeType = MimeType.createFromFormat(format);
} catch (MimeException e4) {
log.debug(e4);
}
}
String gridSetId = req.getGridSetId();
if (gridSetId == null) {
SRS srs = req.getSRS();
List<GridSubset> crsMatches = tl.getGridSubsetsForSRS(srs);
if (!crsMatches.isEmpty()) {
if (crsMatches.size() == 1) {
gridSetId = crsMatches.get(0).getName();
} else {
throw new IllegalArgumentException("More than one GridSubet matches the requested SRS " + srs + ". gridSetId must be specified");
}
}
}
if (gridSetId == null) {
gridSetId = tl.getGridSubsets().iterator().next();
}
GridSubset gridSubset = tl.getGridSubset(gridSetId);
if (gridSubset == null) {
throw new GeoWebCacheException("Unknown grid set " + gridSetId);
}
long[][] coveredGridLevels;
BoundingBox bounds = req.getBounds();
if (bounds == null) {
coveredGridLevels = gridSubset.getCoverages();
} else {
coveredGridLevels = gridSubset.getCoverageIntersections(bounds);
}
int[] metaTilingFactors = tl.getMetaTilingFactors();
coveredGridLevels = gridSubset.expandToMetaFactors(coveredGridLevels, metaTilingFactors);
String layerName = tl.getName();
Map<String, String> parameters = req.getParameters();
return new TileRange(layerName, gridSetId, zoomStart, zoomStop, coveredGridLevels, mimeType, parameters);
}
use of org.geowebcache.mime.MimeException in project geowebcache by GeoWebCache.
the class SwiftTile method getMetadata.
private BaseMutableContentMetadata getMetadata() {
BaseMutableContentMetadata metadata = new BaseMutableContentMetadata();
metadata.setContentLength(outputLength);
try {
metadata.setContentType(MimeType.createFromFormat(blobFormat).getMimeType());
} catch (MimeException e) {
// Do nothing if we cannot determine the mimeType;
log.warn("Could not determine mimetype for " + toString());
}
return metadata;
}
Aggregations