Apache HTTP client does not support GET requests with content

Aperta
#1,442 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
java

Direzione di ricerca

Inizia da google-http-client-apache-v2/src/main/java/com/google/api/client/http/apache/v2/ApacheHttpRequest.java alla precondizione menzionata nel report, quindi confronta la gestione di GET in NetHttpTransport.java. Riproduci l’esempio fornito di ImagesClient con ApacheHttpTransport e verifica che la gestione del contenuto di GET non fallisca più, mentre PATCH rimane supportato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

type: feature request

I'm trying to update a resource with google-cloud-compute-1.3.0, the client does this using HTTP PATCH. This is not supported with the default NetHttpTransport (#1316): https://github.com/googleapis/google-http-java-client/blob/7ebc6ca7807424b6372f1b52ac7b129752a9acf5/google-http-client/src/main/java/com/google/api/client/http/javanet/NetHttpTransport.java#L68-L76

To workaround that, I set the HTTP transport to ApacheHttpTransport, but then other requests fail with

Caused by: java.lang.IllegalStateException: Apache HTTP client does not support GET requests with content.
	at com.google.common.base.Preconditions.checkState(Preconditions.java:469)
	at com.google.api.client.util.Preconditions.checkState(Preconditions.java:113)
	at com.google.api.client.http.apache.v2.ApacheHttpRequest.execute(ApacheHttpRequest.java:60)
	at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1012)
	at com.google.api.gax.httpjson.HttpRequestRunnable.run(HttpRequestRunnable.java:143)
	... 6 more

This precondition is run when getContentStreaming() != null: https://github.com/googleapis/google-http-java-client/blob/7ebc6ca7807424b6372f1b52ac7b129752a9acf5/google-http-client-apache-v2/src/main/java/com/google/api/client/http/apache/v2/ApacheHttpRequest.java#L59-L71
but in this case getContentStreaming() is returning an com.google.api.client.http.EmptyContet due to https://github.com/googleapis/gax-java/pull/648

I think this precondition needs to be relaxed and be in-line with NetHttpTransport, which does support GET requests with non-null getContentStreaming().

Environment details
  1. Specify the API at the beginning of the title. For example, "BigQuery: ...").
    google-cloud-compute-1.3.0
  2. OS type and version: RHEL 8.3
  3. Java version: 11.0.10
  4. google-http-client version(s): 1.39.2
Code example
TransportChannelProvider transportChannelProvider = InstantiatingHttpJsonChannelProvider.newBuilder().setHttpTransport(new ApacheHttpTransport()).build();
ImagesSettings settings = ImagesSettings.newBuilder().setTransportChannelProvider(transportChannelProvider).build();
try (ImagesClient client = ImagesClient.create(settings)) {
    client.list("centos-cloud");
}

Will fail with the stacktrace above. Removing either .setTransportChannelProvider() or .setHttpTransport() (so that it defaults to NetHttpTransport) will fix this issue (but then PATCH doesn't work).

Lingua principale
Java
Stelle
1.4k
Fork
476
Merge medio
10h 47m
PR unite (30g)
3

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di googleapis/google-http-java-client

Tutte le issue di googleapis/google-http-java-client

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.