use of javax.activation.MimeType in project ddf by codice.
the class BinaryContentStringTypeConverter method convertTo.
@Override
public <T> T convertTo(Class<T> type, Exchange exchange, Object value) {
String mimeTypeString = exchange.getOut().getHeader(HttpHeaders.CONTENT_TYPE, String.class);
if (null == mimeTypeString) {
mimeTypeString = MediaType.TEXT_PLAIN;
}
MimeType mimeType = null;
try {
mimeType = new MimeType(mimeTypeString);
} catch (MimeTypeParseException e) {
LOGGER.debug("Failed to parse mimetype: " + mimeTypeString, e);
}
T result = null;
try {
result = type.cast(new BinaryContentImpl(exchange.getOut().getBody(InputStream.class), mimeType));
} catch (ClassCastException e) {
LOGGER.debug("Failed to create BinaryContent", e);
}
return result;
}
use of javax.activation.MimeType in project ddf by codice.
the class CatalogComponentTest method testTransformMetacard.
@Test
public void testTransformMetacard() throws Exception {
LOGGER.debug("Running testTransformMetacard()");
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMinimumMessageCount(1);
// Mock a XML InputTransformer and register it in the OSGi Registry
// (PojoSR)
InputTransformer mockTransformer = getMockInputTransformer();
Hashtable<String, String> props = new Hashtable<String, String>();
props.put(MimeTypeToTransformerMapper.ID_KEY, "xml");
props.put(MimeTypeToTransformerMapper.MIME_TYPE_KEY, "text/xml");
bundleContext.registerService(InputTransformer.class.getName(), mockTransformer, props);
// Mock the MimeTypeToTransformerMapper and register it in the OSGi
// Registry (PojoSR)
MimeTypeToTransformerMapper matchingService = mock(MimeTypeToTransformerMapper.class);
// HUGH bundleContext.registerService(
// MimeTypeToTransformerMapper.class.getName(), matchingService, null );
catalogComponent.setMimeTypeToTransformerMapper(matchingService);
// Mock the MimeTypeToTransformerMapper returning the mock XML
// InputTransformer
when(matchingService.findMatches(eq(InputTransformer.class), isA(MimeType.class))).thenReturn((List) Arrays.asList(mockTransformer));
// Send in sample XML as InputStream to InputTransformer
InputStream input = IOUtils.toInputStream(xmlInput);
// Get the InputTransformer registered with the ID associated with the
// <from> node in the Camel route
InputTransformer transformer = getTransformer("text/xml", "identity");
assertNotNull("InputTransformer for mimeType=text/xml&id=identity not found", transformer);
// Transform the XML input into a Metacard
Metacard metacard = transformer.transform(input);
assertNotNull(metacard);
assertMockEndpointsSatisfied();
}
use of javax.activation.MimeType in project ddf by codice.
the class TestCswTransformProvider method testMarshalCswRecord.
@Test
public void testMarshalCswRecord() throws Exception {
when(mockMetacardManager.getTransformerBySchema(CswConstants.CSW_OUTPUT_SCHEMA)).thenReturn(mockCswRecordConverter);
when(mockCswRecordConverter.transform(any(Metacard.class), any(Map.class))).thenReturn(new BinaryContentImpl(IOUtils.toInputStream(getRecord()), new MimeType(MediaType.APPLICATION_XML)));
StringWriter stringWriter = new StringWriter();
HierarchicalStreamWriter writer = new WstxDriver().createWriter(stringWriter);
CswTransformProvider provider = new CswTransformProvider(mockMetacardManager, null);
MarshallingContext context = new TreeMarshaller(writer, null, null);
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
provider.marshal(getMetacard(), writer, context);
// Verify the context arguments were set correctly
verify(mockMetacardManager, times(1)).getTransformerBySchema(captor.capture());
String outputSchema = captor.getValue();
assertThat(outputSchema, is(CswConstants.CSW_OUTPUT_SCHEMA));
}
use of javax.activation.MimeType in project ddf by codice.
the class ResourceCacheImplTest method createCachedResource.
private ReliableResource createCachedResource(Metacard metacard) {
String fileName = "15bytes.txt";
String productLocation = System.getProperty("user.dir") + "/src/test/resources/" + fileName;
File rrCachedFile = new File(productLocation);
return new ReliableResource(CACHED_RESOURCE_KEY, rrCachedFile.getAbsolutePath(), new MimeType(), fileName, metacard);
}
use of javax.activation.MimeType in project ddf by codice.
the class ResourceCacheImplSizeLimitTest method simulateAddFileToProductCache.
private ReliableResource simulateAddFileToProductCache(String key, String fileName, String destFileName, IMap<String, ReliableResource> cacheMap) throws IOException {
String productOriginalLocation = new File(this.getClass().getClassLoader().getResource(fileName).getPath()).getAbsolutePath();
File rrCachedFile = new File(productCacheDir + "/" + destFileName);
FileUtils.copyFile(new File(productOriginalLocation), rrCachedFile);
ReliableResource rr = new ReliableResource(key, rrCachedFile.getAbsolutePath(), new MimeType(), fileName, new MetacardImpl());
rr.setSize(rrCachedFile.length());
LOGGER.debug("adding entry to cache: {}", key);
cacheMap.put(key, rr);
listener.entryAdded(new EntryEvent<Object, Object>(destFileName, null, EntryEventType.ADDED.getType(), key, rr));
return rr;
}
Aggregations