/** * Creates an HTTP/HTTPS client. */ public static HttpClient createHttpClient(Env env) { return new HttpClient(PhpVerticleFactory.vertx.createHttpClient()); }
/** Create HttpClient */ public RxHttpClient createHttpClient() { return new RxHttpClient(core.createHttpClient()); }
protected HttpClient createClient(URL url) throws MalformedURLException { // lets create a client HttpClient client = vertx.createHttpClient(); client.setHost(url.getHost()); client.setPort(url.getPort()); return client; }
protected <T> HttpClient createClient(URI url, final Deferred<T> d) { if (url == null) throw new IllegalArgumentException("url is null"); if (!url.isAbsolute()) throw new IllegalArgumentException("url must be absolute"); int port = (url.getPort() > 0) ? url.getPort() : 80; return vertx.createHttpClient() .setHost(url.getHost()) .setPort(port) .setConnectTimeout(CONNECT_TIMEOUT) .exceptionHandler(t -> d.reject(t)); }
private void connect() { int index = this.currentIndex.get(); int oldIndex = index; if (index + 1 == hosts.length) { index = 0; } else { index++; } if (this.currentIndex.compareAndSet(oldIndex, index)) { final URI uri = this.hosts[index]; logger.info("Connecting to ", uri); httpClient = vertx.createHttpClient().setHost(uri.getHost()).setPort(uri.getPort()) .setConnectTimeout(this.timeOutInMilliseconds).setMaxPoolSize(poolSize); httpClient.exceptionHandler(new Handler<Throwable>() { @Override public void handle(Throwable throwable) { if (throwable instanceof ConnectException) { closed.set(true); } else { logger.error(throwable, "Unable to connect to ", uri); } } }); configureSSL(httpClient); closed.set(false); } }
private void connect() { int index = this.currentIndex.get(); int oldIndex = index; if (index + 1 == hosts.length) { index = 0; } else { index++; } if (this.currentIndex.compareAndSet(oldIndex, index)) { final URI uri = this.hosts[index]; logger.info("Connecting to ", uri); httpClient = vertx.createHttpClient().setHost(uri.getHost()).setPort(uri.getPort()) .setConnectTimeout(this.timeOutInMilliseconds).setMaxPoolSize(poolSize); httpClient.exceptionHandler(new Handler<Throwable>() { @Override public void handle(Throwable throwable) { if (throwable instanceof ConnectException) { closed.set(true); } else { logger.error(throwable, "Unable to connect to ", uri); } } }); configureSSL(httpClient); closed.set(false); } }
private void connect() { int index = this.currentIndex.get(); int oldIndex = index; if (index + 1 == hosts.length) { index = 0; } else { index++; } if (this.currentIndex.compareAndSet(oldIndex, index)) { final URI uri = this.hosts[index]; logger.info("Connecting to ", uri); httpClient = vertx.createHttpClient().setHost(uri.getHost()).setPort(uri.getPort()) .setConnectTimeout(this.timeOutInMilliseconds).setMaxPoolSize(poolSize); httpClient.exceptionHandler(new Handler<Throwable>() { @Override public void handle(Throwable throwable) { if (throwable instanceof ConnectException) { closed.set(true); } else { logger.error(throwable, "Unable to connect to ", uri); } } }); configureSSL(httpClient); closed.set(false); } }
protected HttpClient createClient(String scheme, String host, int port) { if (client != null) { throw new IllegalStateException("Client already created"); } client = vertx.createHttpClient(); client.setKeepAlive(false); // Not all servers will allow keep alive connections if (proxyHost != null) { client.setHost(proxyHost); if (proxyPort != 80) { client.setPort(proxyPort); } else { client.setPort(80); } } else { client.setHost(host); client.setPort(port); } if (scheme.equals("https")) { client.setSSL(true); } client.exceptionHandler(new Handler<Throwable>() { public void handle(Throwable t) { end(false); } }); return client; }
@Override public void createMember(RequestContext ctx, ResourceState state, Responder responder) { String path = (String) state.getProperty("path"); String destination = (String) state.getProperty("destination"); String contentType = (String) state.getProperty("content-type"); if (contentType == null) { contentType = "application/json"; } ResourceCodec codec = this.codecManager.getResourceCodec(new MediaType(contentType)); if (codec == null) { responder.internalError("content-type not supported: " + contentType); return; } try { URI destinationUri = new URI(destination); HttpClient httpClient = this.vertx.createHttpClient(); httpClient.setHost(destinationUri.getHost()); httpClient.setPort(destinationUri.getPort()); SecurityContext requestSecurityContext = ctx.securityContext(); HttpSubscription sub = new HttpSubscription(httpClient, path, destinationUri, codec, requestSecurityContext); this.subscriptionManager.addSubscription(sub); responder.resourceCreated(new HttpSubscriptionResource(this, sub)); } catch (URISyntaxException e) { responder.internalError(e.getMessage()); } }