use of org.apache.cxf.jaxrs.provider.JAXBElementProvider in project cxf by apache.
the class JAXRSClientServerBookTest method testPostGetBookAdapterListJSON.
@Test
public void testPostGetBookAdapterListJSON() 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));
Response r = wc.type("application/xml").accept("application/json").post(new Books(new Book("CXF", 123L)));
assertEquals("{\"Book\":[{\"id\":123,\"name\":\"CXF\"}]}", IOUtils.readStringFromStream((InputStream) r.getEntity()));
}
use of org.apache.cxf.jaxrs.provider.JAXBElementProvider in project cxf by apache.
the class JAXRSClientServerSpringBookTest method testPostGeneratedBook.
@Test
public void testPostGeneratedBook() throws Exception {
String baseAddress = "http://localhost:" + PORT + "/the/generated";
JAXBElementProvider<?> provider = new JAXBElementProvider<>();
provider.setJaxbElementClassMap(Collections.singletonMap("org.apache.cxf.systest.jaxrs.codegen.schema.Book", "{http://superbooks}thebook"));
org.apache.cxf.systest.jaxrs.codegen.service.BookStore bookStore = JAXRSClientFactory.create(baseAddress, org.apache.cxf.systest.jaxrs.codegen.service.BookStore.class, Collections.singletonList(provider));
org.apache.cxf.systest.jaxrs.codegen.schema.Book book = new org.apache.cxf.systest.jaxrs.codegen.schema.Book();
book.setId(123);
bookStore.addBook(123, book);
Response r = WebClient.client(bookStore).getResponse();
assertEquals(204, r.getStatus());
}
use of org.apache.cxf.jaxrs.provider.JAXBElementProvider in project tesb-rt-se by Talend.
the class CustomerServiceServer method createProviders.
private static List<Object> createProviders() {
JAXBElementProvider provider = new JAXBElementProvider();
provider.setUnmarshallAsJaxbElement(true);
provider.setMarshallAsJaxbElement(true);
List<Object> providers = new ArrayList<Object>();
providers.add(provider);
return providers;
}
use of org.apache.cxf.jaxrs.provider.JAXBElementProvider in project tesb-rt-se by Talend.
the class CustomerServiceServer method main.
public static void main(String[] args) throws Exception {
Bus bus = BusFactory.getDefaultBus();
System.out.println("Starting Server");
CustomerService implementor = new CustomerServiceImpl();
Endpoint.publish("http://localhost:8080/services/jaxws", implementor);
JAXRSServerFactoryBean jaxrsFactory = new JAXRSServerFactoryBean();
jaxrsFactory.setBus(bus);
jaxrsFactory.setAddress("http://localhost:8080/services/jaxrs");
jaxrsFactory.setModelRef("classpath:/data/model/CustomerService-jaxrs.xml");
jaxrsFactory.setServiceBean(implementor);
List<Object> providers = new ArrayList<Object>();
JAXBElementProvider jaxbProvider = new JAXBElementProvider();
jaxbProvider.setMarshallAsJaxbElement(true);
jaxbProvider.setUnmarshallAsJaxbElement(true);
providers.add(jaxbProvider);
providers.add(new NoCustomerExceptionMapper());
jaxrsFactory.setProviders(providers);
jaxrsFactory.create();
System.out.println("Server ready...");
Thread.sleep(5 * 60 * 1000);
System.out.println("Server exiting");
System.exit(0);
}
use of org.apache.cxf.jaxrs.provider.JAXBElementProvider in project jbpm by kiegroup.
the class BasicAuthRestWorkItemHandlerTest 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());
// disabled logging interceptor by default but proves to be useful
// bean.getInInterceptors().add(new LoggingInInterceptor(new PrintWriter(System.out, true)));
bean.setProvider(new AuthenticationFilter());
server = bean.create();
server.start();
}
Aggregations