private void sendMessage ( String aspectPath , boolean fired ) { if ( Boolean . valueOf ( _config . getValue ( SystemConfiguration . Property . REFOCUS_ENABLED ) ) ) { int refreshMaxTimes = Integer . parseInt ( _config . getValue ( Property . REFOCUS_CONNECTION_REFRESH_MAX_TIMES . getName ( ) , Property . REFOCUS_CONNECTION_REFRESH_MAX_TIMES . getDefaultValue ( ) ) ) ; try { //TODO: get customer specified refocus sample values when UI is ready, currently use '1' for active trigger and '0' for non-active trigger RefocusSample refocusSample = new RefocusSample ( aspectPath , fired ? "1" : "0" ) ; RefocusTransport refocusTransport = RefocusTransport . getInstance ( ) ; HttpClient httpclient = refocusTransport . getHttpClient ( _config ) ; PostMethod post = null ; try { post = new PostMethod ( String . format ( "%s/v1/samples/upsert" , endpoint ) ) ; post . setRequestHeader ( "Authorization" , token ) ; post . setRequestEntity ( new StringRequestEntity ( refocusSample . toJSON ( ) , "application/json" , null ) ) ; for ( int i = 0 ; i < 1 + refreshMaxTimes ; i ++ ) { int respCode = httpclient . executeMethod ( post ) ; // Check for success if ( respCode == 200 || respCode == 201 || respCode == 204 ) { _logger . info ( "Success - send Refocus sample '{}'." , refocusSample . toJSON ( ) ) ; break ; } else if ( respCode == 401 ) { // Indication that the session timedout, Need to refresh and retry continue ; } else { _logger . error ( "Failure - send Refocus sample '{}'. Response code '{}' response '{}'" , refocusSample . toJSON ( ) , respCode , post . getResponseBodyAsString ( ) ) ; break ; } } } catch ( Exception e ) { _logger . error ( "Failure - send Refocus sample '{}'. Exception '{}'" , refocusSample . toJSON ( ) , e ) ; } finally { if ( post != null ) { post . releaseConnection ( ) ; } } } catch ( RuntimeException ex ) { throw new SystemException ( "Failed to send an Refocus notification." , ex ) ; } } else { _logger . info ( "Sending Refocus notification is disabled. Not sending message for aspect '{}'." , aspectPath ) ; } }
Sends an Refocus sample .