Search in sources :

Example 1 with MimeException

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);
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Resource(org.geowebcache.io.Resource) ByteArrayResource(org.geowebcache.io.ByteArrayResource) MimeException(org.geowebcache.mime.MimeException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Example 2 with MimeException

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);
        }
    }
}
Also used : BlockBlobURL(com.microsoft.azure.storage.blob.BlockBlobURL) InputStream(java.io.InputStream) Resource(org.geowebcache.io.Resource) ByteArrayResource(org.geowebcache.io.ByteArrayResource) RestException(com.microsoft.rest.v2.RestException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) BlobHTTPHeaders(com.microsoft.azure.storage.blob.models.BlobHTTPHeaders) MimeException(org.geowebcache.mime.MimeException) BlobGetPropertiesResponse(com.microsoft.azure.storage.blob.models.BlobGetPropertiesResponse) StorageException(org.geowebcache.storage.StorageException)

Example 3 with MimeException

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);
}
Also used : MimeException(org.geowebcache.mime.MimeException) MimeType(org.geowebcache.mime.MimeType)

Example 4 with MimeException

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);
}
Also used : GridSubset(org.geowebcache.grid.GridSubset) MimeType(org.geowebcache.mime.MimeType) TileRange(org.geowebcache.storage.TileRange) SRS(org.geowebcache.grid.SRS) BoundingBox(org.geowebcache.grid.BoundingBox) MimeException(org.geowebcache.mime.MimeException) GeoWebCacheException(org.geowebcache.GeoWebCacheException)

Example 5 with MimeException

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;
}
Also used : BaseMutableContentMetadata(org.jclouds.io.payloads.BaseMutableContentMetadata) MimeException(org.geowebcache.mime.MimeException)

Aggregations

MimeException (org.geowebcache.mime.MimeException)20 MimeType (org.geowebcache.mime.MimeType)14 GeoWebCacheException (org.geowebcache.GeoWebCacheException)8 ConveyorTile (org.geowebcache.conveyor.ConveyorTile)7 GridSubset (org.geowebcache.grid.GridSubset)6 ServiceException (org.geowebcache.service.ServiceException)6 TileLayer (org.geowebcache.layer.TileLayer)5 IOException (java.io.IOException)3 BoundingBox (org.geowebcache.grid.BoundingBox)3 Resource (org.geowebcache.io.Resource)3 File (java.io.File)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 ServletOutputStream (javax.servlet.ServletOutputStream)2 OutsideCoverageException (org.geowebcache.grid.OutsideCoverageException)2 SRS (org.geowebcache.grid.SRS)2 ByteArrayResource (org.geowebcache.io.ByteArrayResource)2 GWCTask (org.geowebcache.seed.GWCTask)2 StorageException (org.geowebcache.storage.StorageException)2 TileObject (org.geowebcache.storage.TileObject)2