use of org.apache.cxf.jaxrs.provider.JAXBElementProvider in project tesb-rt-se by Talend.
the class CustomerServiceClient method useCustomerServiceRest.
public void useCustomerServiceRest(String[] args) throws Exception {
JAXBElementProvider provider = new JAXBElementProvider();
provider.setUnmarshallAsJaxbElement(true);
provider.setMarshallAsJaxbElement(true);
List<Object> providers = new ArrayList<Object>();
providers.add(provider);
providers.add(new ResponseExceptionMapper<NoSuchCustomerException>() {
@Override
public NoSuchCustomerException fromResponse(Response r) {
return new NoSuchCustomerException();
}
});
CustomerService customerService = JAXRSClientFactory.createFromModel("http://localhost:" + port + "/services/jaxrs", CustomerService.class, "classpath:/data/model/CustomerService-jaxrs.xml", providers, null);
System.out.println("Using RESTful CustomerService");
Customer customer = createCustomer("Smith");
customerService.updateCustomer(customer);
customer = customerService.getCustomerByName("Smith");
printCustomerDetails(customer);
customer = customerService.getCustomerByName("Barry");
if (customer != null) {
throw new RuntimeException("Barry should not be found");
}
System.out.println("Status : " + WebClient.client(customerService).getResponse().getStatus());
try {
customerService.getCustomerByName("John");
throw new RuntimeException("Exception is expected");
} catch (NoSuchCustomerException ex) {
System.out.println("NoSuchCustomerException : John");
}
}
use of org.apache.cxf.jaxrs.provider.JAXBElementProvider in project jbpm by kiegroup.
the class RestWorkItemHandlerTest method initialize.
@SuppressWarnings({ "rawtypes" })
@BeforeClass
public static void initialize() throws Exception {
SimpleRESTApplication application = new SimpleRESTApplication();
RuntimeDelegate delegate = RuntimeDelegate.getInstance();
JAXRSServerFactoryBean bean = delegate.createEndpoint(application, JAXRSServerFactoryBean.class);
bean.setProvider(new JAXBElementProvider());
bean.setAddress("http://localhost:9998" + bean.getAddress());
server = bean.create();
server.start();
}
use of org.apache.cxf.jaxrs.provider.JAXBElementProvider in project jbpm by kiegroup.
the class RestWorkitemHandlerClientCreationTest method initialize.
@SuppressWarnings({ "rawtypes" })
@BeforeClass
public static void initialize() throws Exception {
SimpleRESTApplication application = new SimpleRESTApplication();
RuntimeDelegate delegate = RuntimeDelegate.getInstance();
JAXRSServerFactoryBean bean = delegate.createEndpoint(application, JAXRSServerFactoryBean.class);
bean.setProvider(new JAXBElementProvider());
bean.setAddress("http://localhost:9998" + bean.getAddress());
server = bean.create();
server.start();
}
use of org.apache.cxf.jaxrs.provider.JAXBElementProvider in project ddf by codice.
the class WfsResponseExceptionMapper method fromResponse.
public WfsException fromResponse(Response response) {
WfsException wfsEx = null;
if (response != null) {
if (response.getEntity() instanceof InputStream) {
String msg = null;
try {
InputStream is = (InputStream) response.getEntity();
is.reset();
msg = IOUtils.toString(is);
} catch (IOException e) {
wfsEx = new WfsException("Error reading Response" + (msg != null ? ": " + msg : ""), e);
}
if (msg != null) {
try {
JAXBElementProvider<ServiceExceptionReport> provider = new JAXBElementProvider<ServiceExceptionReport>();
Unmarshaller um = provider.getJAXBContext(ServiceExceptionReport.class, ServiceExceptionReport.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));
ServiceExceptionReport report = (ServiceExceptionReport) um.unmarshal(xmlStreamReader);
wfsEx = convertToWfsException(report);
} catch (JAXBException | XMLStreamException e) {
wfsEx = new WfsException("Error parsing Response: " + msg, e);
}
}
} else {
wfsEx = new WfsException("Error reading response, entity type not understood: " + response.getEntity().getClass().getName());
}
if (wfsEx != null) {
wfsEx.setHttpStatus(response.getStatus());
}
} else {
wfsEx = new WfsException("Error handling response, response is null");
}
return wfsEx;
}
use of org.apache.cxf.jaxrs.provider.JAXBElementProvider in project syncope by apache.
the class SyncopeClientFactoryBean method defaultJAXBProvider.
@SuppressWarnings({ "rawtypes" })
protected JAXBElementProvider<?> defaultJAXBProvider() {
JAXBElementProvider<?> defaultJAXBProvider = new JAXBElementProvider();
DocumentDepthProperties depthProperties = new DocumentDepthProperties();
depthProperties.setInnerElementCountThreshold(500);
defaultJAXBProvider.setDepthProperties(depthProperties);
Map<String, Object> marshallerProperties = new HashMap<>();
marshallerProperties.put(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
defaultJAXBProvider.setMarshallerProperties(marshallerProperties);
Map<String, String> collectionWrapperMap = new HashMap<>();
collectionWrapperMap.put(PolicyTO.class.getName(), "policies");
defaultJAXBProvider.setCollectionWrapperMap(collectionWrapperMap);
return defaultJAXBProvider;
}
Aggregations