[KYUUBI #4594] Support PUT method in REST client

### _Why are the changes needed?_

We have api that need `PUT` method.
<img width="802" alt="image" src="https://user-images.githubusercontent.com/6757692/227441606-100bb7ff-2a51-400d-a1c9-dcd4217da305.png">

### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible

- [ ] Add screenshots for manual tests if appropriate

- [ ] [Run test](https://kyuubi.readthedocs.io/en/master/develop_tools/testing.html#running-tests) locally before make a pull request

Closes #4594 from turboFei/support_put.

Closes #4594

26fab9e26 [fwang12] add put in rest client

Authored-by: fwang12 <fwang12@ebay.com>
Signed-off-by: fwang12 <fwang12@ebay.com>
This commit is contained in:
fwang12 2023-03-24 15:37:51 +08:00
parent e21ec213c5
commit 46d23ffd56
2 changed files with 19 additions and 0 deletions

View File

@ -32,6 +32,10 @@ public interface IRestClient extends AutoCloseable {
String post(String path, String body, String authHeader);
<T> T put(String path, String body, Class<T> type, String authHeader);
String put(String path, String body, String authHeader);
<T> T delete(String path, Map<String, Object> params, Class<T> type, String authHeader);
String delete(String path, Map<String, Object> params, String authHeader);

View File

@ -126,6 +126,21 @@ public class RestClient implements IRestClient {
return JsonUtils.fromJson(responseJson, type);
}
@Override
public <T> T put(String path, String body, Class<T> type, String authHeader) {
String responseJson = put(path, body, authHeader);
return JsonUtils.fromJson(responseJson, type);
}
@Override
public String put(String path, String body, String authHeader) {
RequestBuilder putRequestBuilder = RequestBuilder.put();
if (body != null) {
putRequestBuilder.setEntity(new StringEntity(body, StandardCharsets.UTF_8));
}
return doRequest(buildURI(path), authHeader, putRequestBuilder);
}
@Override
public <T> T delete(String path, Map<String, Object> params, Class<T> type, String authHeader) {
String responseJson = delete(path, params, authHeader);