use of javax.activation.MimeType in project ddf by codice.
the class TestActionProviderRegistryProxy method testAttributeTransformer.
@Test
public void testAttributeTransformer() throws MimeTypeParseException {
// given
ActionProviderRegistryProxy proxy = new ActionProviderRegistryProxyTest(mtapf);
when(mockBundleContext.getService(mockServiceReference)).thenReturn(new AttributeMetacardTransformer("metadata", "metadata", new MimeType("text", "xml")));
// when
proxy.bind(mockServiceReference);
// then
verify(mockBundleContext, times(1)).registerService(anyString(), captor.capture(), any(Dictionary.class));
Object value = captor.getValue();
assertThat(value, notNullValue());
assertThat(value instanceof ActionProvider, is(true));
}
use of javax.activation.MimeType in project ddf by codice.
the class ResourceMetacardTransformer method transform.
@Override
public BinaryContent transform(Metacard metacard, Map<String, Serializable> arguments) throws CatalogTransformerException {
LOGGER.trace("Entering resource ResourceMetacardTransformer.transform");
if (!isValid(metacard)) {
throw new CatalogTransformerException("Could not transform metacard to a resource because the metacard is not valid.");
}
if (StringUtils.isNotEmpty(metacard.getResourceSize())) {
arguments.put(Metacard.RESOURCE_SIZE, metacard.getResourceSize());
}
String id = metacard.getId();
LOGGER.debug("executing resource request with id '{}'", id);
final ResourceRequest resourceRequest = new ResourceRequestById(id, arguments);
ResourceResponse resourceResponse = null;
String sourceName = metacard.getSourceId();
if (StringUtils.isBlank(sourceName)) {
sourceName = catalogFramework.getId();
}
String resourceUriAscii = "";
if (metacard.getResourceURI() != null) {
resourceUriAscii = metacard.getResourceURI().toASCIIString();
}
try {
resourceResponse = catalogFramework.getResource(resourceRequest, sourceName);
} catch (IOException e) {
throw new CatalogTransformerException(retrieveResourceFailureMessage(id, sourceName, resourceUriAscii, e.getMessage()), e);
} catch (ResourceNotFoundException e) {
throw new CatalogTransformerException(retrieveResourceFailureMessage(id, sourceName, resourceUriAscii, e.getMessage()), e);
} catch (ResourceNotSupportedException e) {
throw new CatalogTransformerException(retrieveResourceFailureMessage(id, sourceName, resourceUriAscii, e.getMessage()), e);
}
if (resourceResponse == null) {
throw new CatalogTransformerException(retrieveResourceFailureMessage(id, sourceName, resourceUriAscii));
}
Resource transformedContent = resourceResponse.getResource();
MimeType mimeType = transformedContent.getMimeType();
if (mimeType == null) {
try {
mimeType = new MimeType(DEFAULT_MIME_TYPE_STR);
// There is no method to set the MIME type, so in order to set it to our default
// one, we need to create a new object.
transformedContent = new ResourceImpl(transformedContent.getInputStream(), mimeType, transformedContent.getName());
} catch (MimeTypeParseException e) {
throw new CatalogTransformerException("Could not create default mime type upon null mimeType, for default mime type '" + DEFAULT_MIME_TYPE_STR + "'.", e);
}
}
LOGGER.debug("Found mime type: '{}' for product of metacard with id: '{}'.\nGetting associated resource from input stream. \n", mimeType, id);
LOGGER.trace("Exiting resource transform for metacard id: '{}'", id);
return transformedContent;
}
use of javax.activation.MimeType in project ddf by codice.
the class TestResourceMetacardTransformer method testNullMetacard.
@Test
public void testNullMetacard() throws Exception {
thrown.expect(CatalogTransformerException.class);
thrown.expectMessage("Could not transform metacard to a resource because the metacard is not valid.");
String filePath = ABSOLUTE_PATH + TEST_PATH + TS_FILE_NAME_1;
URI uri = getUri(filePath);
Metacard metacard = null;
boolean expectSuccess = false;
MimeType mimeType = getMimeType(VIDEO_MIME_TYPE);
CatalogFramework framework = getFramework(getResourceResponse(getResource(mimeType, uri)));
testGetResource(metacard, filePath, mimeType, framework, expectSuccess);
}
use of javax.activation.MimeType in project ddf by codice.
the class TestResourceMetacardTransformer method testNullResourceResponse.
@Test
public void testNullResourceResponse() throws Exception {
String filePath = ABSOLUTE_PATH + TEST_PATH + JPEG_FILE_NAME_1;
URI uri = getUri(filePath);
Metacard metacard = getMockMetacard(uri);
thrown.expect(CatalogTransformerException.class);
thrown.expectMessage("Unable to retrieve resource.");
thrown.expectMessage("Metacard id: " + TEST_ID);
thrown.expectMessage("Uri: " + uri);
thrown.expectMessage("Source: " + TEST_SITE);
boolean expectSuccess = false;
MimeType mimeType = getMimeType(JPEG_MIME_TYPE);
CatalogFramework framework = getFramework(null);
testGetResource(metacard, filePath, mimeType, framework, expectSuccess);
}
use of javax.activation.MimeType in project ddf by codice.
the class TestResourceMetacardTransformer method testFrameworkThrowsResourceNotFoundException.
@Test
public void testFrameworkThrowsResourceNotFoundException() throws Exception {
String filePath = ABSOLUTE_PATH + TEST_PATH + JPEG_FILE_NAME_1;
URI uri = getUri(filePath);
Metacard metacard = getMockMetacard(uri);
thrown.expect(CatalogTransformerException.class);
thrown.expectMessage("Unable to retrieve resource.");
thrown.expectMessage("Metacard id: " + TEST_ID);
thrown.expectMessage("Uri: " + uri);
thrown.expectMessage("Source: " + TEST_SITE);
boolean expectSuccess = false;
MimeType mimeType = getMimeType(JPEG_MIME_TYPE);
CatalogFramework framework = getFrameworkException(new ResourceNotFoundException("Test Resource Not Found Exception"));
testGetResource(metacard, filePath, mimeType, framework, expectSuccess);
}
Aggregations