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()); }
private WebTarget newWebTarget(UriBuilder newBuilder) { checkClosed(); boolean complete = false; if (targetClient != null) { try { newBuilder.build(); complete = true; } catch (IllegalArgumentException ex) { // the builder still has unresolved vars } } if (!complete) { return new WebTargetImpl(newBuilder, getConfiguration()); } WebClient newClient = WebClient.fromClient(targetClient); return new WebTargetImpl(newBuilder, getConfiguration(), newClient); }
@Override public Builder request() { checkClosed(); initTargetClientIfNeeded(); ClientProviderFactory pf = ClientProviderFactory.getInstance(WebClient.getConfig(targetClient).getEndpoint()); List<Object> providers = new LinkedList<Object>(); Configuration cfg = configImpl.getConfiguration(); for (Object p : cfg.getInstances()) { if (!(p instanceof Feature)) { Map<Class<?>, Integer> contracts = cfg.getContracts(p.getClass()); if (contracts == null || contracts.isEmpty()) { providers.add(p); } else { providers.add(new FilterProviderInfo<Object>(p, pf.getBus(), contracts)); } } } pf.setUserProviders(providers); WebClient.getConfig(targetClient) .getRequestContext() .putAll(getConfiguration().getProperties()); WebClient.getConfig(targetClient) .getRequestContext() .put(Client.class.getName(), ClientImpl.this); WebClient.getConfig(targetClient) .getRequestContext() .put(Configuration.class.getName(), getConfiguration()); // TLS TLSClientParameters tlsParams = secConfig.getTlsClientParams(); if (tlsParams.getSSLSocketFactory() != null || tlsParams.getTrustManagers() != null) { WebClient.getConfig(targetClient).getHttpConduit().setTlsClientParameters(tlsParams); } // start building the invocation return new InvocationBuilderImpl(WebClient.fromClient(targetClient)); }
private void runWebClients( WebClient client, 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++) { WebClient wc = !threadSafe ? WebClient.fromClient(client) : client; String bookName = stateCanBeChanged ? Integer.toString(i) : "TheBook"; String bookHeader = stateCanBeChanged ? "value" + i : "CustomValue"; executor.execute( new WebClientWorker( wc, bookName, bookHeader, startSignal, doneSignal, stateCanBeChanged)); } startSignal.countDown(); doneSignal.await(60, TimeUnit.SECONDS); executor.shutdownNow(); assertEquals("Not all invocations have completed", 0, doneSignal.getCount()); }