private SchemeRegistry createRegistry(CouchDbProperties properties) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, CertificateException, IOException, UnrecoverableKeyException { SchemeRegistry registry = new SchemeRegistry(); if("https".equals(properties.getProtocol())) { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new MySSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); registry.register(new Scheme(properties.getProtocol(), sf, properties.getPort())); } else { registry.register(new Scheme(properties.getProtocol(), PlainSocketFactory.getSocketFactory(), properties.getPort())); } return registry; }
private Registry<ConnectionSocketFactory> createRegistry(CouchDbProperties props) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException { RegistryBuilder<ConnectionSocketFactory> registry = RegistryBuilder .<ConnectionSocketFactory> create(); if("https".equals(props.getProtocol())) { SSLContext sslcontext = SSLContexts.custom() .loadTrustMaterial(null, new TrustStrategy(){ public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }).build(); return registry.register("https", new SSLConnectionSocketFactory(sslcontext, new NoopHostnameVerifier())).build(); } else { return registry.register("http", PlainConnectionSocketFactory.INSTANCE).build(); } }
CouchDbClientBase(CouchDbConfig config) { final CouchDbProperties props = config.getProperties(); this.httpClient = createHttpClient(props); this.gson = initGson(new GsonBuilder()); this.host = new HttpHost(props.getHost(), props.getPort(), props.getProtocol()); final String path = props.getPath() != null ? props.getPath() : ""; this.baseURI = buildUri().scheme(props.getProtocol()).host(props.getHost()).port(props.getPort()).path("/").path(path).build(); this.dbURI = buildUri(baseURI).path(props.getDbName()).path("/").build(); this.context = new CouchDbContext(this, props); this.design = new CouchDbDesign(this); }
public CouchDbConfig(CouchDbProperties dbProperties) { assertNotEmpty(dbProperties, "Properties"); assertNotEmpty(dbProperties.getDbName(), "Database"); assertNotEmpty(dbProperties.getProtocol(), "Protocol"); assertNotEmpty(dbProperties.getHost(), "Host"); assertNotEmpty(dbProperties.getPort(), "Port"); this.dbProperties = dbProperties; }