/** * Creates a proxy, baseURI will be set to Client currentURI * * @param client Client instance * @param cls proxy class, if not interface then a CGLIB proxy will be created * @return typed proxy */ public static <T> T fromClient(Client client, Class<T> cls) { return fromClient(client, cls, false); }
/** * Creates a proxy, baseURI will be set to Client currentURI * * @param client Client instance * @param cls proxy class, if not interface then a CGLIB proxy will be created * @return typed proxy */ public static <T> T fromClient(Client client, Class<T> cls) { return fromClient(client, cls, false); }
/** * Creates a proxy, baseURI will be set to Client currentURI * * @param client Client instance * @param cls proxy class, if not interface then a CGLIB proxy will be created * @return typed proxy */ public static <T> T fromClient(Client client, Class<T> cls) { return fromClient(client, cls, false); }
/** * Creates a JAXRS web client for the given JAXRS client */ @Override protected <T> T createWebClient(Class<T> clientType) { List<Object> providers = WebClients.createProviders(); providers.add(new Authenticator()); WebClient webClient = WebClient.create(address, providers); disableSslChecks(webClient); //configureUserAndPassword(webClient, username, password); return JAXRSClientFactory.fromClient(webClient, clientType); }
/** * Creates a JAXRS web client for the given JAXRS client */ protected <T> T createWebClient(Class<T> clientType, String hubotUrl) { List<Object> providers = createProviders(); WebClient webClient = WebClient.create(hubotUrl, providers); disableSslChecks(webClient); configureUserAndPassword(webClient, username, password); return JAXRSClientFactory.fromClient(webClient, clientType); }
/** * Creates a JAXRS web client for the given JAXRS client */ @Override protected <T> T createWebClient(Class<T> clientType) { List<Object> providers = WebClients.createProviders(); WebClient webClient = WebClient.create(address, providers); disableSslChecks(webClient); configureUserAndPassword(webClient, username, password); return JAXRSClientFactory.fromClient(webClient, clientType); }
/** * Creates a JAXRS web client for the given JAXRS client */ @Override protected <T> T createWebClient(Class<T> clientType) { List<Object> providers = WebClients.createProviders(); WebClient webClient = WebClient.create(address, providers); disableSslChecks(webClient); configureAuthorization(webClient, username, authorizationType, authorization); return JAXRSClientFactory.fromClient(webClient, clientType); }
/** * Creates a JAXRS web client for the given JAXRS client */ @Override protected <T> T createWebClient(Class<T> clientType) { List<Object> providers = WebClients.createProviders(); WebClient webClient = WebClient.create(address, providers); disableSslChecks(webClient); configureAuthorization(webClient, username, authorizationType, authorization); return JAXRSClientFactory.fromClient(webClient, clientType); }
/** * Creates a JAXRS web client for the given JAXRS client */ @Override protected <T> T createWebClient(Class<T> clientType) { List<Object> providers = WebClients.createProviders(); if (Strings.isNotBlank(privateToken)) { providers.add(createPrivateTokenFilter(privateToken)); } WebClient webClient = WebClient.create(address, providers); disableSslChecks(webClient); configureUserAndPassword(webClient, username, password); return JAXRSClientFactory.fromClient(webClient, clientType); }
private void runProxies(BookStore proxy, int numberOfClients, boolean threadSafe, boolean stateCanBeChanged) throws Exception { ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 5, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10)); CountDownLatch startSignal = new CountDownLatch(1); CountDownLatch doneSignal = new CountDownLatch(numberOfClients); for (int i = 1; i <= numberOfClients; i++) { // here we do a double copy : from proxy to web client and back to proxy BookStore bs = !threadSafe ? JAXRSClientFactory.fromClient( WebClient.fromClient(WebClient.client(proxy)), BookStore.class) : proxy; String bookName = stateCanBeChanged ? Integer.toString(i) : "TheBook"; String bookHeader = stateCanBeChanged ? "value" + i : "CustomValue"; executor.execute(new RootProxyWorker(bs, bookName, bookHeader, startSignal, doneSignal, stateCanBeChanged)); } startSignal.countDown(); doneSignal.await(60, TimeUnit.SECONDS); executor.shutdownNow(); assertEquals("Not all invocations have completed", 0, doneSignal.getCount()); }
@Test public void testGetBookSubresourceWebClientProxyBean() throws Exception { WebClient client = WebClient.create("http://localhost:" + PORT + "/test/services/rest"); client.type(MediaType.TEXT_PLAIN_TYPE) .accept(MediaType.APPLICATION_XML_TYPE, MediaType.TEXT_XML_TYPE); BookStoreJaxrsJaxws proxy = JAXRSClientFactory.fromClient(client, BookStoreJaxrsJaxws.class, true); doTestSubresource(proxy); BookStoreJaxrsJaxws proxy2 = JAXRSClientFactory.fromClient( WebClient.client(proxy), BookStoreJaxrsJaxws.class); doTestSubresource(proxy2); }
@Test public void testGetBookSubresourceWebClientProxy2() throws Exception { WebClient client = WebClient.create("http://localhost:" + PORT + "/test/services/rest/bookstore") .path("/books/378"); client.type(MediaType.TEXT_PLAIN_TYPE).accept(MediaType.APPLICATION_XML_TYPE); BookSubresource proxy = JAXRSClientFactory.fromClient(client, BookSubresource.class); Book b = proxy.getTheBook2("CXF ", "in ", "Acti", "on ", "- 3", "7", "8"); assertEquals(378, b.getId()); assertEquals("CXF in Action - 378", b.getName()); }
@Test public void testGetBook123WebClientToProxy() throws Exception { WebClient wc = WebClient.create("https://localhost:" + PORT, CLIENT_CONFIG_FILE1); wc.path("/bookstore/securebooks/123").accept(MediaType.APPLICATION_XML_TYPE); Book b = wc.get(Book.class); assertEquals(123, b.getId()); wc.back(true); BookStore bs = JAXRSClientFactory.fromClient(wc, BookStore.class); Book b2 = bs.getSecureBook("123"); assertEquals(b2.getId(), 123); }