Search in sources :

Example 6 with MimeTypeParseException

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);
    }
}
Also used : MimetypesFileTypeMap(javax.activation.MimetypesFileTypeMap) MimeTypeParseException(javax.activation.MimeTypeParseException) File(java.io.File) MimeType(javax.activation.MimeType) Failure(org.junit.runner.notification.Failure) Before(org.junit.Before)

Example 7 with MimeTypeParseException

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;
}
Also used : MimeTypeParseException(javax.activation.MimeTypeParseException) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) Resource(ddf.catalog.resource.Resource) IOException(java.io.IOException) MimeType(javax.activation.MimeType) ResourceImpl(ddf.catalog.resource.impl.ResourceImpl) ResourceResponse(ddf.catalog.operation.ResourceResponse) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) ResourceRequestById(ddf.catalog.operation.impl.ResourceRequestById) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException)

Example 8 with MimeTypeParseException

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;
}
Also used : MimeTypeParseException(javax.activation.MimeTypeParseException) MimeType(javax.activation.MimeType)

Example 9 with MimeTypeParseException

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;
}
Also used : MimeTypeParseException(javax.activation.MimeTypeParseException) MimeType(javax.activation.MimeType)

Example 10 with MimeTypeParseException

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;
}
Also used : MimeTypeParseException(javax.activation.MimeTypeParseException) MetacardCreationException(ddf.catalog.data.MetacardCreationException) MimeType(javax.activation.MimeType)

Aggregations

MimeTypeParseException (javax.activation.MimeTypeParseException)17 MimeType (javax.activation.MimeType)14 IOException (java.io.IOException)8 File (java.io.File)4 ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)3 MimetypesFileTypeMap (javax.activation.MimetypesFileTypeMap)3 Before (org.junit.Before)3 Failure (org.junit.runner.notification.Failure)3 RestResponse (com.linkedin.r2.message.rest.RestResponse)2 RestLiDecodingException (com.linkedin.restli.client.RestLiDecodingException)2 IndividualResponse (com.linkedin.restli.common.multiplexer.IndividualResponse)2 BinaryContent (ddf.catalog.data.BinaryContent)2 MetacardCreationException (ddf.catalog.data.MetacardCreationException)2 ResourceResponse (ddf.catalog.operation.ResourceResponse)2 ResourceRequestById (ddf.catalog.operation.impl.ResourceRequestById)2 Resource (ddf.catalog.resource.Resource)2 ResourceNotSupportedException (ddf.catalog.resource.ResourceNotSupportedException)2 ResourceImpl (ddf.catalog.resource.impl.ResourceImpl)2 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)2 InputStream (java.io.InputStream)2