@@ -380,14 +380,13 @@ private Channel createQueues(Connection connection) throws IOException, URISynta
380380 channel .queueDeclare (queueName , true , false , false , null );
381381 }
382382 }
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 ();
386385 }
387386 return channel ;
388387 }
389388
390- private boolean alivenessTest () throws URISyntaxException {
389+ private void alivenessTest () throws URISyntaxException {
391390 HttpClient client = HttpClient .newBuilder ()
392391 .authenticator (new Authenticator () {
393392
@@ -409,18 +408,22 @@ protected PasswordAuthentication getPasswordAuthentication() {
409408 response = client .send (request , BodyHandlers .ofString ());
410409 }
411410 catch (IOException ex ) {
412- LOGGER .error ("Exception checking admin aliveness" , ex );
413- return false ;
411+ throw new BrokerNotAliveException ("Failed to check aliveness" , ex );
414412 }
415413 catch (InterruptedException ex ) {
416414 Thread .currentThread ().interrupt ();
417- return false ;
415+ throw new BrokerNotAliveException ( "Interrupted while checking aliveness" , ex ) ;
418416 }
419417 String body = null ;
420418 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" );
422426 }
423- return body != null && body .contentEquals ("{\" status\" :\" ok\" }" );
424427 }
425428
426429 public static boolean fatal () {
0 commit comments