Search in sources :

Example 6 with ResourceResponse

use of ddf.catalog.operation.ResourceResponse in project ddf by codice.

the class TestResourceReader method testRetrieveResourceTextHtmlDetectedByTika.

@Test
public void testRetrieveResourceTextHtmlDetectedByTika() throws Exception {
    // Setup
    Response mockResponse = getMockResponse();
    setupMockWebClient(mockResponse);
    setupMockTika(MediaType.TEXT_HTML);
    URLResourceReader urlResourceReader = new URLResourceReader(null) {

        @Override
        protected WebClient getWebClient(String uri, Map<String, Serializable> properties) {
            return mockWebClient;
        }
    };
    OgcUrlResourceReader resourceReader = new OgcUrlResourceReader(urlResourceReader, mockTika);
    String httpUriStr = HTTP_SCHEME_PLUS_SEP + MOCK_HTTP_SERVER_HOST + ":" + MOCK_HTTP_SERVER_PORT + MOCK_HTTP_SERVER_PATH;
    URI uri = new URI(httpUriStr);
    HashMap<String, Serializable> arguments = new HashMap<String, Serializable>();
    // Perform Test
    ResourceResponse resourceResponse = resourceReader.retrieveResource(uri, arguments);
    // Verify
    StringWriter writer = new StringWriter();
    IOUtils.copy(resourceResponse.getResource().getInputStream(), writer, MOCK_HTTP_SERVER_ENCODING);
    String responseString = writer.toString();
    LOGGER.info("Response {}", responseString);
    assertThat(responseString, is("<html><script type=\"text/javascript\">window.location.replace(\"" + httpUriStr + "\");</script></html>"));
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) Response(javax.ws.rs.core.Response) Serializable(java.io.Serializable) URLResourceReader(ddf.catalog.resource.impl.URLResourceReader) ResourceResponse(ddf.catalog.operation.ResourceResponse) StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) HashMap(java.util.HashMap) Map(java.util.Map) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) URI(java.net.URI) Test(org.junit.Test)

Example 7 with ResourceResponse

use of ddf.catalog.operation.ResourceResponse in project ddf by codice.

the class TestResourceReader method testRetrieveResourceOriginalUrlResourceReaderResponseReturned.

/**
     * Tests the case in which the mime type of the Resource in the ResourceResponse returned by the
     * URLResourceReader is not text/html, application/unknown or application/octet-stream.  The original
     * response from the URLResourceReader is returned.
     */
@Test
public void testRetrieveResourceOriginalUrlResourceReaderResponseReturned() throws Exception {
    // Setup
    String httpUriStr = HTTP_SCHEME_PLUS_SEP + MOCK_HTTP_SERVER_HOST + ":" + MOCK_HTTP_SERVER_PORT + MOCK_HTTP_SERVER_PATH;
    URI uri = new URI(httpUriStr);
    ResourceResponse mockResourceResponse = getMockResourceResponse(new MimeType("image/jpeg"));
    URLResourceReader mockUrlResourceReader = getMockUrlResourceReader(uri, mockResourceResponse);
    setupMockTika(null);
    OgcUrlResourceReader resourceReader = new OgcUrlResourceReader(mockUrlResourceReader, mockTika);
    HashMap<String, Serializable> arguments = new HashMap<String, Serializable>();
    // Perform Test
    ResourceResponse resourceResponse = resourceReader.retrieveResource(uri, arguments);
    // Verify
    assertThat(resourceResponse, is(mockResourceResponse));
}
Also used : Serializable(java.io.Serializable) ResourceResponse(ddf.catalog.operation.ResourceResponse) URLResourceReader(ddf.catalog.resource.impl.URLResourceReader) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) URI(java.net.URI) MimeType(javax.activation.MimeType) Test(org.junit.Test)

Example 8 with ResourceResponse

use of ddf.catalog.operation.ResourceResponse in project ddf by codice.

the class ResourceOperations method getLocalResource.

public ResourceResponse getLocalResource(ResourceRequest request, boolean fanoutEnabled) throws IOException, ResourceNotFoundException, ResourceNotSupportedException {
    String methodName = "getLocalResource";
    LOGGER.debug("ENTERING: {}", methodName);
    ResourceResponse resourceResponse;
    if (fanoutEnabled) {
        LOGGER.debug("getLocalResource call received, fanning it out to all sites.");
        resourceResponse = getEnterpriseResource(request, fanoutEnabled);
    } else {
        resourceResponse = getResource(request, false, getId(), fanoutEnabled);
    }
    LOGGER.debug("EXITING: {} ", methodName);
    return resourceResponse;
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse)

Example 9 with ResourceResponse

use of ddf.catalog.operation.ResourceResponse in project ddf by codice.

the class ResourceOperations method getEnterpriseResource.

//
// Delegate methods
//
public ResourceResponse getEnterpriseResource(ResourceRequest request, boolean fanoutEnabled) throws IOException, ResourceNotFoundException, ResourceNotSupportedException {
    String methodName = "getEnterpriseResource";
    LOGGER.debug("ENTERING: {}", methodName);
    ResourceResponse resourceResponse = getResource(request, true, null, fanoutEnabled);
    LOGGER.debug("EXITING: {}", methodName);
    return resourceResponse;
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse)

Example 10 with ResourceResponse

use of ddf.catalog.operation.ResourceResponse in project ddf by codice.

the class ReliableResourceDownloader method retrieveResource.

private ReliableResourceCallable retrieveResource(long bytesRead) {
    ReliableResourceCallable reliableResourceCallable = null;
    try {
        LOGGER.debug("Attempting to re-retrieve resource, skipping {} bytes", bytesRead);
        // Re-fetch product from the Source after setting up values to indicate the number of
        // bytes to skip. This prevents the same bytes being read again and put in the
        // PipedOutputStream that the client is still reading from and in the file being cached
        // to. It also allows for range headers to be used in the request so that already read
        // bytes do not need to be re-retrieved.
        ResourceResponse resourceResponse = retriever.retrieveResource(bytesRead);
        LOGGER.debug("Name of re-retrieved resource = {}", resourceResponse.getResource().getName());
        resourceInputStream = resourceResponse.getResource().getInputStream();
        reliableResourceCallable = new ReliableResourceCallable(resourceInputStream, countingFbos, fos, downloaderConfig.getChunkSize(), lock);
        // So that Callable can account for bytes read in previous download attempt(s)
        reliableResourceCallable.setBytesRead(bytesRead);
    } catch (ResourceNotFoundException | ResourceNotSupportedException | IOException e) {
        LOGGER.info("Unable to re-retrieve product; cannot download product file {}", filePath);
    }
    return reliableResourceCallable;
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) IOException(java.io.IOException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException)

Aggregations

ResourceResponse (ddf.catalog.operation.ResourceResponse)71 Test (org.junit.Test)36 HashMap (java.util.HashMap)17 Resource (ddf.catalog.resource.Resource)16 URI (java.net.URI)16 Serializable (java.io.Serializable)15 Metacard (ddf.catalog.data.Metacard)13 IOException (java.io.IOException)13 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)13 ResourceRequest (ddf.catalog.operation.ResourceRequest)12 ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)12 MimeType (javax.activation.MimeType)11 ResourceNotSupportedException (ddf.catalog.resource.ResourceNotSupportedException)10 Response (javax.ws.rs.core.Response)10 ResourceRequestById (ddf.catalog.operation.impl.ResourceRequestById)8 URLResourceReader (ddf.catalog.resource.impl.URLResourceReader)7 Matchers.anyString (org.mockito.Matchers.anyString)7 InputStream (java.io.InputStream)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6