/** * Creates a proxy using user resource model * @param baseAddress baseAddress * @param cls proxy class, if not interface then a CGLIB proxy will be created * @param modelBeans model beans * @param configLocation classpath location of the configuration resource * @return typed proxy */ public static <T> T createFromModel(String baseAddress, Class<T> cls, List<UserResource> modelBeans, String configLocation) { return createFromModel(baseAddress, cls, modelBeans, Collections.emptyList(), configLocation); }
/** * Creates a proxy using user resource model * @param baseAddress baseAddress * @param cls proxy class, if not interface then a CGLIB proxy will be created * @param modelBeans model beans * @param configLocation classpath location of the configuration resource * @return typed proxy */ public static <T> T createFromModel(String baseAddress, Class<T> cls, List<UserResource> modelBeans, String configLocation) { return createFromModel(baseAddress, cls, modelBeans, Collections.emptyList(), configLocation); }
/** * Creates a proxy using user resource model * @param baseAddress baseAddress * @param cls proxy class, if not interface then a CGLIB proxy will be created * @param modelRef model location * @return typed proxy */ public static <T> T createFromModel(String baseAddress, Class<T> cls, String modelRef, String configLocation) { return createFromModel(baseAddress, cls, modelRef, Collections.emptyList(), configLocation); }
/** * Creates a proxy using user resource model * @param baseAddress baseAddress * @param cls proxy class, if not interface then a CGLIB proxy will be created * @param modelRef model location * @return typed proxy */ public static <T> T createFromModel(String baseAddress, Class<T> cls, String modelRef, String configLocation) { return createFromModel(baseAddress, cls, modelRef, Collections.emptyList(), configLocation); }
/** * Creates a proxy using user resource model * @param baseAddress baseAddress * @param cls proxy class, if not interface then a CGLIB proxy will be created * @param modelRef model location * @return typed proxy */ public static <T> T createFromModel(String baseAddress, Class<T> cls, String modelRef, String configLocation) { return createFromModel(baseAddress, cls, modelRef, Collections.emptyList(), configLocation); }
/** * Creates a proxy using user resource model * @param baseAddress baseAddress * @param cls proxy class, if not interface then a CGLIB proxy will be created * @param modelBeans model beans * @param configLocation classpath location of the configuration resource * @return typed proxy */ public static <T> T createFromModel(String baseAddress, Class<T> cls, List<UserResource> modelBeans, String configLocation) { return createFromModel(baseAddress, cls, modelBeans, Collections.emptyList(), configLocation); }
/** * Old REST client uses old REST service */ public void useOldRESTService() throws Exception { List<Object> providers = createJAXRSProviders(); com.example.customerservice.CustomerService customerService = JAXRSClientFactory .createFromModel("http://localhost:" + port + "/examples/direct/rest", com.example.customerservice.CustomerService.class, "classpath:/model/CustomerService-jaxrs.xml", providers, null); System.out.println("Using old RESTful CustomerService with old client"); customer.v1.Customer customer = createOldCustomer("Smith Old REST"); customerService.updateCustomer(customer); customer = customerService.getCustomerByName("Smith Old REST"); printOldCustomerDetails(customer); }
/** * New REST client uses new REST service */ public void useNewRESTService(String address) throws Exception { List<Object> providers = createJAXRSProviders(); org.customer.service.CustomerService customerService = JAXRSClientFactory .createFromModel(address, org.customer.service.CustomerService.class, "classpath:/model/CustomerService-jaxrs.xml", providers, null); System.out.println("Using new RESTful CustomerService with new client"); customer.v2.Customer customer = createNewCustomer("Smith New REST"); customerService.updateCustomer(customer); customer = customerService.getCustomerByName("Smith New REST"); printNewCustomerDetails(customer); }
/** * Old REST client uses new REST service with the * redirection to the new endpoint and transformation * on the server side */ public void useNewRESTServiceWithOldClientAndRedirection() throws Exception { List<Object> providers = createJAXRSProviders(); com.example.customerservice.CustomerService customerService = JAXRSClientFactory .createFromModel("http://localhost:" + port + "/examples/old/rest-endpoint", com.example.customerservice.CustomerService.class, "classpath:/model/CustomerService-jaxrs.xml", providers, null); System.out.println("Using new RESTful CustomerService with old client and the redirection"); customer.v1.Customer customer = createOldCustomer("Smith Old to New REST With Redirection"); customerService.updateCustomer(customer); customer = customerService.getCustomerByName("Smith Old to New REST With Redirection"); printOldCustomerDetails(customer); }
.createFromModel("http://localhost:" + port + "/services/jaxrs", CustomerService.class, "classpath:/data/model/CustomerService-jaxrs.xml", providers, null);
@Test public void testGetBooksUserModelInterface() throws Exception { BookStoreNoAnnotationsInterface proxy = JAXRSClientFactory.createFromModel("http://localhost:" + PORT + "/usermodel2", BookStoreNoAnnotationsInterface.class, "classpath:org/apache/cxf/systest/jaxrs/resources/resources2.xml", null); Book book = new Book("From Model", 1L); List<Book> books = new ArrayList<>(); books.add(book); books = proxy.getBooks(books); assertEquals(1, books.size()); assertNotSame(book, books.get(0)); assertEquals("From Model", books.get(0).getName()); }
@Test public void testUserModelInterfaceOneWay() throws Exception { BookStoreNoAnnotationsInterface proxy = JAXRSClientFactory.createFromModel("http://localhost:" + PORT + "/usermodel2", BookStoreNoAnnotationsInterface.class, "classpath:org/apache/cxf/systest/jaxrs/resources/resources2.xml", null); proxy.pingBookStore(); assertEquals(202, WebClient.client(proxy).getResponse().getStatus()); }
/** * New REST client uses old REST service */ public void useOldRESTServiceWithNewClient() throws Exception { List<Object> providers = createJAXRSProviders(); org.customer.service.CustomerService customerService = JAXRSClientFactory .createFromModel("http://localhost:" + port + "/examples/direct/rest", org.customer.service.CustomerService.class, "classpath:/model/CustomerService-jaxrs.xml", providers, null); // The outgoing new Customer data needs to be transformed for // the old service to understand it and the response from the old service // needs to be transformed for this new client to understand it. ClientConfiguration config = WebClient.getConfig(customerService); addTransformInterceptors(config.getInInterceptors(), config.getOutInterceptors(), true); System.out.println("Using old RESTful CustomerService with new client"); customer.v2.Customer customer = createNewCustomer("Smith New to Old REST"); customerService.updateCustomer(customer); customer = customerService.getCustomerByName("Smith New to Old REST"); printNewCustomerDetails(customer); }
/** * Old REST client uses new REST service */ public void useNewRESTServiceWithOldClient() throws Exception { List<Object> providers = createJAXRSProviders(); com.example.customerservice.CustomerService customerService = JAXRSClientFactory .createFromModel("http://localhost:" + port + "/examples/direct/new-rest", com.example.customerservice.CustomerService.class, "classpath:/model/CustomerService-jaxrs.xml", providers, null); // The outgoing old Customer data needs to be transformed for // the new service to understand it and the response from the new service // needs to be transformed for this old client to understand it. ClientConfiguration config = WebClient.getConfig(customerService); addTransformInterceptors(config.getInInterceptors(), config.getOutInterceptors(), false); System.out.println("Using new RESTful CustomerService with old Client"); customer.v1.Customer customer = createOldCustomer("Smith Old to New REST"); customerService.updateCustomer(customer); customer = customerService.getCustomerByName("Smith Old to New REST"); printOldCustomerDetails(customer); }
@Test public void testGetBookUserResourceFromProxy() throws Exception { String endpointAddress = "http://localhost:" + PORT + "/the/thebooks6"; BookStoreNoAnnotations bStore = JAXRSClientFactory.createFromModel( endpointAddress, BookStoreNoAnnotations.class, "classpath:/org/apache/cxf/systest/jaxrs/resources/resources.xml", Collections.singletonList(new LongTypeParamConverterProvider()), null); Book b = bStore.getBook(null); assertNotNull(b); assertEquals(123L, b.getId()); assertEquals("CXF in Action", b.getName()); ChapterNoAnnotations proxy = bStore.getBookChapter(123L); ChapterNoAnnotations c = proxy.getItself(); assertNotNull(c); assertEquals(1, c.getId()); assertEquals("chapter 1", c.getTitle()); }