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;
}
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));
}
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));
}
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));
}
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);
}
}
Aggregations