getMethod.addHeader( hdr );
}
try
{
CloseableHttpResponse response = execute( getMethod );
closeable = response;
int statusCode = response.getStatusLine().getStatusCode();
String reasonPhrase = ", ReasonPhrase:" + response.getStatusLine().getReasonPhrase() + ".";
fireTransferDebug( url + " - Status code: " + statusCode + reasonPhrase );
switch ( statusCode )
{
case HttpStatus.SC_OK:
break;
case HttpStatus.SC_NOT_MODIFIED:
// return, leaving last modified set to original value so getIfNewer should return unmodified
return;
case HttpStatus.SC_FORBIDDEN:
fireSessionConnectionRefused();
throw new AuthorizationException( "Access denied to: " + url + " " + reasonPhrase );
case HttpStatus.SC_UNAUTHORIZED:
fireSessionConnectionRefused();
throw new AuthorizationException( "Not authorized " + reasonPhrase );
case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
fireSessionConnectionRefused();
throw new AuthorizationException( "Not authorized by proxy " + reasonPhrase );
case HttpStatus.SC_NOT_FOUND:
throw new ResourceDoesNotExistException( "File: " + url + " " + reasonPhrase );
// add more entries here
default:
{
cleanupGetTransfer( resource );
TransferFailedException e = new TransferFailedException(
"Failed to transfer file: " + url + ". Return code is: " + statusCode + " " + reasonPhrase );
fireTransferError( resource, e, TransferEvent.REQUEST_GET );
throw e;
}
}
Header contentLengthHeader = response.getFirstHeader( "Content-Length" );
if ( contentLengthHeader != null )
{
try
{
long contentLength = Long.parseLong( contentLengthHeader.getValue() );
resource.setContentLength( contentLength );
}
catch ( NumberFormatException e )
{
fireTransferDebug(
"error parsing content length header '" + contentLengthHeader.getValue() + "' " + e );
}
}
Header lastModifiedHeader = response.getFirstHeader( "Last-Modified" );
if ( lastModifiedHeader != null )
{
Date lastModified = DateUtils.parseDate( lastModifiedHeader.getValue() );
if ( lastModified != null )
{
resource.setLastModified( lastModified.getTime() );
fireTransferDebug( "last-modified = " + lastModifiedHeader.getValue() +
" (" + lastModified.getTime() + ")" );
}
}
HttpEntity entity = response.getEntity();
if ( entity != null )
{
inputData.setInputStream( entity.getContent() );
}
}