@@ -380,14 +380,13 @@ private Channel createQueues(Connection connection) throws IOException, URISynta
380
380
channel .queueDeclare (queueName , true , false , false , null );
381
381
}
382
382
}
383
- if (this .management && !alivenessTest ()) {
384
- throw new BrokerNotAliveException ("Aliveness test failed for localhost:15672 guest/quest; "
385
- + "management not available" );
383
+ if (this .management ) {
384
+ alivenessTest ();
386
385
}
387
386
return channel ;
388
387
}
389
388
390
- private boolean alivenessTest () throws URISyntaxException {
389
+ private void alivenessTest () throws URISyntaxException {
391
390
HttpClient client = HttpClient .newBuilder ()
392
391
.authenticator (new Authenticator () {
393
392
@@ -409,18 +408,22 @@ protected PasswordAuthentication getPasswordAuthentication() {
409
408
response = client .send (request , BodyHandlers .ofString ());
410
409
}
411
410
catch (IOException ex ) {
412
- LOGGER .error ("Exception checking admin aliveness" , ex );
413
- return false ;
411
+ throw new BrokerNotAliveException ("Failed to check aliveness" , ex );
414
412
}
415
413
catch (InterruptedException ex ) {
416
414
Thread .currentThread ().interrupt ();
417
- return false ;
415
+ throw new BrokerNotAliveException ( "Interrupted while checking aliveness" , ex ) ;
418
416
}
419
417
String body = null ;
420
418
if (response .statusCode () == HttpStatus .OK .value ()) {
421
- response .body ();
419
+ body = response .body ();
420
+ }
421
+ if (body == null || !body .contentEquals ("{\" status\" :\" ok\" }" )) {
422
+ throw new BrokerNotAliveException ("Aliveness test failed for " + uri .toString ()
423
+ + " user: " + getAdminUser () + " pw: " + getAdminPassword ()
424
+ + " status: " + response .statusCode () + " body: " + body
425
+ + "; management not available" );
422
426
}
423
- return body != null && body .contentEquals ("{\" status\" :\" ok\" }" );
424
427
}
425
428
426
429
public static boolean fatal () {
0 commit comments