Skip to content

Commit a69f79a

Browse files
committed
Added Accept header to requests where applicable
1 parent be2ff19 commit a69f79a

File tree

1 file changed

+36
-17
lines changed

1 file changed

+36
-17
lines changed

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

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public String createSession(Map<String, Collection<String>> params) throws Reque
5959

6060
Future<Response> request = this.preparePost(this.apiUrl + "/session/create")
6161
.setFormParams(paramsWithList)
62-
.addHeader("Accept", "application/json") // XML version is deprecated
62+
.setHeader("Accept", "application/json") // XML version is deprecated
6363
.execute();
6464

6565
try {
@@ -119,7 +119,9 @@ public String signal(String sessionId, String connectionId, SignalProperties pro
119119

120120
public String getArchive(String archiveId) throws RequestException {
121121
String url = this.apiUrl + "/v2/project/" + this.apiKey + "/archive/" + archiveId;
122-
Future<Response> request = this.prepareGet(url).execute();
122+
Future<Response> request = this.prepareGet(url)
123+
.setHeader("Accept", "application/json")
124+
.execute();
123125

124126
try {
125127
Response response = request.get();
@@ -161,7 +163,9 @@ public String getArchives(String sessionId, int offset, int count) throws OpenTo
161163
url += (url.contains("?") ? "&" : "?") + "sessionId=" + sessionId;
162164
}
163165

164-
Future<Response> request = this.prepareGet(url).execute();
166+
Future<Response> request = this.prepareGet(url)
167+
.setHeader("Accept", "application/json")
168+
.execute();
165169

166170
try {
167171
Response response = request.get();
@@ -221,6 +225,7 @@ public String startArchive(String sessionId, ArchiveProperties properties) throw
221225
Future<Response> request = this.preparePost(url)
222226
.setBody(requestBody)
223227
.setHeader("Content-Type", "application/json")
228+
.setHeader("Accept", "application/json")
224229
.execute();
225230

226231
try {
@@ -251,7 +256,9 @@ public String startArchive(String sessionId, ArchiveProperties properties) throw
251256

252257
public String stopArchive(String archiveId) throws RequestException {
253258
String url = this.apiUrl + "/v2/project/" + this.apiKey + "/archive/" + archiveId + "/stop";
254-
Future<Response> request = this.preparePost(url).execute();
259+
Future<Response> request = this.preparePost(url)
260+
.setHeader("Accept", "application/json")
261+
.execute();
255262

256263
try {
257264
Response response = request.get();
@@ -490,6 +497,7 @@ public String startBroadcast(String sessionId, BroadcastProperties properties) t
490497
ObjectNode requestJson = nodeFactory.objectNode();
491498
requestJson.put("sessionId", sessionId);
492499
requestJson.put("streamMode", properties.streamMode().toString());
500+
493501
if (properties.layout() != null) {
494502
ObjectNode layout = requestJson.putObject("layout");
495503
screenshareType = properties.layout().getScreenshareType();
@@ -511,6 +519,7 @@ public String startBroadcast(String sessionId, BroadcastProperties properties) t
511519
if (properties.resolution() != null) {
512520
requestJson.put("resolution", properties.resolution());
513521
}
522+
514523
ObjectNode outputs = requestJson.putObject("outputs");
515524
if (properties.hasHls()) {
516525
ObjectNode hlsNode = nodeFactory.objectNode();
@@ -521,6 +530,7 @@ public String startBroadcast(String sessionId, BroadcastProperties properties) t
521530
hlsNode.put("lowLatency", hlsPojo.lowLatency());
522531
}
523532
}
533+
524534
ArrayNode rtmp = outputs.putArray("rtmp");
525535
for (RtmpProperties prop : properties.rtmpList()) {
526536
ObjectNode rtmpProps = nodeFactory.objectNode();
@@ -540,6 +550,7 @@ public String startBroadcast(String sessionId, BroadcastProperties properties) t
540550
Future<Response> request = this.preparePost(url)
541551
.setBody(requestBody)
542552
.setHeader("Content-Type", "application/json")
553+
.setHeader("Accept", "application/json")
543554
.execute();
544555

545556
try {
@@ -566,11 +577,11 @@ public String startBroadcast(String sessionId, BroadcastProperties properties) t
566577
}
567578

568579
public String stopBroadcast(String broadcastId) throws OpenTokException {
569-
String requestBody = null;
570580
String url = this.apiUrl + "/v2/project/" + this.apiKey + "/broadcast/" + broadcastId + "/stop";
581+
571582
Future<Response> request = this.preparePost(url)
572-
.setBody(requestBody)
573583
.setHeader("Content-Type", "application/json")
584+
.setHeader("Accept", "application/json")
574585
.execute();
575586

576587
try {
@@ -595,14 +606,14 @@ public String stopBroadcast(String broadcastId) throws OpenTokException {
595606
}
596607
}
597608

598-
public String getBroadcast(String broadcastId)
599-
throws OpenTokException {
600-
String requestBody = null;
609+
public String getBroadcast(String broadcastId) throws OpenTokException {
601610
String url = this.apiUrl + "/v2/project/" + this.apiKey + "/broadcast/" + broadcastId;
611+
602612
Future<Response> request = this.prepareGet(url)
603-
.setBody(requestBody)
604613
.setHeader("Content-Type", "application/json")
614+
.setHeader("Accept", "application/json")
605615
.execute();
616+
606617
try {
607618
Response response = request.get();
608619
switch (response.getStatusCode()) {
@@ -629,13 +640,16 @@ public String patchBroadcast(String broadcastId, String addStream, String remove
629640
String url = this.apiUrl + "/v2/project/" + this.apiKey + "/broadcast/" + broadcastId + "/streams";
630641
JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
631642
ObjectNode requestJson = nodeFactory.objectNode();
643+
632644
if (removeStream != null && !removeStream.equals("")) {
633645
requestJson.put("removeStream", removeStream);
634-
} else if(addStream != null && !addStream.equals("")) {
646+
}
647+
else if(addStream != null && !addStream.equals("")) {
635648
requestJson.put("hasAudio", hasAudio);
636649
requestJson.put("hasVideo", hasVideo);
637650
requestJson.put("addStream", addStream);
638-
} else {
651+
}
652+
else {
639653
throw new InvalidArgumentException("Could not patch broadcast, needs one of: addStream or removeStream");
640654
}
641655

@@ -682,6 +696,7 @@ public String setBroadcastLayout(String broadcastId, BroadcastProperties propert
682696
String type = properties.layout().getType().toString();
683697
String stylesheet = properties.layout().getStylesheet();
684698
String screenshareLayout = null;
699+
685700
if (StringUtils.isEmpty(type)) {
686701
throw new RequestException("Could not set the layout. Either an invalid JSON or an invalid layout options.");
687702
}
@@ -695,10 +710,13 @@ public String setBroadcastLayout(String broadcastId, BroadcastProperties propert
695710
}
696711
screenshareLayout = properties.layout().getScreenshareType().toString();
697712
}
713+
698714
String url = this.apiUrl + "/v2/project/" + this.apiKey + "/broadcast/" + broadcastId + "/layout";
715+
699716
JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
700717
ObjectNode requestJson = nodeFactory.objectNode();
701718
requestJson.put("type", type);
719+
702720
if (type.equals(BroadcastLayout.Type.CUSTOM.toString())) {
703721
requestJson.put("stylesheet", properties.layout().getStylesheet());
704722
}
@@ -716,6 +734,7 @@ public String setBroadcastLayout(String broadcastId, BroadcastProperties propert
716734
.setBody(requestBody)
717735
.setHeader("Content-Type", "application/json")
718736
.execute();
737+
719738
try {
720739
Response response = request.get();
721740
switch (response.getStatusCode()) {
@@ -758,7 +777,6 @@ public String forceDisconnect(String sessionId, String connectionId) throws Open
758777
} catch (InterruptedException | ExecutionException e) {
759778
throw new RequestException("Could not force disconnect", e);
760779
}
761-
762780
}
763781

764782
public String sipDial(String sessionId, String token, SipProperties props) throws OpenTokException {
@@ -817,7 +835,9 @@ public String sipDial(String sessionId, String token, SipProperties props) throw
817835
Future<Response> request = this.preparePost(url)
818836
.setBody(outputStream.toString())
819837
.setHeader("Content-Type", "application/json")
838+
.setHeader("Accept", "application/json")
820839
.execute();
840+
821841
try {
822842
Response response = request.get();
823843
switch (response.getStatusCode()) {
@@ -870,7 +890,6 @@ public String playDtmf(String url, String dtmfDigits) throws OpenTokException {
870890
} catch (InterruptedException | ExecutionException e) {
871891
throw new RequestException("Could not play dtmf");
872892
}
873-
874893
}
875894

876895
public String playDtmfAll(String sessionId, String dtmfDigits) throws OpenTokException {
@@ -1031,7 +1050,6 @@ public String disableForceMute(String sessionId) throws OpenTokException {
10311050
+ "sessionId: " + sessionId);
10321051
case 403:
10331052
throw new RequestException("Invalid OpenTok API key or JWT token.");
1034-
10351053
case 408:
10361054
throw new RequestException("You passed in an invalid stream ID.");
10371055
case 500:
@@ -1047,7 +1065,9 @@ public String disableForceMute(String sessionId) throws OpenTokException {
10471065

10481066
public String listStreams(String sessionId) throws RequestException {
10491067
String url = this.apiUrl + "/v2/project/" + this.apiKey + "/session/" + sessionId + "/stream";
1050-
Future<Response> request = this.prepareGet(url).execute();
1068+
Future<Response> request = this.prepareGet(url)
1069+
.setHeader("Accept", "application/json")
1070+
.execute();
10511071

10521072
try {
10531073
Response response = request.get();
@@ -1069,7 +1089,6 @@ public String listStreams(String sessionId) throws RequestException {
10691089
} catch (InterruptedException | ExecutionException e) {
10701090
throw new RequestException("Could not get streams information", e);
10711091
}
1072-
10731092
}
10741093

10751094
public enum ProxyAuthScheme {

0 commit comments

Comments
 (0)