use of javax.activation.MimeTypeParseException in project ddf by codice.
the class ResourceImplTest method setUp.
@Before
public void setUp() {
content = new File("src/test/resources/data/i4ce.png");
MimetypesFileTypeMap mimeMapper = new MimetypesFileTypeMap();
try {
mimeType = new MimeType(mimeMapper.getContentType(content));
} catch (MimeTypeParseException e) {
LOGGER.error("Mime parser Failure", e);
new Failure(null, e);
}
}
use of javax.activation.MimeTypeParseException 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 javax.activation.MimeTypeParseException in project ddf by codice.
the class Configuration method setMimeType.
public void setMimeType(String mimeType) {
MimeType mime = null;
try {
mime = new MimeType(mimeType);
} catch (MimeTypeParseException e) {
LOGGER.info("Failed to create mimetype: {}.", mimeType);
}
this.mimeType = mime;
}
use of javax.activation.MimeTypeParseException in project ddf by codice.
the class RESTEndpoint method getMimeType.
private MimeType getMimeType(HttpHeaders headers) {
List<String> contentTypeList = headers.getRequestHeader(HttpHeaders.CONTENT_TYPE);
String singleMimeType = null;
if (contentTypeList != null && !contentTypeList.isEmpty()) {
singleMimeType = contentTypeList.get(0);
LOGGER.debug("Encountered [{}] {}", singleMimeType, HttpHeaders.CONTENT_TYPE);
}
MimeType mimeType = null;
// Sending a null argument to MimeType causes NPE
if (singleMimeType != null) {
try {
mimeType = new MimeType(singleMimeType);
} catch (MimeTypeParseException e) {
LOGGER.debug("Could not parse mime type from headers.", e);
}
}
return mimeType;
}
use of javax.activation.MimeTypeParseException in project ddf by codice.
the class RESTEndpoint method parseMetadata.
private Metacard parseMetadata(String transformerParam, Metacard metacard, Attachment attachment, InputStream inputStream) {
String transformer = DEFAULT_METACARD_TRANSFORMER;
if (transformerParam != null) {
transformer = transformerParam;
}
try {
MimeType mimeType = new MimeType(attachment.getContentType().toString());
metacard = generateMetacard(mimeType, "assigned-when-ingested", inputStream, transformer);
} catch (MimeTypeParseException | MetacardCreationException e) {
LOGGER.debug("Unable to parse metadata {}", attachment.getContentType().toString());
} finally {
IOUtils.closeQuietly(inputStream);
}
return metacard;
}
Aggregations