Search in sources :

Example 56 with MultivaluedHashMap

use of javax.ws.rs.core.MultivaluedHashMap in project ddf by codice.

the class TestResourceReader method getMockResponse.

private Response getMockResponse() {
    Response mockResponse = mock(Response.class);
    MultivaluedMap<String, Object> map = new MultivaluedHashMap<>();
    when(mockResponse.getHeaders()).thenReturn(map);
    InputStream mockInputStream = mock(InputStream.class);
    when(mockResponse.getEntity()).thenReturn(mockInputStream);
    when(mockResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
    return mockResponse;
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) Response(javax.ws.rs.core.Response) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) InputStream(java.io.InputStream)

Example 57 with MultivaluedHashMap

use of javax.ws.rs.core.MultivaluedHashMap in project ddf by codice.

the class TestGetRecordsMessageBodyReader method testReadProductData.

@Test
public void testReadProductData() throws Exception {
    CswSourceConfiguration config = new CswSourceConfiguration(encryptionService);
    config.setMetacardCswMappings(DefaultCswRecordMap.getCswToMetacardAttributeNames());
    config.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
    GetRecordsMessageBodyReader reader = new GetRecordsMessageBodyReader(mockProvider, config);
    String sampleData = "SampleData";
    byte[] data = sampleData.getBytes();
    ByteArrayInputStream dataInputStream = new ByteArrayInputStream(data);
    MultivaluedMap<String, String> httpHeaders = new MultivaluedHashMap<>();
    httpHeaders.add(CswConstants.PRODUCT_RETRIEVAL_HTTP_HEADER, "TRUE");
    httpHeaders.add(HttpHeaders.CONTENT_DISPOSITION, String.format("inline; filename=ResourceName"));
    MediaType mediaType = new MediaType("text", "plain");
    CswRecordCollection cswRecords = reader.readFrom(CswRecordCollection.class, null, null, mediaType, httpHeaders, dataInputStream);
    Resource resource = cswRecords.getResource();
    assertThat(resource, notNullValue());
    assertThat(resource.getName(), is("ResourceName"));
    assertThat(resource.getMimeType().toString(), is(MediaType.TEXT_PLAIN));
    assertThat(resource.getByteArray(), is(data));
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) Resource(ddf.catalog.resource.Resource) MediaType(javax.ws.rs.core.MediaType) Test(org.junit.Test)

Example 58 with MultivaluedHashMap

use of javax.ws.rs.core.MultivaluedHashMap in project ddf by codice.

the class TestGetRecordsMessageBodyReader method testPartialContentNotSupportedHandling.

@Test
public void testPartialContentNotSupportedHandling() throws Exception {
    CswSourceConfiguration config = new CswSourceConfiguration(encryptionService);
    config.setMetacardCswMappings(DefaultCswRecordMap.getCswToMetacardAttributeNames());
    config.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
    GetRecordsMessageBodyReader reader = new GetRecordsMessageBodyReader(mockProvider, config);
    String sampleData = "SampleData";
    byte[] data = sampleData.getBytes();
    ByteArrayInputStream dataInputStream = new ByteArrayInputStream(data);
    MultivaluedMap<String, String> httpHeaders = new MultivaluedHashMap<>();
    httpHeaders.add(CswConstants.PRODUCT_RETRIEVAL_HTTP_HEADER, "TRUE");
    httpHeaders.add(HttpHeaders.CONTENT_DISPOSITION, String.format("inline; filename=ResourceName"));
    MediaType mediaType = new MediaType("text", "plain");
    CswRecordCollection cswRecords = reader.readFrom(CswRecordCollection.class, null, null, mediaType, httpHeaders, dataInputStream);
    Resource resource = cswRecords.getResource();
    // assert that the CswRecordCollection property is not set if the server does not support Partial Content responses
    assertThat(cswRecords.getResourceProperties().get(GetRecordsMessageBodyReader.BYTES_SKIPPED), nullValue());
    // assert that the input stream has not been skipped at this stage. Since AbstractCswSource has the number
    // of bytes that was attempted to be skipped, the stream must be aligned there instead.
    assertThat(resource.getByteArray(), is(data));
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) Resource(ddf.catalog.resource.Resource) MediaType(javax.ws.rs.core.MediaType) Test(org.junit.Test)

Example 59 with MultivaluedHashMap

use of javax.ws.rs.core.MultivaluedHashMap in project ddf by codice.

the class TestGetRecordsMessageBodyReader method testFullThread.

@Test
public void testFullThread() throws Exception {
    List<Metacard> inputMetacards = new ArrayList<>();
    MetacardImpl metacard = new MetacardImpl(BasicTypes.BASIC_METACARD);
    metacard.setId("metacard1");
    metacard.setTitle("title1");
    inputMetacards.add(metacard);
    CswRecordCollection collection = new CswRecordCollection();
    collection.setCswRecords(inputMetacards);
    when(mockProvider.unmarshal(any(), any())).thenReturn(collection);
    CswSourceConfiguration config = new CswSourceConfiguration(encryptionService);
    Map<String, String> mappings = new HashMap<>();
    mappings.put(Core.CREATED, "dateSubmitted");
    mappings.put(Metacard.EFFECTIVE, "created");
    mappings.put(Core.MODIFIED, "modified");
    mappings.put(Metacard.CONTENT_TYPE, "type");
    config.setMetacardCswMappings(mappings);
    config.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
    config.setCswAxisOrder(CswAxisOrder.LAT_LON);
    config.putMetacardCswMapping(Core.THUMBNAIL, CswConstants.CSW_REFERENCES);
    config.putMetacardCswMapping(Core.RESOURCE_URI, CswConstants.CSW_SOURCE);
    GetRecordsMessageBodyReader reader = new GetRecordsMessageBodyReader(mockProvider, config);
    InputStream is = TestGetRecordsMessageBodyReader.class.getResourceAsStream("/getRecordsResponse.xml");
    MultivaluedMap<String, String> httpHeaders = new MultivaluedHashMap<>();
    CswRecordCollection cswRecords = reader.readFrom(CswRecordCollection.class, null, null, null, httpHeaders, is);
    List<Metacard> metacards = cswRecords.getCswRecords();
    assertThat(metacards, contains(metacard));
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) Metacard(ddf.catalog.data.Metacard) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) Test(org.junit.Test)

Example 60 with MultivaluedHashMap

use of javax.ws.rs.core.MultivaluedHashMap in project cxf by apache.

the class InboundSseEventImpl method read.

private <T> T read(Class<T> messageType, Type type, MediaType mediaType) {
    if (data == null) {
        return null;
    }
    final Annotation[] annotations = new Annotation[0];
    final MultivaluedMap<String, String> headers = new MultivaluedHashMap<>(0);
    final MessageBodyReader<T> reader = factory.createMessageBodyReader(messageType, type, annotations, mediaType, message);
    if (reader == null) {
        throw new RuntimeException("No suitable message body reader for class: " + messageType.getName());
    }
    try (ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8))) {
        return reader.readFrom(messageType, type, annotations, mediaType, headers, is);
    } catch (final IOException ex) {
        throw new RuntimeException("Unable to read data of type " + messageType.getName(), ex);
    }
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) Annotation(java.lang.annotation.Annotation)

Aggregations

MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)133 Response (javax.ws.rs.core.Response)98 Builder (javax.ws.rs.client.Invocation.Builder)78 JSONException (org.codehaus.jettison.json.JSONException)77 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)77 Test (org.testng.annotations.Test)75 JSONObject (org.codehaus.jettison.json.JSONObject)73 Parameters (org.testng.annotations.Parameters)73 BaseTest (org.xdi.oxauth.BaseTest)73 TokenRequest (org.xdi.oxauth.client.TokenRequest)39 Test (org.junit.Test)28 URISyntaxException (java.net.URISyntaxException)27 OxAuthCryptoProvider (org.xdi.oxauth.model.crypto.OxAuthCryptoProvider)21 RegisterResponse (org.xdi.oxauth.client.RegisterResponse)18 ByteArrayInputStream (java.io.ByteArrayInputStream)12 UserInfoRequest (org.xdi.oxauth.client.UserInfoRequest)12 URI (java.net.URI)11 ResourceResponse (ddf.catalog.operation.ResourceResponse)10 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)10 Matchers.containsString (org.hamcrest.Matchers.containsString)9