use of org.apache.cxf.jaxrs.provider.JAXBElementProvider in project cxf by apache.
the class JAXRSClientServerSpringBookTest method testPostBookXsiType.
@Test
public void testPostBookXsiType() throws Exception {
String address = "http://localhost:" + PORT + "/the/thebooksxsi/bookstore/books/xsitype";
JAXBElementProvider<Book> provider = new JAXBElementProvider<>();
provider.setExtraClass(new Class[] { SuperBook.class });
provider.setJaxbElementClassNames(Collections.singletonList(Book.class.getName()));
WebClient wc = WebClient.create(address, Collections.singletonList(provider));
wc.accept("application/xml");
wc.type("application/xml");
SuperBook book = new SuperBook("SuperBook2", 999L, true);
Book book2 = wc.invoke("POST", book, Book.class, Book.class);
assertEquals("SuperBook2", book2.getName());
}
use of org.apache.cxf.jaxrs.provider.JAXBElementProvider in project ddf by codice.
the class WfsSource method initProviders.
private List<?> initProviders() {
// We need to tell the JAXBElementProvider to marshal the GetFeatureType
// class as an element because it is missing the @XmlRootElement Annotation
JAXBElementProvider<ExtendedGetFeatureType> provider = new JAXBElementProvider<>();
Map<String, String> jaxbClassMap = new HashMap<>();
// Ensure a namespace is used when the GetFeature request is generated
String expandedName = new QName(Wfs11Constants.WFS_NAMESPACE, Wfs11Constants.GET_FEATURE).toString();
jaxbClassMap.put(ExtendedGetFeatureType.class.getName(), expandedName);
provider.setJaxbElementClassMap(jaxbClassMap);
provider.setMarshallAsJaxbElement(true);
return Arrays.asList(provider, new WfsResponseExceptionMapper(), new XmlSchemaMessageBodyReaderWfs11(), new WfsMessageBodyReader(featureTransformationService, () -> wfsMetadata));
}
use of org.apache.cxf.jaxrs.provider.JAXBElementProvider in project ddf by codice.
the class CswResponseExceptionMapper method fromResponse.
@Override
public CswException fromResponse(Response response) {
CswException cswException = null;
if (response != null) {
if (response.getEntity() instanceof InputStream) {
String msg = null;
try {
InputStream is = (InputStream) response.getEntity();
if (is.markSupported()) {
is.reset();
}
msg = IOUtils.toString(is);
} catch (IOException e) {
LOGGER.info("Unable to parse exception report: {}", e.getMessage());
LOGGER.debug("Unable to parse exception report", e);
}
if (msg != null) {
try {
JAXBElementProvider<ExceptionReport> provider = new JAXBElementProvider<>();
Unmarshaller um = provider.getJAXBContext(ExceptionReport.class, ExceptionReport.class).createUnmarshaller();
XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(new StringReader(msg));
ExceptionReport report = (ExceptionReport) um.unmarshal(xmlStreamReader);
cswException = convertToCswException(report);
} catch (JAXBException | XMLStreamException e) {
cswException = new CswException("Error received from remote Csw server: " + msg, e);
LOGGER.info("Error parsing the exception report: {}", e.getMessage());
LOGGER.debug("Error parsing the exception report", e);
}
} else {
cswException = new CswException("Error received from remote Csw server.");
}
} else {
cswException = new CswException("Error reading response, entity type not understood: " + response.getEntity().getClass().getName());
}
cswException.setHttpStatus(response.getStatus());
} else {
cswException = new CswException("Error handling response, response is null");
}
return cswException;
}
use of org.apache.cxf.jaxrs.provider.JAXBElementProvider in project ddf by codice.
the class WfsResponseExceptionMapper method unmarshalResponseEntity.
private WfsException unmarshalResponseEntity(String msg) {
WfsException wfsEx;
try {
JAXBElementProvider<ExceptionReport> provider = new JAXBElementProvider<>();
Unmarshaller um = provider.getJAXBContext(ExceptionReport.class, ExceptionReport.class).createUnmarshaller();
XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(new StringReader(msg));
ExceptionReport report = (ExceptionReport) um.unmarshal(xmlStreamReader);
wfsEx = convertToWfsException(report);
} catch (JAXBException | XMLStreamException e) {
wfsEx = new WfsParseException(msg, e);
}
return wfsEx;
}
use of org.apache.cxf.jaxrs.provider.JAXBElementProvider in project tesb-rt-se by Talend.
the class RESTClient method createJAXRSProviders.
/**
* Creates a custom JAX-RS JAXBElementProvider which can handle
* generated JAXB clasess with no XmlRootElement annotation
* @return providers
*/
private List<Object> createJAXRSProviders() {
JAXBElementProvider provider = new JAXBElementProvider();
provider.setUnmarshallAsJaxbElement(true);
provider.setMarshallAsJaxbElement(true);
List<Object> providers = new ArrayList<Object>();
providers.add(provider);
return providers;
}
Aggregations