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

Commitf783e3a

Browse files
author
Scott Kidder
committed
Updated docs
1 parentc0d23d2 commitf783e3a

File tree

2 files changed

+50
-28
lines changed

2 files changed

+50
-28
lines changed

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

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,46 +21,55 @@
2121
importorg.apache.http.message.BasicNameValuePair;
2222

2323
/**
24+
* Client for interacting with the Castlabs key ingestion API.
25+
*
2426
* @author Scott Kidder
2527
*
2628
*/
2729
publicclassCastlabsClient {
2830

29-
privatestaticfinalStringCASTLABS_BASE_URL ="https://auth.drmtoday.com/";
30-
privateStringbaseUrl;
31+
privatestaticfinalStringCASTLABS_AUTH_BASE_URL ="https://auth.drmtoday.com/";
32+
privatestaticfinalStringCASTLABS_INGESTION_BASE_URL ="https://fe.drmtoday.com/";
33+
privateStringauthBaseUrl;
34+
privateStringingestionBaseUrl;
3135
privateStringusername;
3236
privateStringpassword;
3337
privateintconnectionTimeoutSeconds = -1;
3438

3539
publicCastlabsClient(Stringusername,Stringpassword) {
36-
this(username,password,CASTLABS_BASE_URL, -1);
37-
}
38-
39-
publicCastlabsClient(Stringusername,Stringpassword,StringbaseUrl) {
40-
this(username,password,baseUrl, -1);
40+
this(username,password,CASTLABS_AUTH_BASE_URL,CASTLABS_INGESTION_BASE_URL, -1);
4141
}
4242

43-
publicCastlabsClient(Stringusername,Stringpassword,StringbaseUrl,
43+
publicCastlabsClient(Stringusername,Stringpassword,StringauthBaseUrl,StringingestionBaseUrl,
4444
intconnectionTimeoutSeconds) {
4545
this.username =username;
4646
this.password =password;
4747
this.connectionTimeoutSeconds =connectionTimeoutSeconds;
48-
if (baseUrl.endsWith("/")) {
49-
this.baseUrl =baseUrl;
48+
49+
if (authBaseUrl.endsWith("/")) {
50+
this.authBaseUrl =authBaseUrl;
51+
52+
}else {
53+
this.authBaseUrl =authBaseUrl +"/";
54+
}
55+
56+
if (ingestionBaseUrl.endsWith("/")) {
57+
this.ingestionBaseUrl =ingestionBaseUrl;
5058

5159
}else {
52-
this.baseUrl =baseUrl +"/";
60+
this.ingestionBaseUrl =ingestionBaseUrl +"/";
5361
}
5462
}
5563

5664
/**
5765
* Login to the Castlabs API endpoint.
5866
*
59-
* @return
60-
* @throws CastlabsException
67+
* @return a ticket URL
68+
* @throws CastlabsException error reported by Castlabs
69+
* @throws IOException communication error when interacting with Castlabs API
6170
*/
6271
protectedStringlogin()throwsCastlabsException,IOException {
63-
finalHttpPostloginRequest =newHttpPost(this.baseUrl +"cas/v1/tickets");
72+
finalHttpPostloginRequest =newHttpPost(this.authBaseUrl +"cas/v1/tickets");
6473
loginRequest.addHeader("Content-Type","application/x-www-form-urlencoded");
6574
loginRequest.setHeader("Accept","*/*");
6675

@@ -108,14 +117,23 @@ protected String login() throws CastlabsException, IOException {
108117
}
109118
}
110119

111-
120+
121+
/**
122+
* Retrieve an authentication ticket with the given merchant ID.
123+
*
124+
* @param merchantId Castlabs-issued merchant ID
125+
* @return ticket that can be used to ingest encryption keys
126+
* @throws CastlabsException error reported by Castlabs
127+
* @throws IOException communication error when interacting with Castlabs API
128+
*/
112129
publicStringgetTicket(StringmerchantId)throwsCastlabsException,IOException {
113130
finalHttpPostticketRequest =newHttpPost(this.login());
114131
ticketRequest.addHeader("Content-Type","application/x-www-form-urlencoded");
115132
ticketRequest.setHeader("Accept","*/*");
116133

117134
finalList<NameValuePair>entityParts =newArrayList<NameValuePair>();
118-
entityParts.add(newBasicNameValuePair("service","https://fe.drmtoday.com/frontend/rest/keys/v1/cenc/merchant/" +merchantId +"/key"));
135+
entityParts.add(newBasicNameValuePair("service",
136+
this.ingestionBaseUrl +"frontend/api/keys/v2/ingest/" +merchantId));
119137

120138
finalCloseableHttpClienthttpclient =HttpClients.createDefault();
121139
CloseableHttpResponseticketResponse =null;
@@ -134,8 +152,8 @@ public String getTicket(String merchantId) throws CastlabsException, IOException
134152
finalintstatusCode =ticketResponse.getStatusLine().getStatusCode();
135153
finalStringreason =ticketResponse.getStatusLine().getReasonPhrase();
136154
if (200 !=statusCode) {
137-
thrownewCastlabsException(
138-
"Ticket retrieval failed: Response code="+statusCode +", Reason=" +reason);
155+
thrownewCastlabsException("Ticket retrieval failed: Response code="
156+
+statusCode +", Reason=" +reason);
139157
}
140158
}else {
141159
thrownewCastlabsException("No response when retrieving Castlabs ticket");
@@ -148,6 +166,6 @@ public String getTicket(String merchantId) throws CastlabsException, IOException
148166
}catch (IOExceptione) {
149167
// ignore
150168
}
151-
}
169+
}
152170
}
153171
}

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
*/
2929
publicclassCastlabsClientTest {
3030

31+
privatestaticfinalintmockPort =1080;
32+
3133
@Rule
32-
publicMockServerRulemockServerRule =newMockServerRule(1080,this);
34+
publicMockServerRulemockServerRule =newMockServerRule(mockPort,this);
3335

3436
privateMockServerClientmockServerClient;
3537

@@ -45,7 +47,8 @@ public class CastlabsClientTest {
4547
publicvoidsetUp()throwsException {
4648
username ="x";
4749
password ="y";
48-
castlabsClient =newCastlabsClient(username,password,"http://localhost:1080",1);
50+
StringmockURL ="http://localhost:" +mockPort;
51+
castlabsClient =newCastlabsClient(username,password,mockURL,mockURL,1);
4952
}
5053

5154
/**
@@ -119,8 +122,8 @@ public void testTicketRequestWithLoginFailure() {
119122
finalHttpRequestloginRequest =request().withMethod("POST").withPath("/cas/v1/tickets")
120123
.withBody("username=" +username +"&password=" +password)
121124
.withHeader("content-type","application/x-www-form-urlencoded");
122-
mockServerClient.when(loginRequest).respond(response().withStatusCode(401)
123-
.withHeader("location","http://localhost:1080/cas/v1/tickets/" +loginToken));
125+
mockServerClient.when(loginRequest).respond(response().withStatusCode(401).withHeader(
126+
"location","http://localhost:" +mockPort +"/cas/v1/tickets/" +loginToken));
124127

125128
finalHttpRequestticketRequest =
126129
request().withMethod("POST").withPath("/cas/v1/tickets/" +loginToken);
@@ -142,8 +145,8 @@ public void testUnauthorizedTicketRequest() {
142145
finalHttpRequestloginRequest =request().withMethod("POST").withPath("/cas/v1/tickets")
143146
.withBody("username=" +username +"&password=" +password)
144147
.withHeader("content-type","application/x-www-form-urlencoded");
145-
mockServerClient.when(loginRequest).respond(response().withStatusCode(201)
146-
.withHeader("location","http://localhost:1080/cas/v1/tickets/" +loginToken));
148+
mockServerClient.when(loginRequest).respond(response().withStatusCode(201).withHeader(
149+
"location","http://localhost:" +mockPort +"/cas/v1/tickets/" +loginToken));
147150

148151
finalHttpRequestticketRequest =
149152
request().withMethod("POST").withPath("/cas/v1/tickets/" +loginToken);
@@ -166,12 +169,13 @@ public void testTicketRequestGold() throws Exception {
166169
finalHttpRequestloginRequest =request().withMethod("POST").withPath("/cas/v1/tickets")
167170
.withBody("username=" +username +"&password=" +password)
168171
.withHeader("content-type","application/x-www-form-urlencoded");
169-
mockServerClient.when(loginRequest).respond(response().withStatusCode(201)
170-
.withHeader("location","http://localhost:1080/cas/v1/tickets/" +loginToken));
172+
mockServerClient.when(loginRequest).respond(response().withStatusCode(201).withHeader(
173+
"location","http://localhost:" +mockPort +"/cas/v1/tickets/" +loginToken));
171174

172175
finalHttpRequestticketRequest =
173176
request().withMethod("POST").withPath("/cas/v1/tickets/" +loginToken);
174-
mockServerClient.when(ticketRequest).respond(response().withStatusCode(200).withBody("F40D6052-236F-4942-9C51-DD01C15A14C6"));
177+
mockServerClient.when(ticketRequest).respond(
178+
response().withStatusCode(200).withBody("F40D6052-236F-4942-9C51-DD01C15A14C6"));
175179
finalStringticket =castlabsClient.getTicket("merchX");
176180
assertNotNull(ticket);
177181
assertEquals("F40D6052-236F-4942-9C51-DD01C15A14C6",ticket);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp