private WebClient getAccessTokenService() { final JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(oauth2TokenServiceURI.toASCIIString()); bean.setUsername("odatajclient"); bean.setPassword("odatajclient"); return bean.createWebClient() .type(MediaType.APPLICATION_FORM_URLENCODED_TYPE) .accept(MediaType.APPLICATION_JSON_TYPE); }
/** * Build a client proxy, for a specific proxy type. * * @param proxyType proxy type class * @return client proxy stub */ protected <T> T build(Class<T> proxyType) { String address = generateAddress(); T rootResource; // Synchronized on the class to correlate with the scope of clientStaticResources // We want to ensure that the shared bean isn't set concurrently in multiple callers synchronized (ClouderaManagerClientBuilder.class) { JAXRSClientFactoryBean bean = cleanFactory(clientStaticResources.getUnchecked(proxyType)); bean.setAddress(address); if (username != null) { bean.setUsername(username); bean.setPassword(password); } if (enableLogging) { bean.setFeatures(Arrays.<AbstractFeature>asList(new LoggingFeature())); } rootResource = bean.create(proxyType); } boolean isTlsEnabled = address.startsWith("https://"); ClientConfiguration config = WebClient.getConfig(rootResource); HTTPConduit conduit = (HTTPConduit) config.getConduit(); if (isTlsEnabled) { TLSClientParameters tlsParams = new TLSClientParameters(); if (!validateCerts) { tlsParams.setTrustManagers(new TrustManager[] {new AcceptAllTrustManager()}); } else if (trustManagers != null) { tlsParams.setTrustManagers(trustManagers); } tlsParams.setDisableCNCheck(!validateCn); conduit.setTlsClientParameters(tlsParams); } HTTPClientPolicy policy = conduit.getClient(); policy.setConnectionTimeout(connectionTimeoutUnits.toMillis(connectionTimeout)); policy.setReceiveTimeout(receiveTimeoutUnits.toMillis(receiveTimeout)); return rootResource; }
private static JAXRSClientFactoryBean cleanFactory(JAXRSClientFactoryBean bean) { bean.setUsername(null); bean.setPassword(null); bean.setFeatures(Arrays.<AbstractFeature>asList()); return bean; }