Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
¿Es posible cancelar la solicitud http [GET, POST, etc.] en HttpAsynClient desde HttpClient-5.x?

Estoy usando org.apache.hc.client5.http.impl.async.HttpAsyncClients.create() para crear org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient para mis solicitudes HTTP/2. Estoy buscando alguna funcionalidad para abortar la solicitud después de leer cierta cantidad de datos del canal de socket.

probé con el método cancel (mayInterruptIfRunning) de la instancia de Future. Pero después de cancelarlo, no puedo obtener los encabezados de respuesta y el contenido descargado.

 Future<SimpleHttpResponse> future = null; CloseableHttpAsyncClient httpClient = null; try { httpClient = httpAsyncClientBuilder.build(); httpClient.start(); future = httpClient.execute(target, asyncRequestProducer, SimpleResponseConsumer.create(), null, this.httpClientContext, this); future.get(10, TimeUnit.SECONDS); } catch (Exception ex) { ex.printStackTrace(); } finally { httpClient.close(CloseMode.GRACEFUL); }

¿Hay alguna otra forma de lograr esto con httpclient-5.x?

Gracias por adelantado.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Por supuesto que es. Pero debe implementar su propio consumidor de respuesta personalizado que pueda devolver un contenido de mensaje parcial

 try (CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault()) { httpClient.start(); final Future<Void> future = httpClient.execute( new BasicRequestProducer(Method.GET, new URI("http://httpbin.org/")), new AbstractCharResponseConsumer<Void>() { @Override protected void start( final HttpResponse response, final ContentType contentType) throws HttpException, IOException { System.out.println(response.getCode()); } @Override protected int capacityIncrement() { return Integer.MAX_VALUE; } @Override protected void data(final CharBuffer src, final boolean endOfStream) throws IOException { } @Override protected Void buildResult() throws IOException { return null; } @Override public void releaseResources() { } }, null, null); try { future.get(1, TimeUnit.SECONDS); } catch (TimeoutException ex) { future.cancel(true); } }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!