use of org.apache.cxf.jaxrs.provider.JAXBElementProvider in project cxf by apache.
the class JAXRSSoapBookTest method testPostGetBookFastinfosetProxy.
@Test
public void testPostGetBookFastinfosetProxy() throws Exception {
JAXBElementProvider<Object> p = new JAXBElementProvider<>();
p.setConsumeMediaTypes(Collections.singletonList("application/fastinfoset"));
p.setProduceMediaTypes(Collections.singletonList("application/fastinfoset"));
BookStoreJaxrsJaxws client = JAXRSClientFactory.create("http://localhost:" + PORT + "/test/services/rest4", BookStoreSoapRestFastInfoset2.class, Collections.singletonList(p));
Book b = new Book("CXF", 1L);
Book b2 = client.addFastinfoBook(b);
assertEquals(b2.getName(), b.getName());
assertEquals(b2.getId(), b.getId());
checkFiInterceptors(WebClient.getConfig(client));
}
use of org.apache.cxf.jaxrs.provider.JAXBElementProvider in project cxf by apache.
the class JAXRSSoapBookTest method testGetBookFastinfoset.
@Test
public void testGetBookFastinfoset() throws Exception {
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress("http://localhost:" + PORT + "/test/services/rest3/bookstore/fastinfoset2");
bean.getInInterceptors().add(new FIStaxInInterceptor());
JAXBElementProvider<?> p = new JAXBElementProvider<>();
p.setConsumeMediaTypes(Collections.singletonList("application/fastinfoset"));
bean.setProvider(p);
Map<String, Object> props = new HashMap<>();
props.put(FIStaxInInterceptor.FI_GET_SUPPORTED, Boolean.TRUE);
bean.setProperties(props);
WebClient client = bean.createWebClient();
Book b = client.accept("application/fastinfoset").get(Book.class);
assertEquals("CXF2", b.getName());
assertEquals(2L, b.getId());
}
use of org.apache.cxf.jaxrs.provider.JAXBElementProvider in project cxf by apache.
the class AbstractXmlSecOutInterceptor method getDomDocument.
@SuppressWarnings("unchecked")
private Document getDomDocument(Message m) throws Exception {
Object body = getRequestBody(m);
if (body == null) {
return null;
}
if (body instanceof Document) {
return (Document) body;
}
if (body instanceof DOMSource) {
return (Document) ((DOMSource) body).getNode();
}
ProviderFactory pf = ProviderFactory.getInstance(m);
Object providerObject = pf.createMessageBodyWriter(body.getClass(), body.getClass(), new Annotation[] {}, MediaType.APPLICATION_XML_TYPE, m);
if (!(providerObject instanceof JAXBElementProvider)) {
return null;
}
JAXBElementProvider<Object> provider = (JAXBElementProvider<Object>) providerObject;
W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
m.setContent(XMLStreamWriter.class, writer);
provider.writeTo(body, body.getClass(), new Annotation[] {}, MediaType.APPLICATION_XML_TYPE, (MultivaluedMap<String, Object>) m.get(Message.PROTOCOL_HEADERS), null);
return writer.getDocument();
}
use of org.apache.cxf.jaxrs.provider.JAXBElementProvider in project cxf by apache.
the class JAXRSClientServerResourceCreatedSpringProviderTest method testPostPetStatusType.
@Test
public void testPostPetStatusType() throws Exception {
JAXBElementProvider<Object> p = new JAXBElementProvider<>();
p.setUnmarshallAsJaxbElement(true);
WebClient wc = WebClient.create("http://localhost:" + PORT + "/webapp/pets/petstore/jaxb/statusType/", Collections.singletonList(p));
WebClient.getConfig(wc).getInInterceptors().add(new LoggingInInterceptor());
wc.accept("text/xml");
PetStore.PetStoreStatusType type = wc.get(PetStore.PetStoreStatusType.class);
assertEquals(PetStore.CLOSED, type.getStatus());
}
use of org.apache.cxf.jaxrs.provider.JAXBElementProvider in project cxf by apache.
the class JAXRSClientServerBookTest method testPostGetBookAdapterList.
@Test
public void testPostGetBookAdapterList() throws Exception {
JAXBElementProvider<?> provider = new JAXBElementProvider<>();
Map<String, String> outMap = new HashMap<>();
outMap.put("Books", "CollectionWrapper");
outMap.put("books", "Book");
provider.setOutTransformElements(outMap);
WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/books/adapter-list", Collections.singletonList(provider));
Collection<? extends Book> books = wc.type("application/xml").accept("application/xml").postAndGetCollection(new Books(new Book("CXF", 123L)), Book.class);
assertEquals(1, books.size());
assertEquals(123L, books.iterator().next().getId());
}
Aggregations