Search in sources :

Example 1 with ByteArrayResource

use of org.geowebcache.io.ByteArrayResource in project geowebcache by GeoWebCache.

the class KMLService method handleSuperOverlay.

/**
 * Creates a superoverlay, ie. a short description and network links to the first overlays.
 */
private void handleSuperOverlay(ConveyorKMLTile tile) throws GeoWebCacheException {
    TileLayer layer = tile.getLayer();
    GridSubset gridSubset = tile.getGridSubset();
    // int srsIdx = layer.getSRSIndex(srs);
    BoundingBox bbox = gridSubset.getCoverageBestFitBounds();
    String formatExtension = "." + tile.getMimeType().getFileExtension();
    if (tile.getWrapperMimeType() != null) {
        formatExtension = formatExtension + "." + tile.getWrapperMimeType().getFileExtension();
    }
    long[] gridRect = gridSubset.getCoverageBestFit();
    String networkLinks = null;
    // Check whether we need two tiles for world bounds or not
    if (gridRect[4] > 0 && (gridRect[2] != gridRect[0] || gridRect[3] != gridRect[1])) {
        throw new GeoWebCacheException(layer.getName() + " (" + bbox.toString() + ") is too big for the sub grid set for " + gridSubset.getName() + ", allow for smaller zoom levels.");
    } else if (gridRect[0] != gridRect[2]) {
        long[] gridLocWest = { 0, 0, 0 };
        long[] gridLocEast = { 1, 0, 0 };
        BoundingBox bboxWest = new BoundingBox(bbox.getMinX(), bbox.getMinY(), 0.0, bbox.getMaxY());
        BoundingBox bboxEast = new BoundingBox(0.0, bbox.getMinY(), bbox.getMaxX(), bbox.getMaxY());
        networkLinks = superOverlayNetworLink(layer.getName() + " West", bboxWest, tile.getUrlPrefix() + "/" + gridLocString(gridLocWest) + formatExtension) + superOverlayNetworLink(layer.getName() + " East", bboxEast, tile.getUrlPrefix() + "/" + gridLocString(gridLocEast) + formatExtension);
    } else {
        long[] gridLoc = { gridRect[0], gridRect[1], gridRect[4] };
        networkLinks = superOverlayNetworLink(layer.getName(), bbox, tile.getUrlPrefix() + "/" + gridLocString(gridLoc) + formatExtension);
    }
    String xml = KMLHeader() + "\n<Folder>" + getLookAt(bbox) + networkLinks + "\n</Folder>" + "\n</kml>\n";
    tile.setBlob(new ByteArrayResource(xml.getBytes()));
    tile.setMimeType(XMLMime.kml);
    tile.setStatus(200);
    String mimeStr = getMimeTypeOverride(tile);
    writeTileResponse(tile, true, stats, mimeStr);
}
Also used : TileLayer(org.geowebcache.layer.TileLayer) BoundingBox(org.geowebcache.grid.BoundingBox) GeoWebCacheException(org.geowebcache.GeoWebCacheException) GridSubset(org.geowebcache.grid.GridSubset) ByteArrayResource(org.geowebcache.io.ByteArrayResource)

Example 2 with ByteArrayResource

use of org.geowebcache.io.ByteArrayResource in project geowebcache by GeoWebCache.

the class KMLService method handleOverlay.

/**
 * These are the main nodes in the KML hierarchy, each overlay contains a set of network links
 * (up to 4) that point to the overlays on the next level.
 *
 * <p>1) KMZ: The cache will contain a zip with overlay and data
 *
 * <p>2) KML: The cache will only contain the overlay itself, the overlay will cause a separate
 * tile request to get the data
 */
private void handleOverlay(ConveyorKMLTile tile) throws GeoWebCacheException {
    TileLayer tileLayer = tile.getLayer();
    boolean packageData = false;
    if (tile.getWrapperMimeType() == XMLMime.kmz) {
        packageData = true;
    }
    // Sigh....
    if (!packageData) {
        String overlayXml = createOverlay(tile, false);
        tile.setBlob(new ByteArrayResource(overlayXml.getBytes()));
        tile.setStatus(200);
    // tileLayer.putTile(tile);
    } else {
        // Get the overlay
        String overlayXml = createOverlay(tile, true);
        // Get the data (cheat)
        try {
            tile.setWrapperMimeType(null);
            try {
                tileLayer.getTile(tile);
            } catch (OutsideCoverageException oce) {
                log.error("Out of bounds: " + Arrays.toString(tile.getTileIndex()) + " should never habe been linked to.");
                throw oce;
            }
            tile.setWrapperMimeType(XMLMime.kmz);
        } catch (IOException ioe) {
            log.error(ioe);
            throw new ServiceException(ioe.getMessage());
        }
        byte[] zip = KMZHelper.createZippedKML(gridLocString(tile.getTileIndex()), tile.getMimeType().getFileExtension(), overlayXml.getBytes(), tile.getBlob());
        tile.setBlob(new ByteArrayResource(zip));
        tile.setStatus(200);
    // tileLayer.putTile(tile);
    }
    String mimeStr = getMimeTypeOverride(tile);
    writeTileResponse(tile, true, stats, mimeStr);
}
Also used : OutsideCoverageException(org.geowebcache.grid.OutsideCoverageException) TileLayer(org.geowebcache.layer.TileLayer) ServiceException(org.geowebcache.service.ServiceException) ByteArrayResource(org.geowebcache.io.ByteArrayResource) IOException(java.io.IOException)

Example 3 with ByteArrayResource

use of org.geowebcache.io.ByteArrayResource in project geowebcache by GeoWebCache.

the class S3BlobStore method get.

@Override
public boolean get(TileObject obj) throws StorageException {
    final String key = keyBuilder.forTile(obj);
    try (S3Object object = s3Ops.getObject(key)) {
        if (object == null) {
            return false;
        }
        try (S3ObjectInputStream in = object.getObjectContent()) {
            byte[] bytes = ByteStreams.toByteArray(in);
            obj.setBlobSize(bytes.length);
            obj.setBlob(new ByteArrayResource(bytes));
            obj.setCreated(object.getObjectMetadata().getLastModified().getTime());
        }
    } catch (IOException e) {
        throw new StorageException("Error getting " + key, e);
    }
    return true;
}
Also used : S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) S3Object(com.amazonaws.services.s3.model.S3Object) ByteArrayResource(org.geowebcache.io.ByteArrayResource) IOException(java.io.IOException) StorageException(org.geowebcache.storage.StorageException)

Example 4 with ByteArrayResource

use of org.geowebcache.io.ByteArrayResource in project geowebcache by GeoWebCache.

the class HazelcastCacheProviderTest method testTilePut.

@Test
public void testTilePut() throws Exception {
    // Clearing cache
    cache1.clear();
    // Ensure that both caches are cleared
    assertEquals(0, cache1.getStatistics().getActualSize());
    assertEquals(0, cache2.getStatistics().getActualSize());
    // Put a TileObject
    Resource bytes = new ByteArrayResource("1 2 3 4 5 6 test".getBytes());
    long[] xyz = { 1L, 2L, 3L };
    Map<String, String> parameters = new HashMap<>();
    parameters.put("a", "x");
    parameters.put("b", "ΓΈ");
    TileObject to = TileObject.createCompleteTileObject("test:123123 112", xyz, "EPSG:4326", "image/jpeg", parameters, bytes);
    mem1.put(to);
    // Try to get the same TileObject
    TileObject to2 = TileObject.createQueryTileObject("test:123123 112", xyz, "EPSG:4326", "image/jpeg", parameters);
    assertTrue(mem2.get(to2));
    // Checks on the format
    assertEquals(to.getBlobFormat(), to2.getBlobFormat());
    // Checks if the resources are equals
    try (InputStream is = to.getBlob().getInputStream();
        InputStream is2 = to2.getBlob().getInputStream()) {
        checkInputStreams(is, is2);
    }
    // Ensure Caches contain the result
    TileObject to3 = cache1.getTileObj(to);
    assertNotNull(to3);
    // Checks if the resources are equals
    try (InputStream is = to.getBlob().getInputStream();
        InputStream is3 = to3.getBlob().getInputStream()) {
        checkInputStreams(is, is3);
    }
    TileObject to4 = cache2.getTileObj(to);
    assertNotNull(to4);
    // Checks if the resources are equals
    try (InputStream is = to.getBlob().getInputStream();
        InputStream is4 = to4.getBlob().getInputStream()) {
        checkInputStreams(is, is4);
    }
}
Also used : HashMap(java.util.HashMap) InputStream(java.io.InputStream) Resource(org.geowebcache.io.Resource) ByteArrayResource(org.geowebcache.io.ByteArrayResource) TileObject(org.geowebcache.storage.TileObject) ByteArrayResource(org.geowebcache.io.ByteArrayResource) Test(org.junit.Test)

Example 5 with ByteArrayResource

use of org.geowebcache.io.ByteArrayResource in project geowebcache by GeoWebCache.

the class AbstractAzureBlobStoreIntegrationTest method testDelete.

@Test
public void testDelete() throws MimeException, StorageException {
    byte[] bytes = new byte[1024];
    Arrays.fill(bytes, (byte) 0xaf);
    TileObject tile = queryTile(20, 30, 12);
    tile.setBlob(new ByteArrayResource(bytes));
    blobStore.put(tile);
    tile.getXYZ()[0] = 21;
    blobStore.put(tile);
    tile.getXYZ()[0] = 22;
    blobStore.put(tile);
    tile = queryTile(20, 30, 12);
    assertTrue(blobStore.delete(tile));
    tile.getXYZ()[0] = 21;
    assertTrue(blobStore.delete(tile));
    BlobStoreListener listener = mock(BlobStoreListener.class);
    blobStore.addListener(listener);
    tile.getXYZ()[0] = 22;
    assertTrue(blobStore.delete(tile));
    assertFalse(blobStore.delete(tile));
    verify(listener, times(1)).tileDeleted(eq(tile.getLayerName()), eq(tile.getGridSetId()), eq(tile.getBlobFormat()), anyString(), eq(22L), eq(30L), eq(12), eq(1024L));
}
Also used : BlobStoreListener(org.geowebcache.storage.BlobStoreListener) TileObject(org.geowebcache.storage.TileObject) ByteArrayResource(org.geowebcache.io.ByteArrayResource) Test(org.junit.Test)

Aggregations

ByteArrayResource (org.geowebcache.io.ByteArrayResource)71 Test (org.junit.Test)43 Resource (org.geowebcache.io.Resource)24 TileObject (org.geowebcache.storage.TileObject)18 IOException (java.io.IOException)13 InputStream (java.io.InputStream)13 HashMap (java.util.HashMap)12 GridSubset (org.geowebcache.grid.GridSubset)8 BoundingBox (org.geowebcache.grid.BoundingBox)7 BlobStoreListener (org.geowebcache.storage.BlobStoreListener)7 XMLGridSubset (org.geowebcache.config.XMLGridSubset)6 TileLayer (org.geowebcache.layer.TileLayer)6 StorageException (org.geowebcache.storage.StorageException)6 ConveyorTile (org.geowebcache.conveyor.ConveyorTile)5 SecurityDispatcher (org.geowebcache.filter.security.SecurityDispatcher)5 MimeType (org.geowebcache.mime.MimeType)5 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)5 File (java.io.File)4 Capture (org.easymock.Capture)4