Search in sources :

Example 21 with BookStoreJaxrsJaxws

use of org.apache.cxf.systest.jaxrs.jaxws.BookStoreJaxrsJaxws in project cxf by apache.

the class JAXRSSoapBookTest method testGetBookSubresourceParamExtensions2.

@Test
public void testGetBookSubresourceParamExtensions2() throws Exception {
    String baseAddress = "http://localhost:" + PORT + "/test/services/rest";
    BookStoreJaxrsJaxws proxy = JAXRSClientFactory.create(baseAddress, BookStoreJaxrsJaxws.class);
    WebClient.getConfig(proxy).getOutInterceptors().add(new LoggingOutInterceptor());
    BookSubresource bs = proxy.getBookSubresource("139");
    BookBean bean = new BookBean("CXF Rocks", 139L);
    bean.getComments().put(1L, "Good");
    bean.getComments().put(2L, "Good");
    BookBean b = bs.getTheBookQueryBean(bean);
    assertEquals(139, b.getId());
    assertEquals("CXF Rocks", b.getName());
}
Also used : BookStoreJaxrsJaxws(org.apache.cxf.systest.jaxrs.jaxws.BookStoreJaxrsJaxws) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) Test(org.junit.Test)

Example 22 with BookStoreJaxrsJaxws

use of org.apache.cxf.systest.jaxrs.jaxws.BookStoreJaxrsJaxws in project cxf by apache.

the class JAXRSSoapBookTest method testGetUnqualifiedBookSoap.

@Test
public void testGetUnqualifiedBookSoap() throws Exception {
    String wsdlAddress = "http://localhost:" + PORT + "/test/services/soap-transform/bookservice?wsdl";
    BookSoapService service = new BookSoapService(new URL(wsdlAddress), new QName("http://books.com", "BookService"));
    BookStoreJaxrsJaxws store = service.getBookPort();
    TransformOutInterceptor out = new TransformOutInterceptor();
    Map<String, String> mapOut = new HashMap<>();
    // Book content (id, name) is unqualified, thus the following works
    // because JAXB will report
    // - {http://jaxws.jaxrs.systest.cxf.apache.org/}Book
    // - id
    // - name
    // and only the qualified top-level Book tag gets matched by the following
    // mapping
    mapOut.put("{http://jaxws.jaxrs.systest.cxf.apache.org/}*", "*");
    out.setOutTransformElements(mapOut);
    TransformInInterceptor in = new TransformInInterceptor();
    Map<String, String> mapIn = new HashMap<>();
    // mapIn.put("*", "{http://jaxws.jaxrs.systest.cxf.apache.org/}*");
    // won't work for a case where a totally unqualified getBookResponse needs to be
    // qualified such that only the top-level getBookResponse is processed because of '*'.
    // Such a mapping would work nicely if we had say a package-info making both
    // Book id & name qualified; otherwise we need to choose what tag we need to qualify
    // mapIn.put("*", "{http://jaxws.jaxrs.systest.cxf.apache.org/}*");
    // works too if the schema validation is disabled
    mapIn.put("getBookResponse", "{http://jaxws.jaxrs.systest.cxf.apache.org/}getBookResponse");
    in.setInTransformElements(mapIn);
    Client cl = ClientProxy.getClient(store);
    ((HTTPConduit) cl.getConduit()).getClient().setReceiveTimeout(10000000);
    cl.getInInterceptors().add(in);
    cl.getOutInterceptors().add(out);
    Book book = store.getBook(new Long(123));
    assertEquals("id is wrong", book.getId(), 123);
}
Also used : BookStoreJaxrsJaxws(org.apache.cxf.systest.jaxrs.jaxws.BookStoreJaxrsJaxws) HashMap(java.util.HashMap) BookSoapService(org.apache.cxf.systest.jaxrs.jaxws.BookSoapService) QName(javax.xml.namespace.QName) TransformOutInterceptor(org.apache.cxf.interceptor.transform.TransformOutInterceptor) Client(org.apache.cxf.endpoint.Client) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL) TransformInInterceptor(org.apache.cxf.interceptor.transform.TransformInInterceptor) Test(org.junit.Test)

Aggregations

BookStoreJaxrsJaxws (org.apache.cxf.systest.jaxrs.jaxws.BookStoreJaxrsJaxws)22 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)4 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)3 AbstractFeature (org.apache.cxf.feature.AbstractFeature)3 JAXRSClientFactoryBean (org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean)3 URL (java.net.URL)2 NotFoundException (javax.ws.rs.NotFoundException)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 QName (javax.xml.namespace.QName)2 WebClient (org.apache.cxf.jaxrs.client.WebClient)2 JAXBElementProvider (org.apache.cxf.jaxrs.provider.JAXBElementProvider)2 BookSoapService (org.apache.cxf.systest.jaxrs.jaxws.BookSoapService)2 HashMap (java.util.HashMap)1 Response (javax.ws.rs.core.Response)1 Client (org.apache.cxf.endpoint.Client)1 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)1 TransformInInterceptor (org.apache.cxf.interceptor.transform.TransformInInterceptor)1 TransformOutInterceptor (org.apache.cxf.interceptor.transform.TransformOutInterceptor)1 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)1