-
Notifications
You must be signed in to change notification settings - Fork 3k
Auth Manager API part 4: RESTClient, HTTPClient #11992
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
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
81b16de
Auth Manager API part 4: RESTClient, HTTPClient
adutra a513a59
review
adutra 4c41c74
remove unnecessary method overrides
adutra 8fbd0b9
initial auth null
adutra f60891e
fix test failure
adutra a3ba582
move call
adutra 1effdbd
revert unnecessary change
adutra 429fb31
add builder method
adutra d4dd7f7
review
adutra 64c5f2e
avoid using EMPTY auth sessions
adutra 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
220 changes: 220 additions & 0 deletions
220
core/src/main/java/org/apache/iceberg/rest/BaseHTTPClient.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,220 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you 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 org.apache.iceberg.rest; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.function.Consumer; | ||
| import java.util.function.Supplier; | ||
| import org.apache.iceberg.rest.HTTPRequest.HTTPMethod; | ||
| import org.apache.iceberg.rest.auth.AuthSession; | ||
| import org.apache.iceberg.rest.responses.ErrorResponse; | ||
|
|
||
| /** | ||
| * A base class for {@link RESTClient} implementations. | ||
| * | ||
| * <p>All methods in {@link RESTClient} are implemented in the same way: first, an {@link | ||
| * HTTPRequest} is {@linkplain #buildRequest(HTTPMethod, String, Map, Map, Object) built from the | ||
| * method arguments}, then {@linkplain #execute(HTTPRequest, Class, Consumer, Consumer) executed}. | ||
| * | ||
| * <p>This allows subclasses to provide a consistent way to execute all requests, regardless of the | ||
| * method or arguments. | ||
| */ | ||
| public abstract class BaseHTTPClient implements RESTClient { | ||
|
|
||
| @Override | ||
| public abstract RESTClient withAuthSession(AuthSession session); | ||
|
|
||
| @Override | ||
| public void head( | ||
| String path, Supplier<Map<String, String>> headers, Consumer<ErrorResponse> errorHandler) { | ||
| HTTPRequest request = buildRequest(HTTPMethod.HEAD, path, null, headers.get(), null); | ||
| execute(request, null, errorHandler, h -> {}); | ||
| } | ||
|
|
||
| @Override | ||
| public void head(String path, Map<String, String> headers, Consumer<ErrorResponse> errorHandler) { | ||
| HTTPRequest request = buildRequest(HTTPMethod.HEAD, path, null, headers, null); | ||
| execute(request, null, errorHandler, h -> {}); | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends RESTResponse> T delete( | ||
| String path, | ||
| Map<String, String> queryParams, | ||
| Class<T> responseType, | ||
| Supplier<Map<String, String>> headers, | ||
| Consumer<ErrorResponse> errorHandler) { | ||
| HTTPRequest request = buildRequest(HTTPMethod.DELETE, path, queryParams, headers.get(), null); | ||
| return execute(request, responseType, errorHandler, h -> {}); | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends RESTResponse> T delete( | ||
| String path, | ||
| Class<T> responseType, | ||
| Supplier<Map<String, String>> headers, | ||
| Consumer<ErrorResponse> errorHandler) { | ||
| HTTPRequest request = buildRequest(HTTPMethod.DELETE, path, null, headers.get(), null); | ||
| return execute(request, responseType, errorHandler, h -> {}); | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends RESTResponse> T delete( | ||
| String path, | ||
| Class<T> responseType, | ||
| Map<String, String> headers, | ||
| Consumer<ErrorResponse> errorHandler) { | ||
| HTTPRequest request = buildRequest(HTTPMethod.DELETE, path, null, headers, null); | ||
| return execute(request, responseType, errorHandler, h -> {}); | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends RESTResponse> T delete( | ||
| String path, | ||
| Map<String, String> queryParams, | ||
| Class<T> responseType, | ||
| Map<String, String> headers, | ||
| Consumer<ErrorResponse> errorHandler) { | ||
| HTTPRequest request = buildRequest(HTTPMethod.DELETE, path, queryParams, headers, null); | ||
| return execute(request, responseType, errorHandler, h -> {}); | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends RESTResponse> T get( | ||
| String path, | ||
| Class<T> responseType, | ||
| Supplier<Map<String, String>> headers, | ||
| Consumer<ErrorResponse> errorHandler) { | ||
| HTTPRequest request = buildRequest(HTTPMethod.GET, path, null, headers.get(), null); | ||
| return execute(request, responseType, errorHandler, h -> {}); | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends RESTResponse> T get( | ||
| String path, | ||
| Class<T> responseType, | ||
| Map<String, String> headers, | ||
| Consumer<ErrorResponse> errorHandler) { | ||
| HTTPRequest request = buildRequest(HTTPMethod.GET, path, null, headers, null); | ||
| return execute(request, responseType, errorHandler, h -> {}); | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends RESTResponse> T get( | ||
| String path, | ||
| Map<String, String> queryParams, | ||
| Class<T> responseType, | ||
| Supplier<Map<String, String>> headers, | ||
| Consumer<ErrorResponse> errorHandler) { | ||
| HTTPRequest request = buildRequest(HTTPMethod.GET, path, queryParams, headers.get(), null); | ||
| return execute(request, responseType, errorHandler, h -> {}); | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends RESTResponse> T get( | ||
| String path, | ||
| Map<String, String> queryParams, | ||
| Class<T> responseType, | ||
| Map<String, String> headers, | ||
| Consumer<ErrorResponse> errorHandler) { | ||
| HTTPRequest request = buildRequest(HTTPMethod.GET, path, queryParams, headers, null); | ||
| return execute(request, responseType, errorHandler, h -> {}); | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends RESTResponse> T post( | ||
| String path, | ||
| RESTRequest body, | ||
| Class<T> responseType, | ||
| Supplier<Map<String, String>> headers, | ||
| Consumer<ErrorResponse> errorHandler) { | ||
| HTTPRequest request = buildRequest(HTTPMethod.POST, path, null, headers.get(), body); | ||
| return execute(request, responseType, errorHandler, h -> {}); | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends RESTResponse> T post( | ||
| String path, | ||
| RESTRequest body, | ||
| Class<T> responseType, | ||
| Supplier<Map<String, String>> headers, | ||
| Consumer<ErrorResponse> errorHandler, | ||
| Consumer<Map<String, String>> responseHeaders) { | ||
| HTTPRequest request = buildRequest(HTTPMethod.POST, path, null, headers.get(), body); | ||
| return execute(request, responseType, errorHandler, responseHeaders); | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends RESTResponse> T post( | ||
| String path, | ||
| RESTRequest body, | ||
| Class<T> responseType, | ||
| Map<String, String> headers, | ||
| Consumer<ErrorResponse> errorHandler, | ||
| Consumer<Map<String, String>> responseHeaders) { | ||
| HTTPRequest request = buildRequest(HTTPMethod.POST, path, null, headers, body); | ||
| return execute(request, responseType, errorHandler, responseHeaders); | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends RESTResponse> T post( | ||
| String path, | ||
| RESTRequest body, | ||
| Class<T> responseType, | ||
| Map<String, String> headers, | ||
| Consumer<ErrorResponse> errorHandler) { | ||
| HTTPRequest request = buildRequest(HTTPMethod.POST, path, null, headers, body); | ||
| return execute(request, responseType, errorHandler, h -> {}); | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends RESTResponse> T postForm( | ||
| String path, | ||
| Map<String, String> formData, | ||
| Class<T> responseType, | ||
| Supplier<Map<String, String>> headers, | ||
| Consumer<ErrorResponse> errorHandler) { | ||
| HTTPRequest request = buildRequest(HTTPMethod.POST, path, null, headers.get(), formData); | ||
| return execute(request, responseType, errorHandler, h -> {}); | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends RESTResponse> T postForm( | ||
| String path, | ||
| Map<String, String> formData, | ||
| Class<T> responseType, | ||
| Map<String, String> headers, | ||
| Consumer<ErrorResponse> errorHandler) { | ||
| HTTPRequest request = buildRequest(HTTPMethod.POST, path, null, headers, formData); | ||
| return execute(request, responseType, errorHandler, h -> {}); | ||
| } | ||
|
|
||
| protected abstract HTTPRequest buildRequest( | ||
| HTTPMethod method, | ||
| String path, | ||
| Map<String, String> queryParams, | ||
| Map<String, String> headers, | ||
| Object body); | ||
|
|
||
| protected abstract <T extends RESTResponse> T execute( | ||
| HTTPRequest request, | ||
| Class<T> responseType, | ||
| Consumer<ErrorResponse> errorHandler, | ||
| Consumer<Map<String, String>> responseHeaders); | ||
| } | ||
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.