Skip to content

Commit

Permalink
#164 : Fix deprecated use of URL constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
gazbert committed Apr 21, 2024
1 parent 85c57c6 commit dc74025
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -900,10 +902,10 @@ public String toString() {
private ExchangeHttpResponse sendPublicRequestToExchange(String apiMethod)
throws ExchangeNetworkException, TradingApiException {
try {
final URL url = new URL(PUBLIC_API_BASE_URL + apiMethod);
final URL url = new URI(PUBLIC_API_BASE_URL + apiMethod).toURL();
return makeNetworkRequest(url, "GET", null, createHeaderParamMap());

} catch (MalformedURLException e) {
} catch (MalformedURLException | URISyntaxException e) {
final String errorMsg = UNEXPECTED_IO_ERROR_MSG;
log.error(errorMsg, e);
throw new TradingApiException(errorMsg, e);
Expand Down Expand Up @@ -986,10 +988,10 @@ private ExchangeHttpResponse sendAuthenticatedRequestToExchange(
// payload is JSON for this exchange
requestHeaders.put("Content-Type", "application/json");

final URL url = new URL(AUTHENTICATED_API_URL + apiMethod);
final URL url = new URI(AUTHENTICATED_API_URL + apiMethod).toURL();
return makeNetworkRequest(url, "POST", paramsInJson, requestHeaders);

} catch (MalformedURLException e) {
} catch (MalformedURLException | URISyntaxException e) {
final String errorMsg = UNEXPECTED_IO_ERROR_MSG;
log.error(errorMsg, e);
throw new TradingApiException(errorMsg, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
Expand Down Expand Up @@ -754,10 +756,10 @@ public Date deserialize(JsonElement json, Type type, JsonDeserializationContext
private ExchangeHttpResponse sendPublicRequestToExchange(String apiMethod)
throws ExchangeNetworkException, TradingApiException {
try {
final URL url = new URL(API_BASE_URL + apiMethod);
final URL url = new URI(API_BASE_URL + apiMethod).toURL();
return makeNetworkRequest(url, "GET", null, createHeaderParamMap());

} catch (MalformedURLException e) {
} catch (MalformedURLException | URISyntaxException e) {
final String errorMsg = UNEXPECTED_IO_ERROR_MSG;
log.error(errorMsg, e);
throw new TradingApiException(errorMsg, e);
Expand Down Expand Up @@ -820,10 +822,10 @@ private ExchangeHttpResponse sendAuthenticatedRequestToExchange(
requestHeaders.put("Content-Type", "application/x-www-form-urlencoded");

// MUST have the trailing slash else exchange barfs...
final URL url = new URL(API_BASE_URL + apiMethod + "/");
final URL url = new URI(API_BASE_URL + apiMethod + "/").toURL();
return makeNetworkRequest(url, "POST", postData.toString(), requestHeaders);

} catch (MalformedURLException e) {
} catch (MalformedURLException | URISyntaxException e) {
final String errorMsg = UNEXPECTED_IO_ERROR_MSG;
log.error(errorMsg, e);
throw new TradingApiException(errorMsg, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -644,10 +646,10 @@ public String toString() {
private ExchangeHttpResponse sendPublicRequestToExchange(String apiMethod)
throws ExchangeNetworkException, TradingApiException {
try {
final URL url = new URL(PUBLIC_API_BASE_URL + apiMethod);
final URL url = new URI(PUBLIC_API_BASE_URL + apiMethod).toURL();
return makeNetworkRequest(url, "GET", null, createRequestParamMap());

} catch (MalformedURLException e) {
} catch (MalformedURLException | URISyntaxException e) {
final String errorMsg = UNEXPECTED_IO_ERROR_MSG;
log.error(errorMsg, e);
throw new TradingApiException(errorMsg, e);
Expand Down Expand Up @@ -739,10 +741,10 @@ private ExchangeHttpResponse sendAuthenticatedRequestToExchange(
// payload is JSON for this exchange
requestHeaders.put("Content-Type", "application/json");

final URL url = new URL(AUTHENTICATED_API_URL + apiMethod);
final URL url = new URI(AUTHENTICATED_API_URL + apiMethod).toURL();
return makeNetworkRequest(url, "POST", paramsInJson, requestHeaders);

} catch (MalformedURLException e) {
} catch (MalformedURLException | URISyntaxException e) {
final String errorMsg = UNEXPECTED_IO_ERROR_MSG;
log.error(errorMsg, e);
throw new TradingApiException(errorMsg, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
import java.math.RoundingMode;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
Expand Down Expand Up @@ -943,10 +945,10 @@ private ExchangeHttpResponse sendPublicRequestToExchange(
requestHeaders.put("Content-Type", "application/x-www-form-urlencoded");
}

final URL url = new URL(PUBLIC_API_BASE_URL + apiMethod + queryString);
final URL url = new URI(PUBLIC_API_BASE_URL + apiMethod + queryString).toURL();
return makeNetworkRequest(url, "GET", null, requestHeaders);

} catch (MalformedURLException e) {
} catch (MalformedURLException | URISyntaxException e) {
final String errorMsg = UNEXPECTED_IO_ERROR_MSG;
log.error(errorMsg, e);
throw new TradingApiException(errorMsg, e);
Expand Down Expand Up @@ -1028,10 +1030,10 @@ private ExchangeHttpResponse sendAuthenticatedRequestToExchange(
requestHeaders.put("API-Key", key);
requestHeaders.put("API-Sign", signature);

final URL url = new URL(AUTHENTICATED_API_URL + apiMethod);
final URL url = new URI(AUTHENTICATED_API_URL + apiMethod).toURL();
return makeNetworkRequest(url, "POST", postData.toString(), requestHeaders);

} catch (MalformedURLException | NoSuchAlgorithmException e) {
} catch (MalformedURLException | NoSuchAlgorithmException | URISyntaxException e) {
final String errorMsg = UNEXPECTED_IO_ERROR_MSG;
log.error(errorMsg, e);
throw new TradingApiException(errorMsg, e);
Expand Down

0 comments on commit dc74025

Please sign in to comment.