Skip to content

Commit a64e91f

Browse files
committed
Merge branch 'upgrade_asynchttpclient' of https://github.com/dkharrat/Opentok-Java-SDK into dkharrat-upgrade_asynchttpclient
2 parents b715306 + 26bc654 commit a64e91f

File tree

2 files changed

+12
-45
lines changed

2 files changed

+12
-45
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ dependencies {
4242
testCompile group: 'junit', name: 'junit', version: '[4.3,5.0['
4343
testCompile group: 'com.github.tomakehurst', name: 'wiremock', version: '[1.45,1.99999)'
4444
testCompile group: 'commons-lang', name: 'commons-lang', version: '[2.6,2.99999)'
45-
compile group: 'com.ning', name: 'async-http-client', version: '[1.6.1,1.9['
45+
compile group: 'com.ning', name: 'async-http-client', version: '[1.9,2.0['
4646
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '[2.3.1,2.99999)'
4747
compile group: 'commons-validator', name: 'commons-validator', version: '[1.4.0,1.99999)'
4848
compile group: 'commons-codec', name: 'commons-codec', version: '[1.9,1.99999]'

src/main/java/com/opentok/util/HttpClient.java

Lines changed: 11 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,13 @@ private HttpClient(Builder builder) {
3838
}
3939

4040
public String createSession(Map<String, Collection<String>> params) throws RequestException {
41-
Future<Response> request = null;
4241
String responseString = null;
4342
Response response = null;
4443
FluentStringsMap paramsString = new FluentStringsMap().addAll(params);
4544

46-
try {
47-
request = this.preparePost(this.apiUrl + "/session/create")
48-
.setParameters(paramsString)
49-
.execute();
50-
} catch (IOException e) {
51-
throw new RequestException("Could not create an OpenTok Session", e);
52-
}
45+
Future<Response> request = this.preparePost(this.apiUrl + "/session/create")
46+
.setFormParams(paramsString)
47+
.execute();
5348

5449
try {
5550
response = request.get();
@@ -75,14 +70,8 @@ public String createSession(Map<String, Collection<String>> params) throws Reque
7570

7671
public String getArchive(String archiveId) throws RequestException {
7772
String responseString = null;
78-
Future<Response> request = null;
7973
String url = this.apiUrl + "/v2/partner/" + this.apiKey + "/archive/" + archiveId;
80-
81-
try {
82-
request = this.prepareGet(url).execute();
83-
} catch (IOException e) {
84-
throw new RequestException("Could not get an OpenTok Archive", e);
85-
}
74+
Future<Response> request = this.prepareGet(url).execute();
8675

8776
try {
8877
Response response = request.get();
@@ -116,7 +105,6 @@ public String getArchive(String archiveId) throws RequestException {
116105

117106
public String getArchives(int offset, int count) throws RequestException {
118107
String responseString = null;
119-
Future<Response> request = null;
120108
// TODO: maybe use a StringBuilder?
121109
String url = this.apiUrl + "/v2/partner/" + this.apiKey + "/archive";
122110
if (offset != 0 || count != 1000) {
@@ -129,11 +117,7 @@ public String getArchives(int offset, int count) throws RequestException {
129117
}
130118
}
131119

132-
try {
133-
request = this.prepareGet(url).execute();
134-
} catch (IOException e) {
135-
throw new RequestException("Could not get OpenTok Archives", e);
136-
}
120+
Future<Response> request = this.prepareGet(url).execute();
137121

138122
try {
139123
Response response = request.get();
@@ -165,7 +149,6 @@ public String getArchives(int offset, int count) throws RequestException {
165149
public String startArchive(String sessionId, ArchiveProperties properties)
166150
throws OpenTokException {
167151
String responseString = null;
168-
Future<Response> request = null;
169152
String requestBody = null;
170153
// TODO: maybe use a StringBuilder?
171154
String url = this.apiUrl + "/v2/partner/" + this.apiKey + "/archive";
@@ -185,14 +168,10 @@ public String startArchive(String sessionId, ArchiveProperties properties)
185168
} catch (JsonProcessingException e) {
186169
throw new OpenTokException("Could not start an OpenTok Archive. The JSON body encoding failed.", e);
187170
}
188-
try {
189-
request = this.preparePost(url)
190-
.setBody(requestBody)
191-
.setHeader("Content-Type", "application/json")
192-
.execute();
193-
} catch (IOException e) {
194-
throw new RequestException("Could not start an OpenTok Archive.", e);
195-
}
171+
Future<Response> request = this.preparePost(url)
172+
.setBody(requestBody)
173+
.setHeader("Content-Type", "application/json")
174+
.execute();
196175

197176
try {
198177
Response response = request.get();
@@ -228,15 +207,9 @@ public String startArchive(String sessionId, ArchiveProperties properties)
228207

229208
public String stopArchive(String archiveId) throws RequestException {
230209
String responseString = null;
231-
Future<Response> request = null;
232210
// TODO: maybe use a StringBuilder?
233211
String url = this.apiUrl + "/v2/partner/" + this.apiKey + "/archive/" + archiveId + "/stop";
234-
235-
try {
236-
request = this.preparePost(url).execute();
237-
} catch (IOException e) {
238-
throw new RequestException("Could not stop an OpenTok Archive. archiveId = " + archiveId, e);
239-
}
212+
Future<Response> request = this.preparePost(url).execute();
240213

241214
try {
242215
Response response = request.get();
@@ -276,14 +249,8 @@ public String stopArchive(String archiveId) throws RequestException {
276249

277250
public String deleteArchive(String archiveId) throws RequestException {
278251
String responseString = null;
279-
Future<Response> request = null;
280252
String url = this.apiUrl + "/v2/partner/" + this.apiKey + "/archive/" + archiveId;
281-
282-
try {
283-
request = this.prepareDelete(url).execute();
284-
} catch (IOException e) {
285-
throw new RequestException("Could not delete an OpenTok Archive. archiveId = " + archiveId, e);
286-
}
253+
Future<Response> request = this.prepareDelete(url).execute();
287254

288255
try {
289256
Response response = request.get();

0 commit comments

Comments
 (0)