Search in sources :

Example 1 with ResourceNotFoundException

use of ddf.catalog.resource.ResourceNotFoundException in project ddf by codice.

the class OpenSearchSource method retrieveResource.

@Override
public ResourceResponse retrieveResource(URI uri, Map<String, Serializable> requestProperties) throws ResourceNotFoundException, ResourceNotSupportedException, IOException {
    final String methodName = "retrieveResource";
    LOGGER.trace("ENTRY: {}", methodName);
    if (requestProperties == null) {
        throw new ResourceNotFoundException("Could not retrieve resource with null properties.");
    }
    Serializable serializableId = requestProperties.get(Metacard.ID);
    if (serializableId != null) {
        String metacardId = serializableId.toString();
        WebClient restClient = null;
        restClient = newRestClient(null, metacardId, true, null);
        return resourceReader.retrieveResource(restClient.getCurrentURI(), requestProperties);
    }
    LOGGER.trace("EXIT: {}", methodName);
    throw new ResourceNotFoundException(COULD_NOT_RETRIEVE_RESOURCE_MESSAGE);
}
Also used : Serializable(java.io.Serializable) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) WebClient(org.apache.cxf.jaxrs.client.WebClient)

Example 2 with ResourceNotFoundException

use of ddf.catalog.resource.ResourceNotFoundException in project ddf by codice.

the class TestResourceMetacardTransformer method testNullResourceUri.

@Test
public void testNullResourceUri() throws Exception {
    thrown.expect(CatalogTransformerException.class);
    thrown.expectMessage("Unable to retrieve resource.");
    Metacard metacard = getMockMetacard(null);
    CatalogFramework framework = getFrameworkException(new ResourceNotFoundException(""));
    ResourceMetacardTransformer resourceTransformer = new ResourceMetacardTransformer(framework);
    resourceTransformer.transform(metacard, new HashMap<String, Serializable>());
}
Also used : Metacard(ddf.catalog.data.Metacard) Serializable(java.io.Serializable) CatalogFramework(ddf.catalog.CatalogFramework) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) Test(org.junit.Test)

Example 3 with ResourceNotFoundException

use of ddf.catalog.resource.ResourceNotFoundException in project ddf by codice.

the class ResourceReaderTest method testUrlToNonExistentFile.

@Test
public void testUrlToNonExistentFile() throws Exception {
    URLResourceReader resourceReader = new URLResourceReader(mimeTypeMapper);
    String filePath = ABSOLUTE_PATH + TEST_PATH + "NonExistentFile.jpg";
    HashMap<String, Serializable> arguments = new HashMap<String, Serializable>();
    try {
        LOGGER.info("Getting resource: {}", filePath);
        File file = new File(filePath);
        URI uri = file.toURI();
        resourceReader.retrieveResource(uri, arguments);
    } catch (IOException e) {
        LOGGER.info("Successfully caught IOException");
        fail();
    } catch (ResourceNotFoundException e) {
        LOGGER.info("Caught ResourceNotFoundException");
        assert (true);
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) IOException(java.io.IOException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) File(java.io.File) URI(java.net.URI) Test(org.junit.Test)

Example 4 with ResourceNotFoundException

use of ddf.catalog.resource.ResourceNotFoundException in project ddf by codice.

the class ResourceReaderTest method testURLResourceIOException.

@Test
public void testURLResourceIOException() throws Exception {
    URLResourceReader resourceReader = new URLResourceReader(mimeTypeMapper);
    String filePath = "JUMANJI!!!!";
    HashMap<String, Serializable> arguments = new HashMap<String, Serializable>();
    try {
        LOGGER.info("Getting resource: {}", filePath);
        URI uri = new URI(FILE_SCHEME_PLUS_SEP + filePath);
        resourceReader.retrieveResource(uri, arguments);
    } catch (IOException e) {
        LOGGER.info("Successfully caught IOException");
        fail();
    } catch (ResourceNotFoundException e) {
        LOGGER.info("Caught ResourceNotFoundException");
        assert (true);
    } catch (URISyntaxException e) {
        LOGGER.info("Caught unexpected URISyntaxException");
        fail();
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) URI(java.net.URI) Test(org.junit.Test)

Example 5 with ResourceNotFoundException

use of ddf.catalog.resource.ResourceNotFoundException in project ddf by codice.

the class ResourceReaderTest method testURLResourceReaderBadQualifier.

@Test
public void testURLResourceReaderBadQualifier() {
    URLResourceReader resourceReader = new TestURLResourceReader(mimeTypeMapper);
    resourceReader.setRootResourceDirectories(ImmutableSet.of(ABSOLUTE_PATH + TEST_PATH));
    String filePath = TEST_PATH + MPEG_FILE_NAME_1;
    HashMap<String, Serializable> arguments = new HashMap<String, Serializable>();
    try {
        LOGGER.info("Getting resource: {}", filePath);
        URI uri = new URI(FILE_SCHEME_PLUS_SEP + filePath);
        resourceReader.retrieveResource(uri, arguments);
    } catch (IOException e) {
        LOGGER.info("Successfully caught expected IOException");
        fail();
    } catch (ResourceNotFoundException e) {
        LOGGER.info("Caught unexpected ResourceNotFoundException");
        assert (true);
    } catch (URISyntaxException e) {
        LOGGER.info("Caught unexpected URISyntaxException");
        fail();
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) URI(java.net.URI) Test(org.junit.Test)

Aggregations

ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)41 IOException (java.io.IOException)25 ResourceResponse (ddf.catalog.operation.ResourceResponse)17 URI (java.net.URI)16 ResourceNotSupportedException (ddf.catalog.resource.ResourceNotSupportedException)14 Serializable (java.io.Serializable)14 Metacard (ddf.catalog.data.Metacard)13 Test (org.junit.Test)12 HashMap (java.util.HashMap)11 URISyntaxException (java.net.URISyntaxException)10 Result (ddf.catalog.data.Result)8 ResourceRequest (ddf.catalog.operation.ResourceRequest)8 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)8 ResourceRequestById (ddf.catalog.operation.impl.ResourceRequestById)7 Resource (ddf.catalog.resource.Resource)7 QueryRequest (ddf.catalog.operation.QueryRequest)6 QueryResponse (ddf.catalog.operation.QueryResponse)6 ResourceResponseImpl (ddf.catalog.operation.impl.ResourceResponseImpl)6 CatalogFramework (ddf.catalog.CatalogFramework)5 FederationException (ddf.catalog.federation.FederationException)5