@@ -60,13 +60,7 @@ public String createSession(Map<String, Collection<String>> params) throws Reque
60
60
throw new RequestException ("Could not create an OpenTok Session. The server response was invalid." +
61
61
" response code: " + response .getStatusCode ());
62
62
}
63
-
64
- // if we only wanted Java 7 and above, we could DRY this into one catch clause
65
- } catch (InterruptedException e ) {
66
- throw new RequestException ("Could not create an OpenTok Session" , e );
67
- } catch (ExecutionException e ) {
68
- throw new RequestException ("Could not create an OpenTok Session" , e );
69
- } catch (IOException e ) {
63
+ } catch (InterruptedException | ExecutionException | IOException e ) {
70
64
throw new RequestException ("Could not create an OpenTok Session" , e );
71
65
}
72
66
return responseString ;
@@ -94,13 +88,7 @@ public String getArchive(String archiveId) throws RequestException {
94
88
throw new RequestException ("Could not get an OpenTok Archive. The server response was invalid." +
95
89
" response code: " + response .getStatusCode ());
96
90
}
97
-
98
- // if we only wanted Java 7 and above, we could DRY this into one catch clause
99
- } catch (InterruptedException e ) {
100
- throw new RequestException ("Could not get an OpenTok Archive" , e );
101
- } catch (ExecutionException e ) {
102
- throw new RequestException ("Could not get an OpenTok Archive" , e );
103
- } catch (IOException e ) {
91
+ } catch (InterruptedException | ExecutionException | IOException e ) {
104
92
throw new RequestException ("Could not get an OpenTok Archive" , e );
105
93
}
106
94
@@ -137,13 +125,7 @@ public String getArchives(int offset, int count) throws RequestException {
137
125
throw new RequestException ("Could not get an OpenTok Archive. The server response was invalid." +
138
126
" response code: " + response .getStatusCode ());
139
127
}
140
-
141
- // if we only wanted Java 7 and above, we could DRY this into one catch clause
142
- } catch (InterruptedException e ) {
143
- throw new RequestException ("Could not get OpenTok Archives" , e );
144
- } catch (ExecutionException e ) {
145
- throw new RequestException ("Could not get OpenTok Archives" , e );
146
- } catch (IOException e ) {
128
+ } catch (InterruptedException | ExecutionException | IOException e ) {
147
129
throw new RequestException ("Could not get OpenTok Archives" , e );
148
130
}
149
131
@@ -197,13 +179,7 @@ public String startArchive(String sessionId, ArchiveProperties properties)
197
179
throw new RequestException ("Could not start an OpenTok Archive. The server response was invalid." +
198
180
" response code: " + response .getStatusCode ());
199
181
}
200
-
201
- // if we only wanted Java 7 and above, we could DRY this into one catch clause
202
- } catch (InterruptedException e ) {
203
- throw new RequestException ("Could not start an OpenTok Archive." , e );
204
- } catch (ExecutionException e ) {
205
- throw new RequestException ("Could not start an OpenTok Archive." , e );
206
- } catch (IOException e ) {
182
+ } catch (InterruptedException | ExecutionException | IOException e ) {
207
183
throw new RequestException ("Could not start an OpenTok Archive." , e );
208
184
}
209
185
return responseString ;
@@ -239,13 +215,7 @@ public String stopArchive(String archiveId) throws RequestException {
239
215
throw new RequestException ("Could not stop an OpenTok Archive. The server response was invalid." +
240
216
" response code: " + response .getStatusCode ());
241
217
}
242
-
243
- // if we only wanted Java 7 and above, we could DRY this into one catch clause
244
- } catch (InterruptedException e ) {
245
- throw new RequestException ("Could not stop an OpenTok Archive." , e );
246
- } catch (ExecutionException e ) {
247
- throw new RequestException ("Could not stop an OpenTok Archive." , e );
248
- } catch (IOException e ) {
218
+ } catch (InterruptedException | ExecutionException | IOException e ) {
249
219
throw new RequestException ("Could not stop an OpenTok Archive." , e );
250
220
}
251
221
return responseString ;
@@ -273,13 +243,7 @@ public String deleteArchive(String archiveId) throws RequestException {
273
243
throw new RequestException ("Could not get an OpenTok Archive. The server response was invalid." +
274
244
" response code: " + response .getStatusCode ());
275
245
}
276
-
277
- // if we only wanted Java 7 and above, we could DRY this into one catch clause
278
- } catch (InterruptedException e ) {
279
- throw new RequestException ("Could not delete an OpenTok Archive. archiveId = " + archiveId , e );
280
- } catch (ExecutionException e ) {
281
- throw new RequestException ("Could not delete an OpenTok Archive. archiveId = " + archiveId , e );
282
- } catch (IOException e ) {
246
+ } catch (InterruptedException | ExecutionException | IOException e ) {
283
247
throw new RequestException ("Could not delete an OpenTok Archive. archiveId = " + archiveId , e );
284
248
}
285
249
@@ -311,7 +275,7 @@ public Builder proxy(Proxy proxy) {
311
275
public HttpClient build () {
312
276
AsyncHttpClientConfig .Builder configBuilder = new AsyncHttpClientConfig .Builder ()
313
277
.setUserAgent ("Opentok-Java-SDK/" + Version .VERSION + " JRE/" + System .getProperty ("java.version" ))
314
- .addRequestFilter (new PartnerAuthRequestFilter (this .apiKey , this .apiSecret ));
278
+ .addRequestFilter (new TokenAuthRequestFilter (this .apiKey , this .apiSecret ));
315
279
if (this .apiUrl == null ) {
316
280
this .apiUrl =DefaultApiUrl .DEFAULT_API_URI ;
317
281
}
@@ -352,22 +316,29 @@ static ProxyServer createProxyServer(final Proxy proxy) {
352
316
}
353
317
}
354
318
355
- static class PartnerAuthRequestFilter implements RequestFilter {
319
+ static class TokenAuthRequestFilter implements RequestFilter {
356
320
357
321
private int apiKey ;
358
322
private String apiSecret ;
323
+ private final String authHeader = "X-OPENTOK-AUTH" ;
359
324
360
- public PartnerAuthRequestFilter (int apiKey , String apiSecret ) {
325
+ public TokenAuthRequestFilter (int apiKey , String apiSecret ) {
361
326
this .apiKey = apiKey ;
362
327
this .apiSecret = apiSecret ;
363
328
}
364
329
365
330
public FilterContext filter (FilterContext ctx ) throws FilterException {
366
- return new FilterContext .FilterContextBuilder (ctx )
367
- .request (new RequestBuilder (ctx .getRequest ())
368
- .addHeader ("X-TB-PARTNER-AUTH" , this .apiKey +":" +this .apiSecret )
369
- .build ())
370
- .build ();
331
+ try {
332
+ return new FilterContext .FilterContextBuilder (ctx )
333
+ .request (new RequestBuilder (ctx .getRequest ())
334
+ .addHeader (authHeader ,
335
+ TokenGenerator .generateToken (apiKey , apiSecret ))
336
+ .build ())
337
+ .build ();
338
+ } catch (OpenTokException e ) {
339
+ e .printStackTrace ();
340
+ return null ;
341
+ }
371
342
}
372
343
}
373
344
}
0 commit comments