@Override public Mono<ClientHttpResponse> connect(HttpMethod method, URI uri, Function<? super ClientHttpRequest, Mono<Void>> requestCallback) { if (!uri.isAbsolute()) { return Mono.error(new IllegalArgumentException("URI is not absolute: " + uri)); } if (!this.httpClient.isStarted()) { try { this.httpClient.start(); } catch (Exception ex) { return Mono.error(ex); } } JettyClientHttpRequest clientHttpRequest = new JettyClientHttpRequest( this.httpClient.newRequest(uri).method(method.toString()), this.bufferFactory); return requestCallback.apply(clientHttpRequest).then(Mono.from( clientHttpRequest.getReactiveRequest().response((response, chunks) -> { Flux<DataBuffer> content = Flux.from(chunks).map(this::toDataBuffer); return Mono.just(new JettyClientHttpResponse(response, content)); }))); }
@Override public Mono<ClientHttpResponse> connect(HttpMethod method, URI uri, Function<? super ClientHttpRequest, Mono<Void>> requestCallback) { if (!uri.isAbsolute()) { return Mono.error(new IllegalArgumentException("URI is not absolute: " + uri)); } if (!this.httpClient.isStarted()) { try { this.httpClient.start(); } catch (Exception ex) { return Mono.error(ex); } } JettyClientHttpRequest clientHttpRequest = new JettyClientHttpRequest( this.httpClient.newRequest(uri).method(method.toString()), this.bufferFactory); return requestCallback.apply(clientHttpRequest).then(Mono.from( clientHttpRequest.getReactiveRequest().response((response, chunks) -> { Flux<DataBuffer> content = Flux.from(chunks).map(this::toDataBuffer); return Mono.just(new JettyClientHttpResponse(response, content)); }))); }
public JettyClientEngine(final HttpClient client) { if (!client.isStarted()) { try { client.start(); } catch (Exception e) { throw new RuntimeException(e); } } this.client = client; }
public static boolean isConnected() { if(client == null) { return false; } return client.isStarted(); }
private static void startHttpClient(HttpClient client) { if (!client.isStarted()) { try { client.start(); } catch (Exception e) { logger.warn("Cannot start HttpClient!", e); } } }
BlockingProxyServlet(ProxyServletService service) { super(); this.service = service; if (!httpClient.isStarted()) { try { httpClient.start(); } catch (Exception e) { logger.warn("Cannot start HttpClient!", e); } } }
BlockingProxyServlet(ProxyServletService service) { super(); this.service = service; if (!httpClient.isStarted()) { try { httpClient.start(); } catch (Exception e) { logger.warn("Cannot start HttpClient!", e); } } }
/** * @param byteBufferPool the {@link ByteBufferPool} of this {@link HttpClient} */ public void setByteBufferPool(ByteBufferPool byteBufferPool) { if (isStarted()) LOG.warn("Calling setByteBufferPool() while started is deprecated"); updateBean(this.byteBufferPool, byteBufferPool); this.byteBufferPool = byteBufferPool; }
/** * @param executor the {@link Executor} of this {@link HttpClient} */ public void setExecutor(Executor executor) { if (isStarted()) LOG.warn("Calling setExecutor() while started is deprecated"); updateBean(this.executor, executor); this.executor = executor; }
/** * @param scheduler the {@link Scheduler} of this {@link HttpClient} */ public void setScheduler(Scheduler scheduler) { if (isStarted()) LOG.warn("Calling setScheduler() while started is deprecated"); updateBean(this.scheduler, scheduler); this.scheduler = scheduler; }
/** * @param resolver the {@link SocketAddressResolver} of this {@link HttpClient} */ public void setSocketAddressResolver(SocketAddressResolver resolver) { if (isStarted()) LOG.warn("Calling setSocketAddressResolver() while started is deprecated"); updateBean(this.resolver, resolver); this.resolver = resolver; }
/** * This is a special case where the httpClient (jetty) is created due to the need for certificate pinning. * If ceritificate pinning is needed, please refer to {@code TrustManagerProvider}. The http client is * created, used and then shutdown immediately after use. There is little reason to cache the client/ connections * because oauth requests are short; and it may take hours/ days before the next request is needed. * * @param tokenUrl access token url * @return http client. This http client * @throws OAuthException If any exception is thrown while starting the http client. * @see TrustManagerProvider */ private HttpClient createHttpClient(String tokenUrl) throws OAuthException { HttpClient httpClient = httpClientFactory.createHttpClient(HTTP_CLIENT_CONSUMER_NAME, tokenUrl); if (!httpClient.isStarted()) { try { AccessController.doPrivileged((PrivilegedExceptionAction<@Nullable Void>) () -> { httpClient.start(); return null; }); } catch (Exception e) { throw new OAuthException("Exception while starting httpClient, tokenUrl: " + tokenUrl, e); } } return httpClient; }
public void returnIdleConnection(AbstractHttpConnection connection) { // TODO work out the real idle time; long idleForMs = connection.getEndPoint() != null ? connection.getEndPoint().getMaxIdleTime() : -1; connection.onIdleExpired(idleForMs); boolean startConnection = false; boolean remove = false; synchronized (this) { _idleConnections.remove(connection); _connections.remove(connection); if (_exchanges.isEmpty()) remove=_client.isRemoveIdleDestinations() && ( _cookies==null || _cookies.isEmpty() ) &&_connections.isEmpty() && _idleConnections.isEmpty(); else if (_client.isStarted()) startConnection = true; } if (startConnection) startNewConnection(); if (remove) _client.removeDestination(this); }
if (!_exchanges.isEmpty() && _client.isStarted()) startConnection = true;
@Override public Mono<ClientHttpResponse> connect(HttpMethod method, URI uri, Function<? super ClientHttpRequest, Mono<Void>> requestCallback) { if (!uri.isAbsolute()) { return Mono.error(new IllegalArgumentException("URI is not absolute: " + uri)); } if (!this.httpClient.isStarted()) { try { this.httpClient.start(); } catch (Exception ex) { return Mono.error(ex); } } JettyClientHttpRequest clientHttpRequest = new JettyClientHttpRequest( this.httpClient.newRequest(uri).method(method.toString()), this.bufferFactory); return requestCallback.apply(clientHttpRequest).then(Mono.from( clientHttpRequest.getReactiveRequest().response((response, chunks) -> { Flux<DataBuffer> content = Flux.from(chunks).map(this::toDataBuffer); return Mono.just(new JettyClientHttpResponse(response, content)); }))); }
@Override public Mono<ClientHttpResponse> connect(HttpMethod method, URI uri, Function<? super ClientHttpRequest, Mono<Void>> requestCallback) { if (!uri.isAbsolute()) { return Mono.error(new IllegalArgumentException("URI is not absolute: " + uri)); } if (!this.httpClient.isStarted()) { try { this.httpClient.start(); } catch (Exception ex) { return Mono.error(ex); } } JettyClientHttpRequest clientHttpRequest = new JettyClientHttpRequest( this.httpClient.newRequest(uri).method(method.toString()), this.bufferFactory); return requestCallback.apply(clientHttpRequest).then(Mono.from( clientHttpRequest.getReactiveRequest().response((response, chunks) -> { Flux<DataBuffer> content = Flux.from(chunks).map(this::toDataBuffer); return Mono.just(new JettyClientHttpResponse(response, content)); }))); }
while(!httpClient.isStarted() && !httpClient.isFailed()) { Thread.sleep(100);