Search in sources :

Example 11 with NoNameCoder

use of com.thoughtworks.xstream.io.naming.NoNameCoder in project ddf by codice.

the class TransactionMessageBodyReader method readFrom.

@Override
public CswTransactionRequest readFrom(Class<CswTransactionRequest> aClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> multivaluedMap, InputStream inputStream) throws IOException, WebApplicationException {
    XStream xStream = new XStream(new Xpp3Driver(new NoNameCoder()));
    xStream.addPermission(NoTypePermission.NONE);
    TransactionRequestConverter transactionRequestConverter = new TransactionRequestConverter(cswRecordConverter, registry);
    transactionRequestConverter.setCswRecordConverter(new CswRecordConverter(metacardType));
    xStream.registerConverter(transactionRequestConverter);
    xStream.allowTypeHierarchy(CswTransactionRequest.class);
    xStream.alias("csw:" + CswConstants.TRANSACTION, CswTransactionRequest.class);
    xStream.alias(CswConstants.TRANSACTION, CswTransactionRequest.class);
    return (CswTransactionRequest) xStream.fromXML(inputStream);
}
Also used : Xpp3Driver(com.thoughtworks.xstream.io.xml.Xpp3Driver) TransactionRequestConverter(org.codice.ddf.spatial.ogc.csw.catalog.converter.TransactionRequestConverter) XStream(com.thoughtworks.xstream.XStream) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) NoNameCoder(com.thoughtworks.xstream.io.naming.NoNameCoder) CswRecordConverter(org.codice.ddf.spatial.ogc.csw.catalog.converter.CswRecordConverter)

Example 12 with NoNameCoder

use of com.thoughtworks.xstream.io.naming.NoNameCoder in project ddf by codice.

the class GetRecordsResponseConverterTest method createXStream.

private XStream createXStream(final String elementName) {
    GetRecordsResponseConverter rrConverter = new GetRecordsResponseConverter(mockProvider);
    XStream xstream = createXstream(new StaxDriver(new NoNameCoder()));
    xstream.registerConverter(rrConverter);
    xstream.alias(CswConstants.CSW_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + elementName, CswRecordCollection.class);
    return xstream;
}
Also used : StaxDriver(com.thoughtworks.xstream.io.xml.StaxDriver) XStream(com.thoughtworks.xstream.XStream) NoNameCoder(com.thoughtworks.xstream.io.naming.NoNameCoder)

Example 13 with NoNameCoder

use of com.thoughtworks.xstream.io.naming.NoNameCoder in project ddf by codice.

the class GetRecordsResponseConverterTest method testMarshalRecordCollectionFullXml.

@Ignore
@Test
public void testMarshalRecordCollectionFullXml() throws UnsupportedEncodingException, JAXBException {
    final int totalResults = 5;
    TransformerManager mockMetacardManager = mock(TransformerManager.class);
    when(mockMetacardManager.getTransformerBySchema(anyString())).thenReturn(new CswRecordConverter(CswRecordConverterTest.getCswMetacardType()));
    GetRecordsResponseConverter rrConverter = new GetRecordsResponseConverter(new CswTransformProvider(mockMetacardManager, null));
    XStream xstream = createXstream(new StaxDriver(new NoNameCoder()));
    xstream.registerConverter(rrConverter);
    xstream.alias(CswConstants.CSW_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + CswConstants.GET_RECORDS_RESPONSE, CswRecordCollection.class);
    GetRecordsType getRecords = new GetRecordsType();
    QueryType query = new QueryType();
    ElementSetNameType set = new ElementSetNameType();
    set.setValue(ElementSetType.FULL);
    query.setElementSetName(set);
    ObjectFactory objectFactory = new ObjectFactory();
    getRecords.setAbstractQuery(objectFactory.createAbstractQuery(query));
    CswRecordCollection collection = createCswRecordCollection(getRecords, totalResults);
    collection.setElementSetType(ElementSetType.FULL);
    String xml = xstream.toXML(collection);
    JAXBElement<GetRecordsResponseType> jaxb = (JAXBElement<GetRecordsResponseType>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
    GetRecordsResponseType response = jaxb.getValue();
    // Assert the GetRecordsResponse elements and attributes
    assertThat(response, not(nullValue()));
    SearchResultsType resultsType = response.getSearchResults();
    assertThat(resultsType, not(nullValue()));
    assertThat(resultsType.getElementSet(), is(ElementSetType.FULL));
    assertThat(resultsType.getNumberOfRecordsMatched().intValue(), is(totalResults));
    assertThat(resultsType.getNumberOfRecordsReturned().intValue(), is(totalResults));
    assertThat(resultsType.getRecordSchema(), is(CswConstants.CSW_OUTPUT_SCHEMA));
}
Also used : TransformerManager(org.codice.ddf.spatial.ogc.csw.catalog.common.transformer.TransformerManager) XStream(com.thoughtworks.xstream.XStream) SearchResultsType(net.opengis.cat.csw.v_2_0_2.SearchResultsType) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) JAXBElement(javax.xml.bind.JAXBElement) NoNameCoder(com.thoughtworks.xstream.io.naming.NoNameCoder) StaxDriver(com.thoughtworks.xstream.io.xml.StaxDriver) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) ElementSetNameType(net.opengis.cat.csw.v_2_0_2.ElementSetNameType) GetRecordsResponseType(net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

NoNameCoder (com.thoughtworks.xstream.io.naming.NoNameCoder)13 XStream (com.thoughtworks.xstream.XStream)9 StaxDriver (com.thoughtworks.xstream.io.xml.StaxDriver)4 XppDriver (com.thoughtworks.xstream.io.xml.XppDriver)4 MarshallingContext (com.thoughtworks.xstream.converters.MarshallingContext)3 TreeMarshaller (com.thoughtworks.xstream.core.TreeMarshaller)3 CompactWriter (com.thoughtworks.xstream.io.xml.CompactWriter)3 PrettyPrintWriter (com.thoughtworks.xstream.io.xml.PrettyPrintWriter)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 StringWriter (java.io.StringWriter)3 HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)2 Writer (java.io.Writer)2 JAXBElement (javax.xml.bind.JAXBElement)2 ElementSetNameType (net.opengis.cat.csw.v_2_0_2.ElementSetNameType)2 GetRecordsResponseType (net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType)2 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)2 ObjectFactory (net.opengis.cat.csw.v_2_0_2.ObjectFactory)2 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)2 SearchResultsType (net.opengis.cat.csw.v_2_0_2.SearchResultsType)2 DateTimeConverter (org.apache.camel.component.salesforce.api.utils.DateTimeConverter)2