com.aliyun.datahub.client.http.common.HttpRequest Maven / Gradle / Ivy
The newest version!
package com.aliyun.datahub.client.http.common;
import com.aliyun.datahub.client.util.JsonUtils;
import okhttp3.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.aliyun.datahub.client.http.common.Constants.CONTENT_JSON;
public class HttpRequest {
private HttpInterceptor interceptor;
private String endpoint;
private String path;
private HttpMethod method;
private Map headers = new HashMap<>();
private Map> queryParams = new HashMap<>();
private OkHttpClient client;
private HttpEntity> entity;
private int maxRetryCount = 1;
public HttpRequest(OkHttpClient client) {
this.client = client;
}
public OkHttpClient getClient() { return this.client; }
public HttpRequest interceptor(HttpInterceptor interceptor) {
this.interceptor = interceptor;
return this;
}
public HttpRequest endpoint(String endpoint) {
this.endpoint = endpoint;
return this;
}
public HttpRequest path(String path) {
this.path = path;
return this;
}
public String getPath() {
return path;
}
public HttpRequest method(HttpMethod method) {
this.method = method;
return this;
}
public HttpMethod getMethod() {
return method;
}
public HttpRequest header(String key, String value) {
headers.put(key, value);
return this;
}
public Map getHeaders() {
return headers;
}
public HttpRequest queryParam(String key, Object value) {
if (queryParams.containsKey(key)) {
List