Search in sources :

Example 6 with ResourceResponseImpl

use of ddf.catalog.operation.impl.ResourceResponseImpl in project ddf by codice.

the class FilterPluginTest method testNoSubjectResource.

@Test(expected = StopProcessingException.class)
public void testNoSubjectResource() throws Exception {
    ResourceResponseImpl response = new ResourceResponseImpl(mock(Resource.class));
    plugin.processPostResource(response, mock(Metacard.class));
    fail("Plugin should have thrown exception when no subject was sent in.");
}
Also used : Metacard(ddf.catalog.data.Metacard) Resource(ddf.catalog.resource.Resource) ResourceResponseImpl(ddf.catalog.operation.impl.ResourceResponseImpl) Test(org.junit.Test)

Example 7 with ResourceResponseImpl

use of ddf.catalog.operation.impl.ResourceResponseImpl in project ddf by codice.

the class WfsSource method retrieveResource.

@Override
public ResourceResponse retrieveResource(URI uri, Map<String, Serializable> arguments) throws IOException, ResourceNotFoundException, ResourceNotSupportedException {
    StringBuilder strBuilder = new StringBuilder();
    strBuilder.append("<html><script type=\"text/javascript\">window.location.replace(\"");
    strBuilder.append(uri);
    strBuilder.append("\");</script></html>");
    Resource resource = new ResourceImpl(IOUtils.toInputStream(strBuilder.toString()), MediaType.TEXT_HTML, getId() + " Resource");
    return new ResourceResponseImpl(resource);
}
Also used : ResourceImpl(ddf.catalog.resource.impl.ResourceImpl) Resource(ddf.catalog.resource.Resource) ResourceResponseImpl(ddf.catalog.operation.impl.ResourceResponseImpl)

Example 8 with ResourceResponseImpl

use of ddf.catalog.operation.impl.ResourceResponseImpl in project ddf by codice.

the class TestZipCompression method setUp.

@Before
public void setUp() throws Exception {
    JarSigner jarSigner = mock(JarSigner.class);
    doNothing().when(jarSigner).signJar(any(File.class), anyString(), anyString(), anyString(), anyString());
    zipCompression = new ZipCompression(jarSigner);
    sourceResponse = createSourceResponseWithURISchemes(null, null);
    filePathArgument = new HashMap<>();
    filePathArgument.put("filePath", temporaryFolder.getRoot().getAbsolutePath() + File.separator + "signed.zip");
    catalogFramework = mock(CatalogFramework.class);
    Resource resource = mock(Resource.class);
    InputStream resourceFileStream = new FileInputStream(new File(LOCAL_RESOURCE_PATH));
    when(resource.getName()).thenReturn(LOCAL_RESOURCE_FILENAME);
    when(resource.getInputStream()).thenReturn(resourceFileStream);
    ResourceResponse resourceResponse = new ResourceResponseImpl(resource);
    when(catalogFramework.getLocalResource(any(ResourceRequestById.class))).thenReturn(resourceResponse);
    zipCompression.setCatalogFramework(catalogFramework);
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) CatalogFramework(ddf.catalog.CatalogFramework) Resource(ddf.catalog.resource.Resource) ResourceRequestById(ddf.catalog.operation.impl.ResourceRequestById) ResourceResponseImpl(ddf.catalog.operation.impl.ResourceResponseImpl) File(java.io.File) FileInputStream(java.io.FileInputStream) Before(org.junit.Before)

Example 9 with ResourceResponseImpl

use of ddf.catalog.operation.impl.ResourceResponseImpl in project ddf by codice.

the class URLResourceReader method retrieveFileProduct.

private ResourceResponse retrieveFileProduct(URI resourceURI, String productName, String bytesToSkip) throws ResourceNotFoundException {
    URLConnection connection = null;
    try {
        LOGGER.debug("Opening connection to: {}", resourceURI.toString());
        connection = resourceURI.toURL().openConnection();
        productName = StringUtils.defaultIfBlank(handleContentDispositionHeader(connection.getHeaderField(HttpHeaders.CONTENT_DISPOSITION)), productName);
        String mimeType = getMimeType(resourceURI, productName);
        InputStream is = connection.getInputStream();
        skipBytes(is, bytesToSkip);
        return new ResourceResponseImpl(new ResourceImpl(new BufferedInputStream(is), mimeType, FilenameUtils.getName(productName)));
    } catch (MimeTypeResolutionException | IOException e) {
        LOGGER.info("Error retrieving resource", e);
        throw new ResourceNotFoundException("Unable to retrieve resource at: " + resourceURI.toString(), e);
    }
}
Also used : MimeTypeResolutionException(ddf.mime.MimeTypeResolutionException) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) ResourceResponseImpl(ddf.catalog.operation.impl.ResourceResponseImpl) IOException(java.io.IOException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) URLConnection(java.net.URLConnection)

Example 10 with ResourceResponseImpl

use of ddf.catalog.operation.impl.ResourceResponseImpl in project ddf by codice.

the class ReliableResourceDownloader method setupDownload.

public ResourceResponse setupDownload(Metacard metacard, DownloadStatusInfo downloadStatusInfo) {
    Resource resource = resourceResponse.getResource();
    MimeType mimeType = resource.getMimeType();
    String resourceName = resource.getName();
    fbos = new FileBackedOutputStream(DEFAULT_FILE_BACKED_OUTPUT_STREAM_THRESHOLD);
    countingFbos = new CountingOutputStream(fbos);
    streamReadByClient = new ReliableResourceInputStream(fbos, countingFbos, downloadState, downloadIdentifier, resourceResponse);
    this.metacard = metacard;
    // Create new ResourceResponse to return that will encapsulate the
    // ReliableResourceInputStream that will be read by the client simultaneously as the product
    // is cached to disk (if caching is enabled)
    ResourceImpl newResource = new ResourceImpl(streamReadByClient, mimeType, resourceName);
    resourceResponse = new ResourceResponseImpl(resourceResponse.getRequest(), resourceResponse.getProperties(), newResource);
    // Get handle to retrieved product's InputStream
    resourceInputStream = resource.getInputStream();
    eventListener.setDownloadMap(downloadIdentifier, resourceResponse);
    downloadStatusInfo.addDownloadInfo(downloadIdentifier, this, resourceResponse);
    if (downloaderConfig.isCacheEnabled()) {
        CacheKey keyMaker = null;
        String key = null;
        try {
            keyMaker = new CacheKey(metacard, resourceResponse.getRequest());
            key = keyMaker.generateKey();
        } catch (IllegalArgumentException e) {
            LOGGER.info("Cannot create cache key for resource with metacard ID = {}", metacard.getId());
            return resourceResponse;
        }
        if (!resourceCache.isPending(key)) {
            // Fully qualified path to cache file that will be written to.
            // Example:
            // <INSTALL-DIR>/data/product-cache/<source-id>-<metacard-id>
            // <INSTALL-DIR>/data/product-cache/ddf.distribution-abc123
            filePath = FilenameUtils.concat(resourceCache.getProductCacheDirectory(), key);
            if (filePath == null) {
                LOGGER.info("Unable to create cache for cache directory {} and key {} - no caching will be done.", resourceCache.getProductCacheDirectory(), key);
                return resourceResponse;
            }
            reliableResource = new ReliableResource(key, filePath, mimeType, resourceName, metacard);
            resourceCache.addPendingCacheEntry(reliableResource);
            try {
                fos = FileUtils.openOutputStream(new File(filePath));
                doCaching = true;
                this.downloadState.setCacheEnabled(true);
            } catch (IOException e) {
                LOGGER.info("Unable to open cache file {} - no caching will be done.", filePath);
            }
        } else {
            LOGGER.debug("Cache key {} is already pending caching", key);
        }
    }
    return resourceResponse;
}
Also used : ReliableResource(ddf.catalog.resource.data.ReliableResource) Resource(ddf.catalog.resource.Resource) ResourceResponseImpl(ddf.catalog.operation.impl.ResourceResponseImpl) IOException(java.io.IOException) MimeType(javax.activation.MimeType) ReliableResource(ddf.catalog.resource.data.ReliableResource) CountingOutputStream(com.google.common.io.CountingOutputStream) ResourceImpl(ddf.catalog.resource.impl.ResourceImpl) FileBackedOutputStream(com.google.common.io.FileBackedOutputStream) File(java.io.File) CacheKey(ddf.catalog.cache.impl.CacheKey)

Aggregations

ResourceResponseImpl (ddf.catalog.operation.impl.ResourceResponseImpl)14 Resource (ddf.catalog.resource.Resource)8 ResourceImpl (ddf.catalog.resource.impl.ResourceImpl)7 ResourceResponse (ddf.catalog.operation.ResourceResponse)6 ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)5 IOException (java.io.IOException)5 BufferedInputStream (java.io.BufferedInputStream)4 InputStream (java.io.InputStream)4 Serializable (java.io.Serializable)3 HashMap (java.util.HashMap)3 CacheKey (ddf.catalog.cache.impl.CacheKey)2 Metacard (ddf.catalog.data.Metacard)2 MimeTypeResolutionException (ddf.mime.MimeTypeResolutionException)2 Subject (ddf.security.Subject)2 File (java.io.File)2 URI (java.net.URI)2 MimeType (javax.activation.MimeType)2 Response (javax.ws.rs.core.Response)2 WebClient (org.apache.cxf.jaxrs.client.WebClient)2 CountingOutputStream (com.google.common.io.CountingOutputStream)1