Skip to content

Commit 7a67c58

Browse files
authored
Merge pull request #71 from bitsoex/dependency-updates
Dependency updates
2 parents bd24347 + 4fa10c5 commit 7a67c58

File tree

7 files changed

+57
-45
lines changed

7 files changed

+57
-45
lines changed

build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group = 'com.github.bitsoex'
8-
version = '4.1.0'
8+
version = '4.2.0'
99

1010
description = "bitso-java"
1111

@@ -23,11 +23,11 @@ repositories {
2323
}
2424

2525
dependencies {
26-
api 'org.apache.httpcomponents:httpclient:4.5.13'
27-
api 'org.json:json:20250517'
28-
api 'io.netty:netty-all:4.2.2.Final'
26+
api 'org.apache.httpcomponents.client5:httpclient5:5.6'
27+
api 'org.json:json:20251224'
28+
api 'io.netty:netty-all:4.2.10.Final'
2929

30-
testImplementation 'org.junit.jupiter:junit-jupiter:5.13.1'
30+
testImplementation 'org.junit.jupiter:junit-jupiter:5.14.2'
3131
testImplementation 'org.junit.platform:junit-platform-launcher'
3232
testImplementation 'org.mockito:mockito-junit-jupiter:5.18.0'
3333
}

gradle/wrapper/gradle-wrapper.jar

302 Bytes
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/com/bitso/examples/BitsoJavaExample.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
import javax.crypto.Mac;
88
import javax.crypto.spec.SecretKeySpec;
99

10-
import org.apache.http.client.methods.CloseableHttpResponse;
11-
import org.apache.http.client.methods.HttpPost;
12-
import org.apache.http.entity.StringEntity;
13-
import org.apache.http.impl.client.HttpClients;
10+
import org.apache.hc.client5.http.classic.methods.HttpPost;
11+
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
12+
import org.apache.hc.client5.http.impl.classic.HttpClients;
13+
import org.apache.hc.core5.http.io.entity.StringEntity;
1414
import org.json.JSONObject;
1515

1616
public class BitsoJavaExample {

src/main/java/com/bitso/http/BlockingHttpClient.java

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,29 @@
66
import java.net.ProtocolException;
77
import java.net.URL;
88
import java.nio.charset.Charset;
9+
import java.nio.charset.UnsupportedCharsetException;
910
import java.util.HashMap;
11+
import java.util.Map;
1012
import java.util.Map.Entry;
1113

1214
import javax.net.ssl.HttpsURLConnection;
1315

14-
import org.apache.http.client.ClientProtocolException;
15-
import org.apache.http.client.methods.CloseableHttpResponse;
16-
import org.apache.http.client.methods.HttpDelete;
17-
import org.apache.http.client.methods.HttpPost;
18-
import org.apache.http.entity.AbstractHttpEntity;
19-
import org.apache.http.entity.ByteArrayEntity;
20-
import org.apache.http.entity.StringEntity;
21-
import org.apache.http.impl.client.CloseableHttpClient;
22-
import org.apache.http.impl.client.HttpClients;
23-
2416
import com.bitso.exceptions.BitsoAPIException;
2517

2618
import com.bitso.helpers.Helpers;
19+
import org.apache.hc.client5.http.ClientProtocolException;
20+
import org.apache.hc.client5.http.classic.methods.HttpDelete;
21+
import org.apache.hc.client5.http.classic.methods.HttpPost;
22+
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
23+
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
24+
import org.apache.hc.client5.http.impl.classic.HttpClients;
25+
import org.apache.hc.core5.http.ContentType;
26+
import org.apache.hc.core5.http.io.entity.AbstractHttpEntity;
27+
import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
28+
import org.apache.hc.core5.http.io.entity.StringEntity;
2729

2830
public class BlockingHttpClient {
31+
public static final String CONTENT_TYPE = "Content-Type";
2932
private boolean log = false;
3033
private long throttleMs = -1;
3134
private long lastCallTime = 0;
@@ -56,6 +59,7 @@ private void throttle() {
5659
lastCallTime = System.currentTimeMillis();
5760
} catch (InterruptedException e) {
5861
log("Error executing throttle");
62+
Thread.currentThread().interrupt();
5963
}
6064
}
6165

@@ -85,29 +89,37 @@ public String sendPost(String url, String body, HashMap<String, String> headers)
8589

8690
return Helpers.convertInputStreamToString(connection.getInputStream());
8791
} catch (MalformedURLException e) {
88-
e.printStackTrace();
8992
throw new BitsoAPIException(322, "Not a Valid URL", e);
9093
} catch (ProtocolException e) {
91-
e.printStackTrace();
9294
throw new BitsoAPIException(901, "Unsupported HTTP method", e);
9395
} catch (IOException e) {
94-
e.printStackTrace();
96+
e.printStackTrace(System.err);
9597
return Helpers.convertInputStreamToString(connection.getErrorStream());
9698
}
9799
}
98100

99101
public String sendPost(String url, String body, HashMap<String, String> headers, Charset charset)
100-
throws ClientProtocolException, IOException {
102+
throws IOException {
101103
return sendPost(url, new StringEntity(body, charset), headers);
102104
}
103105

104106
public String sendPost(String url, byte[] body, HashMap<String, String> headers)
105-
throws ClientProtocolException, IOException {
106-
return sendPost(url, new ByteArrayEntity(body), headers);
107+
throws IOException {
108+
ContentType contentType = ContentType.APPLICATION_JSON;
109+
if (headers != null && headers.containsKey(CONTENT_TYPE)) {
110+
try {
111+
contentType = ContentType.parse(headers.get(CONTENT_TYPE));
112+
headers = new HashMap<>(headers);
113+
headers.remove(CONTENT_TYPE);
114+
} catch (UnsupportedCharsetException ex) {
115+
//Revert to default
116+
}
117+
}
118+
return sendPost(url, new ByteArrayEntity(body, 0, body.length, contentType), headers);
107119
}
108120

109121
private String sendPost(String url, AbstractHttpEntity body, HashMap<String, String> headers)
110-
throws ClientProtocolException, IOException {
122+
throws IOException {
111123
throttle();
112124

113125
HttpPost postRequest = new HttpPost(url);
@@ -119,13 +131,13 @@ private String sendPost(String url, AbstractHttpEntity body, HashMap<String, Str
119131

120132
postRequest.setEntity(body);
121133

122-
CloseableHttpResponse closeableHttpResponse = HttpClients.createDefault().execute(postRequest);
123-
String response = Helpers.convertInputStreamToString(closeableHttpResponse.getEntity().getContent());
124-
125-
return response;
134+
try (CloseableHttpClient client = HttpClients.createDefault();
135+
CloseableHttpResponse response = client.execute(postRequest)) {
136+
return Helpers.convertInputStreamToString(response.getEntity().getContent());
137+
}
126138
}
127139

128-
public String sendDelete(String url, HashMap<String, String> headers) throws BitsoAPIException {
140+
public String sendDelete(String url, Map<String, String> headers) throws BitsoAPIException {
129141
throttle();
130142
HttpDelete deleteURL = new HttpDelete(url);
131143

@@ -135,16 +147,12 @@ public String sendDelete(String url, HashMap<String, String> headers) throws Bit
135147
}
136148
}
137149

138-
CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
139-
CloseableHttpResponse response = null;
140-
try {
141-
response = closeableHttpClient.execute(deleteURL);
150+
try (CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
151+
CloseableHttpResponse response = closeableHttpClient.execute(deleteURL)) {
142152
return Helpers.convertInputStreamToString(response.getEntity().getContent());
143153
} catch (ClientProtocolException e) {
144-
e.printStackTrace();
145154
throw new BitsoAPIException(901, "Usupported HTTP method", e);
146155
} catch (IOException e) {
147-
e.printStackTrace();
148156
throw new BitsoAPIException(101, "Connection Aborted", e);
149157
}
150158
}

0 commit comments

Comments
 (0)