public static List < HistoryEntry > getHistory ( String siteUri , int limit , boolean filter , String token ) throws URISyntaxException , IOException , ClientProtocolException , Exception { if ( ! siteUri . endsWith ( "/system/history" ) ) { siteUri += "/system/history" ; } List < HistoryEntry > history = null ; HttpClient httpClient = httpClient ( ) ; HttpGet get = null ; try { URIBuilder uriBuilder = new URIBuilder ( siteUri ) ; if ( limit > 0 ) { uriBuilder . addParameter ( "limit" , limit + "" ) ; } if ( filter ) { uriBuilder . addParameter ( "filter" , filter + "" ) ; } URI uri = uriBuilder . build ( ) ; get = new HttpGet ( uri ) ; addAuthHeader ( token , get ) ; HttpResponse resp = httpClient . execute ( get ) ; if ( resp . getStatusLine ( ) . getStatusCode ( ) == HttpStatus . SC_OK ) { HttpEntity entity = resp . getEntity ( ) ; if ( entity . getContentType ( ) . getValue ( ) . equals ( "application/json" ) ) { String responseContent = EntityUtils . toString ( entity ) ; Gson gson = new GsonBuilder ( ) . registerTypeAdapter ( Date . class , new JsonDeserializer < Date > ( ) { @ Override public Date deserialize ( JsonElement json , Type typeOfT , JsonDeserializationContext ctx ) throws JsonParseException { return new Date ( json . getAsLong ( ) ) ; } } ) . create ( ) ; history = gson . fromJson ( responseContent , new TypeToken < List < HistoryEntry > > ( ) { } . getType ( ) ) ; } else { System . err . println ( "Invalid response content type [" + entity . getContentType ( ) . getValue ( ) + "]" ) ; System . exit ( 1 ) ; } } else { System . err . println ( "Request failed due to a [" + resp . getStatusLine ( ) . getStatusCode ( ) + ":" + resp . getStatusLine ( ) . getReasonPhrase ( ) + "] response from the remote server." ) ; System . exit ( 1 ) ; } } finally { if ( get != null ) { get . releaseConnection ( ) ; } } return history ; }
Retrieves the history of a Cadmium site .