use of ddf.catalog.resource.ResourceNotSupportedException in project ddf by codice.
the class CswEndpoint method queryProductById.
private CswRecordCollection queryProductById(String id, String rangeValue) throws CswException, UnsupportedQueryException {
final ResourceRequestById resourceRequest = new ResourceRequestById(id);
long bytesToSkip = getRange(rangeValue);
if (bytesToSkip > 0) {
LOGGER.debug("Bytes to skip: {}", String.valueOf(bytesToSkip));
resourceRequest.getProperties().put(CswConstants.BYTES_TO_SKIP, bytesToSkip);
}
ResourceResponse resourceResponse;
try {
resourceResponse = framework.getLocalResource(resourceRequest);
} catch (IOException | ResourceNotFoundException | ResourceNotSupportedException e) {
throw new CswException(String.format(ERROR_ID_PRODUCT_RETRIEVAL, id), e);
}
Resource resource = resourceResponse.getResource();
MimeType mimeType = resource.getMimeType();
if (mimeType == null) {
try {
mimeType = new MimeType(MediaType.APPLICATION_OCTET_STREAM);
resource = new ResourceImpl(resource.getInputStream(), mimeType, resource.getName());
} catch (MimeTypeParseException e) {
throw new CswException(String.format("Could not create mime type upon null mimeType, for mime %s.", MediaType.APPLICATION_OCTET_STREAM), e);
}
}
CswRecordCollection cswRecordCollection = new CswRecordCollection();
cswRecordCollection.setResource(resource);
cswRecordCollection.setOutputSchema(OCTET_STREAM_OUTPUT_SCHEMA);
LOGGER.debug("{} successfully retrieved product for ID: {}", id);
return cswRecordCollection;
}
use of ddf.catalog.resource.ResourceNotSupportedException in project ddf by codice.
the class ResourceDownload method copyToLocalSite.
@Override
public void copyToLocalSite(String sourceId, String metacardId) throws MBeanException {
LOGGER.debug("Downloading resource associated with metacard id [{}] from source [{}] to the local site.", metacardId, sourceId);
ResourceRequest resourceRequest = new ResourceRequestById(metacardId);
if (!resourceCacheMBean.isCacheEnabled()) {
String message = "Caching of resources is not enabled.";
LOGGER.info(message);
throw new MBeanException(new DownloadToLocalSiteException(Status.BAD_REQUEST, message), message);
}
try {
LOGGER.debug("Attempting to download the resource associated with metacard [{}] from source [{}] to the local site.", metacardId, sourceId);
ResourceResponse resourceResponse = catalogFramework.getResource(resourceRequest, sourceId);
if (resourceResponse == null) {
String message = String.format(ERROR_MESSAGE_TEMPLATE, metacardId, sourceId);
LOGGER.debug(message);
throw new MBeanException(new DownloadToLocalSiteException(Status.INTERNAL_SERVER_ERROR, message), message);
}
} catch (IOException | ResourceNotSupportedException e) {
String message = String.format(ERROR_MESSAGE_TEMPLATE, metacardId, sourceId);
LOGGER.debug(message, e);
throw new MBeanException(new DownloadToLocalSiteException(Status.INTERNAL_SERVER_ERROR, message), message);
} catch (ResourceNotFoundException e) {
String message = String.format(ERROR_MESSAGE_TEMPLATE + " The resource could not be found.", metacardId, sourceId);
LOGGER.debug(message, e);
throw new MBeanException(new DownloadToLocalSiteException(Status.NOT_FOUND, message), message);
}
}
use of ddf.catalog.resource.ResourceNotSupportedException in project ddf by codice.
the class ZipCompression method getResource.
private Resource getResource(Metacard metacard) {
Resource resource = null;
try {
ResourceRequest resourceRequest = new ResourceRequestById(metacard.getId());
ResourceResponse resourceResponse = catalogFramework.getLocalResource(resourceRequest);
resource = resourceResponse.getResource();
} catch (IOException | ResourceNotFoundException | ResourceNotSupportedException e) {
LOGGER.debug("Unable to retrieve content from metacard : {}", metacard.getId(), e);
}
return resource;
}
use of ddf.catalog.resource.ResourceNotSupportedException in project ddf by codice.
the class ExceptionsTest method testResourceNotSupportedException.
@Test
public void testResourceNotSupportedException() {
ResourceNotSupportedException rnse = new ResourceNotSupportedException();
assertNotNull(rnse);
rnse = new ResourceNotSupportedException(msg);
assertEquals(rnse.getMessage(), msg);
rnse = new ResourceNotSupportedException(testCause);
assertEquals(rnse.getCause(), testCause);
rnse = new ResourceNotSupportedException(msg, testCause);
assertEquals(rnse.getMessage(), msg);
assertEquals(rnse.getCause(), testCause);
}
use of ddf.catalog.resource.ResourceNotSupportedException in project ddf by codice.
the class SeedCommand method executeWithSubject.
@Override
protected Object executeWithSubject() throws Exception {
if (resourceLimit <= 0) {
printErrorMessage("A limit of " + resourceLimit + " was supplied. The limit must be greater than 0.");
return null;
}
final long start = System.currentTimeMillis();
int resourceDownloads = 0;
int downloadErrors = 0;
int pageCount = 0;
while (resourceDownloads < resourceLimit) {
final QueryImpl query = new QueryImpl(getFilter());
query.setPageSize(resourceLimit);
query.setStartIndex(pageCount * resourceLimit + 1);
++pageCount;
final QueryRequestImpl queryRequest;
if (isNotEmpty(sources)) {
queryRequest = new QueryRequestImpl(query, sources);
} else {
queryRequest = new QueryRequestImpl(query, true);
}
queryRequest.setProperties(new HashMap<>(CACHE_UPDATE_PROPERTIES));
final QueryResponse queryResponse = catalogFramework.query(queryRequest);
if (queryResponse.getResults().isEmpty()) {
break;
}
final List<Entry<? extends ResourceRequest, String>> resourceRequests = queryResponse.getResults().stream().map(Result::getMetacard).filter(isNonCachedResource).map(metacard -> new SimpleEntry<>(new ResourceRequestById(metacard.getId()), metacard.getSourceId())).collect(toList());
for (Entry<? extends ResourceRequest, String> requestAndSourceId : resourceRequests) {
final ResourceRequest request = requestAndSourceId.getKey();
try {
ResourceResponse response = catalogFramework.getResource(request, requestAndSourceId.getValue());
++resourceDownloads;
EXECUTOR.execute(new ResourceCloseHandler(response));
} catch (IOException | ResourceNotFoundException | ResourceNotSupportedException e) {
++downloadErrors;
LOGGER.debug("Could not download resource for metacard [id={}]", request.getAttributeValue(), e);
}
printProgressAndFlush(start, resourceLimit, resourceDownloads);
if (resourceDownloads == resourceLimit) {
break;
}
}
}
printProgressAndFlush(start, resourceDownloads, resourceDownloads);
console.println();
if (downloadErrors > 0) {
printErrorMessage(downloadErrors + " resource download(s) had errors. Check the logs for details.");
}
printSuccessMessage("Done seeding. " + resourceDownloads + " resource download(s) started.");
return null;
}
Aggregations