-
Notifications
You must be signed in to change notification settings - Fork 461
feat: Introduce google-http-client-apache-v5 (Apache Client/Core 5.x) #1960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gcf-merge-on-green
merged 54 commits into
main
from
google-http-client-apache-v3-httpclient-5.x
Aug 21, 2024
Merged
Changes from 5 commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
8efb1b1
chore: add base google-http-client-apache-v3
diegomarquezp 6c0b7ed
exclude core 4.x
diegomarquezp a4d5c06
chore: demo usage of Apache HTTP Client 5.x
diegomarquezp 7d7dd3a
implement transport using `classic` implementation
diegomarquezp 413ccae
remove author comments
diegomarquezp 6cde3cb
move test code to test class
diegomarquezp 27836c7
remove redundant instanceof
diegomarquezp 1b17559
use interface
diegomarquezp 6b6b7e3
prepare for production
diegomarquezp 06971ce
expose interfaces instead of implementation classes
diegomarquezp cb9c2c8
use executeOpen()
diegomarquezp 68a4c62
rename to google-http-client-apache-v5
diegomarquezp e831876
format
diegomarquezp b23f1f7
format
diegomarquezp 46128b2
remove @since annotations
diegomarquezp f9216de
remove unused beta annotatoins
diegomarquezp 4950aa5
initial re-addition of unit tests in transport class
diegomarquezp 8b75159
rough re-implementation of tests
diegomarquezp e8ccf0b
rename default client builder in transport
diegomarquezp 84e3d02
use ModalCloseable to check if we can close() the client
diegomarquezp 50ed0db
fix javadoc links
diegomarquezp dbbdc43
use ClassicHttpResponse
diegomarquezp 871901c
use concrete exception
diegomarquezp afdc7f1
rename apache 5 mocks
diegomarquezp b3c57d0
rename v2 folder
diegomarquezp d6c4202
fix dependencies
diegomarquezp a7e347a
confirm that any type of requests can have content set
diegomarquezp 4bc7b12
remove TODO
diegomarquezp ff1cba2
execute() with response handler
diegomarquezp c5fcd7f
adapt for java7
diegomarquezp bd7c990
move mock class to test flder
diegomarquezp aa3cc73
Revert "move mock class to test flder"
diegomarquezp 36bf5e8
Revert "adapt for java7"
diegomarquezp ac8e24b
Revert "execute() with response handler"
diegomarquezp 45f8142
make users close the response
diegomarquezp 25d24be
add input stream wrapper
diegomarquezp d7187d8
add input stream test
diegomarquezp 5f249d7
move deps to test scoped
diegomarquezp ca714dc
remove reflect-config.json
diegomarquezp e472ce6
fix dependencies
diegomarquezp 663e7fc
rename project variable to apache-httpxxx-4
diegomarquezp fe1ef0a
exclude google apache 5 client from java 7 tests
diegomarquezp e87f1fb
Merge remote-tracking branch 'origin/google-http-client-apache-v3-htt…
diegomarquezp ff5c209
add javadoc for Apache5ResponseContent
diegomarquezp b4049e0
close() response only, emit getContent() exception
diegomarquezp de87435
format
diegomarquezp 5485b46
implement all methods of InputStream
diegomarquezp 86e70aa
improve javadoc of wrapped stream
diegomarquezp e21f993
add test to confirm the response is close()d
diegomarquezp d8c7f67
update docs to offer Apache5Http.*
diegomarquezp ec0ebb3
exclude apache 4 from test dependencies
diegomarquezp 1cd91ea
throw IOException when disconnect()ing
diegomarquezp 5da2b32
remove convenience integration tests
diegomarquezp 5fd5dd1
fix deps
diegomarquezp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.google.http-client</groupId> | ||
<artifactId>google-http-client-parent</artifactId> | ||
<version>1.44.3-SNAPSHOT</version><!-- {x-version-update:google-http-client-parent:current} --> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<artifactId>google-http-client-apache-v3</artifactId> | ||
<version>1.44.3-SNAPSHOT</version><!-- {x-version-update:google-http-client-apache-v3:current} --> | ||
<name>Apache HTTP transport v3 for the Google HTTP Client Library for Java.</name> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
<configuration> | ||
<links> | ||
<link>https://download.oracle.com/javase/7/docs/api/</link> | ||
</links> | ||
<doctitle>${project.name} ${project.version}</doctitle> | ||
<windowtitle>${project.artifactId} ${project.version}</windowtitle> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-source-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>build-helper-maven-plugin</artifactId> | ||
<version>3.3.0</version> | ||
<executions> | ||
<execution> | ||
<id>add-test-source</id> | ||
<phase>generate-test-sources</phase> | ||
<goals> | ||
<goal>add-test-source</goal> | ||
</goals> | ||
<configuration> | ||
<sources> | ||
<source>target/generated-test-sources</source> | ||
</sources> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> | ||
<manifestEntries> | ||
<Automatic-Module-Name>com.google.api.client.http.apache.v3</Automatic-Module-Name> | ||
</manifestEntries> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>maven-bundle-plugin</artifactId> | ||
<version>5.1.9</version> | ||
<executions> | ||
<execution> | ||
<id>bundle-manifest</id> | ||
<phase>process-classes</phase> | ||
<goals> | ||
<goal>manifest</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.13.0</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.http-client</groupId> | ||
<artifactId>google-http-client</artifactId> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpcore</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.apis</groupId> | ||
<artifactId>google-api-services-cloudresourcemanager</artifactId> | ||
<version>v3-rev20240310-2.0.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents.client5</groupId> | ||
<artifactId>httpclient5</artifactId> | ||
<version>5.3.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents.core5</groupId> | ||
<artifactId>httpcore5-h2</artifactId> | ||
<version>5.2.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.http-client</groupId> | ||
<artifactId>google-http-client-gson</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.api</groupId> | ||
<artifactId>gapic-generator-java</artifactId> | ||
<version>2.28.0</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
73 changes: 73 additions & 0 deletions
73
...lient-apache-v3/src/main/java/com/google/api/client/http/apache/v3/ApacheHttpRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.google.api.client.http.apache.v3; | ||
|
||
import com.google.api.client.http.LowLevelHttpRequest; | ||
import com.google.api.client.http.LowLevelHttpResponse; | ||
import java.io.IOException; | ||
import java.util.concurrent.TimeUnit; | ||
import org.apache.hc.client5.http.config.RequestConfig; | ||
import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase; | ||
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; | ||
import org.apache.hc.core5.util.Timeout; | ||
|
||
final class ApacheHttpRequest extends LowLevelHttpRequest { | ||
burkedavison marked this conversation as resolved.
Show resolved
Hide resolved
burkedavison marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private final HttpUriRequestBase request; | ||
|
||
private RequestConfig.Builder requestConfig; | ||
burkedavison marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private CloseableHttpClient httpClient; | ||
|
||
ApacheHttpRequest(CloseableHttpClient httpClient, HttpUriRequestBase request) { | ||
this.httpClient = httpClient; | ||
this.request = request; | ||
// disable redirects as google-http-client handles redirects | ||
this.requestConfig = | ||
RequestConfig.custom() | ||
.setRedirectsEnabled(false) | ||
; | ||
} | ||
|
||
@Override | ||
public void addHeader(String name, String value) { | ||
request.addHeader(name, value); | ||
} | ||
|
||
@Override | ||
public void setTimeout(int connectTimeout, int readTimeout) throws IOException { | ||
// TODO: these methods are deprecated - we will need a more up-to-date way of setting timeouts | ||
// on existing requests. Also, since we can't control the lower level socket configuration, | ||
// we indirectly set a read timeout via ResponseTimeout | ||
requestConfig | ||
.setConnectTimeout(Timeout.of(connectTimeout, TimeUnit.MILLISECONDS)) | ||
diegomarquezp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.setResponseTimeout(Timeout.of(readTimeout, TimeUnit.MILLISECONDS)); | ||
} | ||
|
||
@Override | ||
public LowLevelHttpResponse execute() throws IOException { | ||
if (getStreamingContent() != null) { | ||
// Preconditions.checkState( | ||
// request instanceof HttpEntityEnclosingRequest, | ||
// "Apache HTTP client does not support %s requests with content.", | ||
// request.getRequestLine().getMethod()); | ||
ContentEntity entity = new ContentEntity(getContentLength(), getStreamingContent(), | ||
getContentType(), getContentEncoding()); | ||
request.setEntity(entity); | ||
} | ||
request.setConfig(requestConfig.build()); | ||
return new ApacheHttpResponse(request, httpClient.execute(request)); | ||
diegomarquezp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
...ient-apache-v3/src/main/java/com/google/api/client/http/apache/v3/ApacheHttpResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.google.api.client.http.apache.v3; | ||
|
||
import com.google.api.client.http.LowLevelHttpResponse; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase; | ||
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; | ||
import org.apache.hc.core5.http.Header; | ||
import org.apache.hc.core5.http.HttpEntity; | ||
import org.apache.hc.core5.http.message.StatusLine; | ||
|
||
final class ApacheHttpResponse extends LowLevelHttpResponse { | ||
|
||
private final HttpUriRequestBase request; | ||
private final CloseableHttpResponse response; | ||
private final Header[] allHeaders; | ||
|
||
ApacheHttpResponse(HttpUriRequestBase request, CloseableHttpResponse response) { | ||
this.request = request; | ||
this.response = response; | ||
allHeaders = response.getHeaders(); | ||
} | ||
|
||
@Override | ||
public int getStatusCode() { | ||
return response.getCode(); | ||
} | ||
|
||
@Override | ||
public InputStream getContent() throws IOException { | ||
HttpEntity entity = response.getEntity(); | ||
return entity == null ? null : entity.getContent(); | ||
} | ||
|
||
@Override | ||
public String getContentEncoding() { | ||
HttpEntity entity = response.getEntity(); | ||
if (entity != null) { | ||
return entity.getContentEncoding(); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public long getContentLength() { | ||
HttpEntity entity = response.getEntity(); | ||
return entity == null ? -1 : entity.getContentLength(); | ||
} | ||
|
||
@Override | ||
public String getContentType() { | ||
HttpEntity entity = response.getEntity(); | ||
if (entity != null) { | ||
return entity.getContentType(); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getReasonPhrase() { | ||
return response.getReasonPhrase(); | ||
} | ||
|
||
@Override | ||
public String getStatusLine() { | ||
return new StatusLine(response).toString(); | ||
} | ||
|
||
public String getHeaderValue(String name) { | ||
return response.getLastHeader(name).getValue(); | ||
} | ||
|
||
@Override | ||
public int getHeaderCount() { | ||
return allHeaders.length; | ||
} | ||
|
||
@Override | ||
public String getHeaderName(int index) { | ||
return allHeaders[index].getName(); | ||
} | ||
|
||
@Override | ||
public String getHeaderValue(int index) { | ||
return allHeaders[index].getValue(); | ||
} | ||
|
||
/** | ||
* Aborts execution of the request. | ||
* | ||
* @since 1.30 | ||
*/ | ||
@Override | ||
public void disconnect() { | ||
request.abort(); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.