Skip to content

Commit

Permalink
[DC-2233] new swagger changes for okhttp3 upgrade (#58)
Browse files Browse the repository at this point in the history
* client now uses okhttp3
* also added new swagger changes (didn't import QueryRequest changes for pagination yet as they seemed backwards incompatible. Created a ORC ticket to handle it
  • Loading branch information
kwadhwa18 authored Sep 8, 2023
1 parent 1b31b65 commit 74bb4c6
Show file tree
Hide file tree
Showing 220 changed files with 2,160 additions and 1,181 deletions.
11 changes: 3 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@
<version>${swagger-core-version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>${okhttp-version}</version>
<exclusions>
Expand All @@ -266,7 +266,7 @@
</exclusions>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId>
<version>${okhttp-version}</version>
</dependency>
Expand Down Expand Up @@ -330,11 +330,6 @@
<version>3.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.9.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down Expand Up @@ -368,7 +363,7 @@
<maven.compiler.target>${java.version}</maven.compiler.target>
<gson-fire-version>1.8.0</gson-fire-version>
<swagger-core-version>1.5.18</swagger-core-version>
<okhttp-version>2.7.5</okhttp-version>
<okhttp-version>4.10.0</okhttp-version>
<gson-version>2.9.0</gson-version>
<threetenbp-version>1.3.5</threetenbp-version>
<maven-plugin-version>1.0.0</maven-plugin-version>
Expand Down
88 changes: 47 additions & 41 deletions src/main/java/com/rockset/client/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.squareup.okhttp.*;
import com.squareup.okhttp.internal.http.HttpMethod;
import com.squareup.okhttp.logging.HttpLoggingInterceptor;
import com.squareup.okhttp.logging.HttpLoggingInterceptor.Level;
import okhttp3.*;
import okhttp3.internal.http.HttpMethod;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.logging.HttpLoggingInterceptor.Level;
import okio.BufferedSink;
import okio.Okio;
import org.threeten.bp.LocalDate;
Expand Down Expand Up @@ -81,10 +81,11 @@ public class ApiClient {
* Constructor for ApiClient
*/
public ApiClient() {
httpClient = new OkHttpClient();
// socket timeout
httpClient.setConnectTimeout(140, TimeUnit.SECONDS);
httpClient.setReadTimeout(140, TimeUnit.SECONDS);
// socket timeout
httpClient = new OkHttpClient.Builder()
.connectTimeout(140, TimeUnit.SECONDS)
.readTimeout(140, TimeUnit.SECONDS)
.build();


verifyingSsl = true;
Expand Down Expand Up @@ -398,7 +399,7 @@ public ApiClient setTempFolderPath(String tempFolderPath) {
* @return Timeout in milliseconds
*/
public int getConnectTimeout() {
return httpClient.getConnectTimeout();
return httpClient.connectTimeoutMillis();
}

/**
Expand All @@ -410,8 +411,8 @@ public int getConnectTimeout() {
* @return Api client
*/
public ApiClient setConnectTimeout(int connectionTimeout) {
httpClient.setConnectTimeout(connectionTimeout, TimeUnit.MILLISECONDS);
return this;
httpClient = httpClient.newBuilder().connectTimeout(connectionTimeout, TimeUnit.MILLISECONDS).build();
return this;
}

/**
Expand All @@ -420,7 +421,7 @@ public ApiClient setConnectTimeout(int connectionTimeout) {
* @return Timeout in milliseconds
*/
public int getReadTimeout() {
return httpClient.getReadTimeout();
return httpClient.readTimeoutMillis();
}

/**
Expand All @@ -432,8 +433,8 @@ public int getReadTimeout() {
* @return Api client
*/
public ApiClient setReadTimeout(int readTimeout) {
httpClient.setReadTimeout(readTimeout, TimeUnit.MILLISECONDS);
return this;
httpClient = httpClient.newBuilder().readTimeout(readTimeout, TimeUnit.MILLISECONDS).build();
return this;
}

/**
Expand All @@ -442,7 +443,7 @@ public ApiClient setReadTimeout(int readTimeout) {
* @return Timeout in milliseconds
*/
public int getWriteTimeout() {
return httpClient.getWriteTimeout();
return httpClient.writeTimeoutMillis();
}

/**
Expand All @@ -454,8 +455,8 @@ public int getWriteTimeout() {
* @return Api client
*/
public ApiClient setWriteTimeout(int writeTimeout) {
httpClient.setWriteTimeout(writeTimeout, TimeUnit.MILLISECONDS);
return this;
httpClient = httpClient.newBuilder().writeTimeout(writeTimeout, TimeUnit.MILLISECONDS).build();
return this;
}

/**
Expand Down Expand Up @@ -845,24 +846,25 @@ public <T> void executeAsync(Call call, ApiCallback<T> callback) {
*/
@SuppressWarnings("unchecked")
public <T> void executeAsync(Call call, final Type returnType, final ApiCallback<T> callback) {
call.enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
callback.onFailure(new ApiException(e), 0, null);
}

@Override
public void onResponse(Response response) throws IOException {
T result;
try {
result = (T) handleResponse(response, returnType);
} catch (Exception e) {
callback.onFailure(e, response.code(), response.headers().toMultimap());
return;
}
callback.onSuccess(result, response.code(), response.headers().toMultimap());
}
});
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
callback.onFailure(new ApiException(e), 0, null);
}

@Override
public void onResponse(Call call, Response response) {
T result;
try {
result = (T) handleResponse(response, returnType);
} catch (Exception e) {
callback.onFailure(e, response.code(), response.headers().toMultimap());
return;
}
callback.onSuccess(result, response.code(), response.headers().toMultimap());

}
});
}

/**
Expand All @@ -883,7 +885,7 @@ public <T> T handleResponse(Response response, Type returnType) throws Exception
if (response.body() != null) {
try {
response.body().close();
} catch (IOException e) {
} catch (Exception e) {
throw new ApiException(response.message(), e, response.code(), response.headers().toMultimap());
}
}
Expand Down Expand Up @@ -1083,7 +1085,7 @@ public void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<
* @return RequestBody
*/
public RequestBody buildRequestBodyFormEncoding(Map<String, Object> formParams) {
FormEncodingBuilder formBuilder = new FormEncodingBuilder();
FormBody.Builder formBuilder = new FormBody.Builder();
for (Entry<String, Object> param : formParams.entrySet()) {
formBuilder.add(param.getKey(), parameterToString(param.getValue()));
}
Expand All @@ -1098,7 +1100,8 @@ public RequestBody buildRequestBodyFormEncoding(Map<String, Object> formParams)
* @return RequestBody
*/
public RequestBody buildRequestBodyMultipart(Map<String, Object> formParams) {
MultipartBuilder mpBuilder = new MultipartBuilder().type(MultipartBuilder.FORM);
MultipartBody.Builder mpBuilder = new MultipartBody.Builder();
mpBuilder.setType(MultipartBody.FORM);
for (Entry<String, Object> param : formParams.entrySet()) {
if (param.getValue() instanceof File) {
File file = (File) param.getValue();
Expand Down Expand Up @@ -1169,14 +1172,17 @@ public void checkServerTrusted(X509Certificate[] chain, String authType) throws
trustManagers = trustManagerFactory.getTrustManagers();
}

OkHttpClient.Builder httpClientLocal = httpClient.newBuilder();
if (keyManagers != null || trustManagers != null) {
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagers, trustManagers, new SecureRandom());
httpClient.setSslSocketFactory(sslContext.getSocketFactory());
httpClientLocal.sslSocketFactory(sslContext.getSocketFactory());
} else {
httpClient.setSslSocketFactory(null);
httpClientLocal.sslSocketFactory(null);
}
httpClient.setHostnameVerifier(hostnameVerifier);

httpClientLocal.hostnameVerifier(hostnameVerifier);
httpClient = httpClientLocal.build();
} catch (GeneralSecurityException e) {
throw new RuntimeException(e);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/rockset/client/ApiException.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.util.Map;
import java.util.List;

@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2023-08-08T22:21:01.705Z")
@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2023-09-07T20:46:16.821-07:00")
public class ApiException extends Exception {
private int code = 0;
private Map<String, List<String>> responseHeaders = null;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/rockset/client/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

package com.rockset.client;

@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2023-08-08T22:21:01.705Z")
@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2023-09-07T20:46:16.821-07:00")
public class Configuration {
private static ApiClient defaultApiClient = new ApiClient();

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/rockset/client/GzipRequestInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

package com.rockset.client;

import com.squareup.okhttp.*;
import okhttp3.*;
import okhttp3.RequestBody;
import okio.Buffer;
import okio.BufferedSink;
import okio.GzipSink;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/rockset/client/Pair.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

package com.rockset.client;

@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2023-08-08T22:21:01.705Z")
@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2023-09-07T20:46:16.821-07:00")
public class Pair {
private String name = "";
private String value = "";
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/rockset/client/ProgressRequestBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

package com.rockset.client;

import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.RequestBody;
import okhttp3.MediaType;
import okhttp3.RequestBody;

import java.io.IOException;

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/rockset/client/ProgressResponseBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

package com.rockset.client;

import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.ResponseBody;
import okhttp3.MediaType;
import okhttp3.ResponseBody;

import java.io.IOException;

Expand Down Expand Up @@ -45,12 +45,12 @@ public MediaType contentType() {
}

@Override
public long contentLength() throws IOException {
public long contentLength() {
return responseBody.contentLength();
}

@Override
public BufferedSource source() throws IOException {
public BufferedSource source() {
if (bufferedSource == null) {
bufferedSource = Okio.buffer(source(responseBody.source()));
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/rockset/client/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

package com.rockset.client;

@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2023-08-08T22:21:01.705Z")
@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2023-09-07T20:46:16.821-07:00")
public class StringUtil {
/**
* Check if the given array contains the given value (with case-insensitive comparison).
Expand Down
Loading

0 comments on commit 74bb4c6

Please sign in to comment.