public boolean preflightRequest ( ) { final HttpURLConnection conn ; try { final URL url = new URL ( rootURL , "status" ) ; final URLConnectionFactory factory = new URLConnectionFactory ( settings ) ; conn = factory . createHttpURLConnection ( url , useProxy ) ; conn . addRequestProperty ( "Accept" , "application/xml" ) ; final String authHeader = buildHttpAuthHeaderValue ( ) ; if ( ! authHeader . isEmpty ( ) ) { conn . addRequestProperty ( "Authorization" , authHeader ) ; } conn . connect ( ) ; if ( conn . getResponseCode ( ) != 200 ) { LOGGER . warn ( "Expected 200 result from Nexus, got {}" , conn . getResponseCode ( ) ) ; return false ; } final DocumentBuilder builder = XmlUtils . buildSecureDocumentBuilder ( ) ; final Document doc = builder . parse ( conn . getInputStream ( ) ) ; if ( ! "status" . equals ( doc . getDocumentElement ( ) . getNodeName ( ) ) ) { LOGGER . warn ( "Expected root node name of status, got {}" , doc . getDocumentElement ( ) . getNodeName ( ) ) ; return false ; } } catch ( IOException | ParserConfigurationException | SAXException e ) { return false ; } return true ; }
Do a preflight request to see if the repository is actually working .