throw new PlaybackException( msg, e );
}
}
protected ResponseData execute( HttpClient client, HttpMethod method ) throws PlaybackException, IOException {
ResponseData response = new ResponseData( method.getHostConfiguration().getHost(),
method.getHostConfiguration().getPort() );
int statusCode = -1;
// retry up to 3 times.
for ( int attempt = 0; statusCode == -1 && attempt < 3; attempt++ ) {
try {
statusCode = client.executeMethod( method );
}
catch ( HttpRecoverableException e ) {
if ( log.isWarnEnabled() ) {
String msg = "A recoverable exception occurred calling URI( " + method.getURI() +
" ), retrying. exception( " + e.getMessage() + " )";
log.error( msg, e );
}
}
catch ( IOException e ) {
String msg = "Failed executing request( " + method.getURI() + " ), exception( " + e.getMessage() +
" )";
log.error( msg, e );
throw e;
}
}
// Retries failed
if ( statusCode == -1 ) {
String msg = "Failed to execute request( " + method.getURI() + " )";
log.error( msg );
throw new PlaybackException( msg );
}
response.setStatusCode( statusCode );
byte[] responseBody = method.getResponseBody();
response.setBody( new String( responseBody ) );
if ( log.isDebugEnabled() ) {
log.debug( "statusCode( " + statusCode + " )" );
// log.debug( "response body:\n" + response.getBody() + "\n" );
}
response.setHeaders( convertHeaders( method.getResponseHeaders() ) );
method.releaseConnection();
return response;
}