Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc710a01

Browse files
author
Scott Kidder
committed
Correct issues with handling the ingest-keys response
1 parent96a19fc commitc710a01

File tree

3 files changed

+61
-25
lines changed

3 files changed

+61
-25
lines changed

‎src/main/java/com/brightcove/castlabs/client/CastlabsClient.java‎

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
importorg.apache.http.message.BasicNameValuePair;
2424

2525
importcom.brightcove.castlabs.client.request.IngestKeysRequest;
26-
importcom.brightcove.castlabs.client.response.IngestKeysResponse;
26+
importcom.brightcove.castlabs.client.response.IngestAssetsResponse;
2727
importcom.fasterxml.jackson.databind.DeserializationFeature;
2828
importcom.fasterxml.jackson.databind.ObjectMapper;
2929

@@ -158,10 +158,12 @@ protected String getTicket(String merchantId) throws CastlabsException, IOExcept
158158
ticketResponse =httpclient.execute(ticketRequest);
159159
if (ticketResponse !=null) {
160160
finalintstatusCode =ticketResponse.getStatusLine().getStatusCode();
161-
finalStringreason =ticketResponse.getStatusLine().getReasonPhrase();
162161
if (200 !=statusCode) {
162+
finalStringreason =ticketResponse.getStatusLine().getReasonPhrase();
163+
finalStringresponseBody =
164+
IOUtils.toString(ticketResponse.getEntity().getContent());
163165
thrownewCastlabsException("Ticket retrieval failed: Response code="
164-
+statusCode +", Reason=" +reason);
166+
+statusCode +", Reason=" +reason +", Body=" +responseBody);
165167
}
166168
}else {
167169
thrownewCastlabsException("No response when retrieving Castlabs ticket");
@@ -186,7 +188,7 @@ protected String getTicket(String merchantId) throws CastlabsException, IOExcept
186188
* @throws CastlabsException error reported by Castlabs
187189
* @throws IOException network error while communicating with Castlabs REST API
188190
*/
189-
publicIngestKeysResponseingestKeys(IngestKeysRequestrequest,StringmerchantId)
191+
publicIngestAssetsResponseingestKeys(IngestKeysRequestrequest,StringmerchantId)
190192
throwsCastlabsException,IOException {
191193
finalStringuri =this.ingestionBaseUrl +"frontend/api/keys/v2/ingest/" +merchantId
192194
+"?ticket=" +this.getTicket(merchantId);
@@ -195,7 +197,7 @@ public IngestKeysResponse ingestKeys(IngestKeysRequest request, String merchantI
195197
ingestRequest.setHeader("Accept","application/json");
196198

197199
finalCloseableHttpClienthttpclient =HttpClients.createDefault();
198-
CloseableHttpResponseticketResponse =null;
200+
CloseableHttpResponseingestResponse =null;
199201
try {
200202
if (this.connectionTimeoutSeconds >0) {
201203
intconnectionTimeout =connectionTimeoutSeconds *1000;
@@ -206,18 +208,20 @@ public IngestKeysResponse ingestKeys(IngestKeysRequest request, String merchantI
206208
ingestRequest.setConfig(requestConfig);
207209
}
208210
ingestRequest.setEntity(newStringEntity(objectMapper.writeValueAsString(request)));
209-
ticketResponse =httpclient.execute(ingestRequest);
210-
if (ticketResponse !=null) {
211-
finalintstatusCode =ticketResponse.getStatusLine().getStatusCode();
212-
finalStringreason =ticketResponse.getStatusLine().getReasonPhrase();
211+
ingestResponse =httpclient.execute(ingestRequest);
212+
if (ingestResponse !=null) {
213+
finalintstatusCode =ingestResponse.getStatusLine().getStatusCode();
213214
if (200 !=statusCode) {
214-
thrownewCastlabsException(
215-
"Ingest failed: Response code=" +statusCode +", Reason=" +reason);
215+
finalStringreason =ingestResponse.getStatusLine().getReasonPhrase();
216+
finalStringresponseBody =
217+
IOUtils.toString(ingestResponse.getEntity().getContent());
218+
thrownewCastlabsException("Ingest failed: Response code=" +statusCode
219+
+", Reason=" +reason +", Body=" +responseBody);
216220
}
217-
finalHttpEntityresponseEntity =ticketResponse.getEntity();
221+
finalHttpEntityresponseEntity =ingestResponse.getEntity();
218222
if (responseEntity !=null) {
219-
finalIngestKeysResponsegetPadResponse =objectMapper
220-
.readValue(responseEntity.getContent(),IngestKeysResponse.class);
223+
finalIngestAssetsResponsegetPadResponse =objectMapper
224+
.readValue(responseEntity.getContent(),IngestAssetsResponse.class);
221225
returngetPadResponse;
222226
}else {
223227
thrownewCastlabsException("Empty response entity from Castlabs");
@@ -227,8 +231,8 @@ public IngestKeysResponse ingestKeys(IngestKeysRequest request, String merchantI
227231
}
228232
}finally {
229233
try {
230-
if (ticketResponse !=null)
231-
ticketResponse.close();
234+
if (ingestResponse !=null)
235+
ingestResponse.close();
232236
}catch (IOExceptione) {
233237
// ignore
234238
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright 2015 Brightcove Inc. All rights reserved.
3+
*
4+
* @author Scott Kidder
5+
*/
6+
packagecom.brightcove.castlabs.client.response;
7+
8+
importjava.util.ArrayList;
9+
importjava.util.List;
10+
11+
/**
12+
* @author Scott Kidder
13+
*
14+
*/
15+
publicclassIngestAssetsResponse {
16+
privateList<AssetResponse>assets =newArrayList<AssetResponse>();
17+
18+
publicList<AssetResponse>getAssets() {
19+
returnassets;
20+
}
21+
22+
publicvoidsetAssets(List<AssetResponse>assets) {
23+
this.assets =assets;
24+
}
25+
26+
@Override
27+
publicStringtoString() {
28+
return"IngestAssetsResponse [assets=" +assets +"]";
29+
}
30+
31+
}

‎src/test/java/com/brightcove/castlabs/client/CastlabsClientTest.java‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@
55
*/
66
packagecom.brightcove.castlabs.client;
77

8-
importstaticorg.junit.Assert.*;
8+
importstaticorg.junit.Assert.assertEquals;
9+
importstaticorg.junit.Assert.assertNotNull;
10+
importstaticorg.junit.Assert.fail;
11+
importstaticorg.mockserver.model.HttpRequest.request;
12+
importstaticorg.mockserver.model.HttpResponse.response;
13+
14+
importjava.io.IOException;
15+
importjava.util.concurrent.TimeUnit;
916

1017
importorg.junit.After;
1118
importorg.junit.Before;
@@ -20,13 +27,7 @@
2027
importcom.brightcove.castlabs.client.request.IngestKey;
2128
importcom.brightcove.castlabs.client.request.IngestKeysRequest;
2229
importcom.brightcove.castlabs.client.request.StreamType;
23-
importcom.brightcove.castlabs.client.response.IngestKeysResponse;
24-
25-
importstaticorg.mockserver.model.HttpRequest.*;
26-
importstaticorg.mockserver.model.HttpResponse.*;
27-
28-
importjava.io.IOException;
29-
importjava.util.concurrent.TimeUnit;
30+
importcom.brightcove.castlabs.client.response.IngestAssetsResponse;
3031

3132
/**
3233
* @author Scott Kidder
@@ -234,7 +235,7 @@ public void testIngestKeysGold() throws Exception {
234235
key.setKeyRotationId("1");
235236
asset.getIngestKeys().add(key);
236237
ingestKeysRequest.getAssets().add(asset);
237-
finalIngestKeysResponseingestKeysResponse =
238+
finalIngestAssetsResponseingestKeysResponse =
238239
castlabsClient.ingestKeys(ingestKeysRequest,merchantId);
239240
assertNotNull(ingestKeysResponse);
240241
assertEquals(asset.getAssetId(),asset.getAssetId());

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp