@@ -126,13 +126,15 @@ public void testAuthorizationCodeGrant() throws Exception {
126126 // Get Authorization Code
127127 String code = OAuth2TestUtils .getAuthorizationCode (client );
128128 assertNotNull (code );
129+ client .close ();
129130
130131 // Now get the access token
131132 client = WebClient .create (address , "consumer-id" , "this-is-a-secret" , null );
132133
133134 ClientAccessToken accessToken =
134135 OAuth2TestUtils .getAccessTokenWithAuthorizationCode (client , code );
135136 assertNotNull (accessToken .getTokenKey ());
137+ client .close ();
136138
137139 if (isAccessTokenInJWTFormat ()) {
138140 validateAccessToken (accessToken .getTokenKey ());
@@ -165,13 +167,15 @@ public void testAuthorizationCodeGrantPOST() throws Exception {
165167 String location = OAuth2TestUtils .getLocation (client , authzData , null );
166168 String code = OAuth2TestUtils .getSubstring (location , "code" );
167169 assertNotNull (code );
170+ client .close ();
168171
169172 // Now get the access token
170173 client = WebClient .create (address , "consumer-id" , "this-is-a-secret" , null );
171174
172175 ClientAccessToken accessToken =
173176 OAuth2TestUtils .getAccessTokenWithAuthorizationCode (client , code );
174177 assertNotNull (accessToken .getTokenKey ());
178+ client .close ();
175179
176180 if (isAccessTokenInJWTFormat ()) {
177181 validateAccessToken (accessToken .getTokenKey ());
@@ -190,6 +194,7 @@ public void testAuthorizationCodeGrantRefresh() throws Exception {
190194 // Get Authorization Code
191195 String code = OAuth2TestUtils .getAuthorizationCode (client );
192196 assertNotNull (code );
197+ client .close ();
193198
194199 // Now get the access token
195200 client = WebClient .create (address , OAuth2TestUtils .setupProviders (),
@@ -214,6 +219,7 @@ public void testAuthorizationCodeGrantRefresh() throws Exception {
214219 accessToken = client .post (form , ClientAccessToken .class );
215220 assertNotNull (accessToken .getTokenKey ());
216221 assertNotNull (accessToken .getRefreshToken ());
222+ client .close ();
217223
218224 if (isAccessTokenInJWTFormat ()) {
219225 validateAccessToken (accessToken .getTokenKey ());
@@ -232,6 +238,7 @@ public void testAuthorizationCodeGrantRefreshWithScope() throws Exception {
232238 // Get Authorization Code
233239 String code = OAuth2TestUtils .getAuthorizationCode (client , "read_balance" );
234240 assertNotNull (code );
241+ client .close ();
235242
236243 // Now get the access token
237244 client = WebClient .create (address , OAuth2TestUtils .setupProviders (),
@@ -258,6 +265,7 @@ public void testAuthorizationCodeGrantRefreshWithScope() throws Exception {
258265 assertNotNull (accessToken .getTokenKey ());
259266 assertNotNull (accessToken .getRefreshToken ());
260267 assertEquals ("read_balance" , accessToken .getApprovedScope ());
268+ client .close ();
261269
262270 if (isAccessTokenInJWTFormat ()) {
263271 validateAccessToken (accessToken .getTokenKey ());
@@ -277,6 +285,7 @@ public void testAuthorizationCodeGrantRefreshWithoutScope() throws Exception {
277285 // Get Authorization Code
278286 String code = OAuth2TestUtils .getAuthorizationCode (client , "read_balance" );
279287 assertNotNull (code );
288+ client .close ();
280289
281290 // Now get the access token
282291 client = WebClient .create (address , OAuth2TestUtils .setupProviders (),
@@ -302,6 +311,7 @@ public void testAuthorizationCodeGrantRefreshWithoutScope() throws Exception {
302311 assertNotNull (accessToken .getTokenKey ());
303312 assertNotNull (accessToken .getRefreshToken ());
304313// assertEquals("read_balance", accessToken.getApprovedScope());
314+ client .close ();
305315
306316 if (isAccessTokenInJWTFormat ()) {
307317 validateAccessToken (accessToken .getTokenKey ());
@@ -320,13 +330,15 @@ public void testAuthorizationCodeGrantWithScope() throws Exception {
320330 // Get Authorization Code
321331 String code = OAuth2TestUtils .getAuthorizationCode (client , "read_balance" );
322332 assertNotNull (code );
333+ client .close ();
323334
324335 // Now get the access token
325336 client = WebClient .create (address , "consumer-id" , "this-is-a-secret" , null );
326337
327338 ClientAccessToken accessToken =
328339 OAuth2TestUtils .getAccessTokenWithAuthorizationCode (client , code );
329340 assertNotNull (accessToken .getTokenKey ());
341+ client .close ();
330342 }
331343
332344 @ org .junit .Test
@@ -343,13 +355,15 @@ public void testAuthorizationCodeGrantWithState() throws Exception {
343355 String code = OAuth2TestUtils .getAuthorizationCode (client , "read_balance" , "consumer-id" ,
344356 null , state );
345357 assertNotNull (code );
358+ client .close ();
346359
347360 // Now get the access token
348361 client = WebClient .create (address , "consumer-id" , "this-is-a-secret" , null );
349362
350363 ClientAccessToken accessToken =
351364 OAuth2TestUtils .getAccessTokenWithAuthorizationCode (client , code );
352365 assertNotNull (accessToken .getTokenKey ());
366+ client .close ();
353367 }
354368
355369 @ org .junit .Test
@@ -364,6 +378,7 @@ public void testAuthorizationCodeGrantWithAudience() throws Exception {
364378 // Get Authorization Code
365379 String code = OAuth2TestUtils .getAuthorizationCode (client , null , "consumer-id-aud" );
366380 assertNotNull (code );
381+ client .close ();
367382
368383 // Now get the access token
369384 client = WebClient .create (address , "consumer-id-aud" , "this-is-a-secret" , null );
@@ -383,6 +398,7 @@ public void testAuthorizationCodeGrantWithAudience() throws Exception {
383398 OAuth2TestUtils .getAccessTokenWithAuthorizationCode (client , code ,
384399 "consumer-id-aud" , audience );
385400 assertNotNull (accessToken .getTokenKey ());
401+ client .close ();
386402 }
387403
388404 @ org .junit .Test
@@ -414,10 +430,15 @@ public void testImplicitGrant() throws Exception {
414430 form .param ("oauthDecision" , "allow" );
415431
416432 Response response = client .post (form );
417-
418- String location = response .getHeaderString ("Location" );
433+ String location ;
434+ try {
435+ location = response .getHeaderString ("Location" );
436+ } finally {
437+ response .close ();
438+ }
419439 String accessToken = OAuth2TestUtils .getSubstring (location , "access_token" );
420440 assertNotNull (accessToken );
441+ client .close ();
421442
422443 if (isAccessTokenInJWTFormat ()) {
423444 validateAccessToken (accessToken );
@@ -442,6 +463,7 @@ public void testPasswordsCredentialsGrant() throws Exception {
442463 ClientAccessToken accessToken = client .post (form , ClientAccessToken .class );
443464 assertNotNull (accessToken .getTokenKey ());
444465 assertNotNull (accessToken .getRefreshToken ());
466+ client .close ();
445467
446468 if (isAccessTokenInJWTFormat ()) {
447469 validateAccessToken (accessToken .getTokenKey ());
@@ -464,6 +486,7 @@ public void testClientCredentialsGrant() throws Exception {
464486 ClientAccessToken accessToken = client .post (form , ClientAccessToken .class );
465487 assertNotNull (accessToken .getTokenKey ());
466488 assertNotNull (accessToken .getRefreshToken ());
489+ client .close ();
467490
468491 if (isAccessTokenInJWTFormat ()) {
469492 validateAccessToken (accessToken .getTokenKey ());
@@ -491,6 +514,7 @@ public void testSAMLAuthorizationGrant() throws Exception {
491514 ClientAccessToken accessToken = client .post (form , ClientAccessToken .class );
492515 assertNotNull (accessToken .getTokenKey ());
493516 assertNotNull (accessToken .getRefreshToken ());
517+ client .close ();
494518
495519 if (isAccessTokenInJWTFormat ()) {
496520 validateAccessToken (accessToken .getTokenKey ());
@@ -519,6 +543,7 @@ public void testJWTAuthorizationGrant() throws Exception {
519543 ClientAccessToken accessToken = client .post (form , ClientAccessToken .class );
520544 assertNotNull (accessToken .getTokenKey ());
521545 assertNotNull (accessToken .getRefreshToken ());
546+ client .close ();
522547
523548 if (isAccessTokenInJWTFormat ()) {
524549 validateAccessToken (accessToken .getTokenKey ());
0 commit comments