Search in sources :

Example 26 with JAXBElementProvider

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()));
}
Also used : Response(javax.ws.rs.core.Response) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JAXBElementProvider(org.apache.cxf.jaxrs.provider.JAXBElementProvider) HashMap(java.util.HashMap) GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 27 with JAXBElementProvider

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());
}
Also used : Response(javax.ws.rs.core.Response) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JAXBElementProvider(org.apache.cxf.jaxrs.provider.JAXBElementProvider) Test(org.junit.Test)

Example 28 with JAXBElementProvider

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;
}
Also used : JAXBElementProvider(org.apache.cxf.jaxrs.provider.JAXBElementProvider) ArrayList(java.util.ArrayList)

Example 29 with JAXBElementProvider

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);
}
Also used : Bus(org.apache.cxf.Bus) JAXBElementProvider(org.apache.cxf.jaxrs.provider.JAXBElementProvider) CustomerService(org.example.customers.CustomerService) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) ArrayList(java.util.ArrayList)

Example 30 with JAXBElementProvider

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();
}
Also used : JAXBElementProvider(org.apache.cxf.jaxrs.provider.JAXBElementProvider) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) RuntimeDelegate(javax.ws.rs.ext.RuntimeDelegate) BeforeClass(org.junit.BeforeClass)

Aggregations

JAXBElementProvider (org.apache.cxf.jaxrs.provider.JAXBElementProvider)30 Test (org.junit.Test)9 HashMap (java.util.HashMap)8 JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)6 WebClient (org.apache.cxf.jaxrs.client.WebClient)6 ArrayList (java.util.ArrayList)5 Unmarshaller (javax.xml.bind.Unmarshaller)5 XMLStreamException (javax.xml.stream.XMLStreamException)5 InputStream (java.io.InputStream)4 StringReader (java.io.StringReader)4 JAXBException (javax.xml.bind.JAXBException)4 QName (javax.xml.namespace.QName)4 XMLInputFactory (javax.xml.stream.XMLInputFactory)4 XMLStreamReader (javax.xml.stream.XMLStreamReader)4 IOException (java.io.IOException)3 Response (javax.ws.rs.core.Response)3 RuntimeDelegate (javax.ws.rs.ext.RuntimeDelegate)3 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)3 Type (java.lang.reflect.Type)2 TypeVariable (java.lang.reflect.TypeVariable)2