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.");
}
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);
}
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);
}
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);
}
}
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;
}
Aggregations