}
catch ( IOException e )
{
fireTransferError( resource, e, TransferEvent.REQUEST_GET );
throw new TransferFailedException( e.getMessage(), e );
}
catch ( HttpException e )
{
fireTransferError( resource, e, TransferEvent.REQUEST_GET );
throw new TransferFailedException( e.getMessage(), e );
}
statusCode = response.getStatusLine().getStatusCode();
String reasonPhrase = ", ReasonPhrase:" + response.getStatusLine().getReasonPhrase() + ".";
fireTransferDebug( url + " - Status code: " + statusCode + reasonPhrase );
// TODO [BP]: according to httpclient docs, really should swallow the output on error. verify if that is
// required
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 SC_NULL:
{
TransferFailedException e =
new TransferFailedException( "Failed to transfer file: " + url + reasonPhrase );
fireTransferError( resource, e, TransferEvent.REQUEST_GET );
throw e;
}
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;
}
}
InputStream is;
Header contentLengthHeader = response.getFirstHeader( "Content-Length" );
if ( contentLengthHeader != null )
{
try
{
long contentLength = Integer.valueOf( contentLengthHeader.getValue() ).intValue();
resource.setContentLength( contentLength );
}
catch ( NumberFormatException e )
{
fireTransferDebug(
"error parsing content length header '" + contentLengthHeader.getValue() + "' " + e );
}
}
Header lastModifiedHeader = response.getFirstHeader( "Last-Modified" );
long lastModified = 0;
if ( lastModifiedHeader != null )
{
try
{
lastModified = DateUtils.parseDate( lastModifiedHeader.getValue() ).getTime();
resource.setLastModified( lastModified );
}
catch ( DateParseException e )
{
fireTransferDebug( "Unable to parse last modified header" );
}
fireTransferDebug( "last-modified = " + lastModifiedHeader.getValue() + " (" + lastModified + ")" );
}
Header contentEncoding = response.getFirstHeader( "Content-Encoding" );
boolean isGZipped = contentEncoding == null ? false : "gzip".equalsIgnoreCase( contentEncoding.getValue() );
try
{
is = response.getEntity().getContent();
if ( isGZipped )
{
is = new GZIPInputStream( is );
}
}
catch ( IOException e )
{
fireTransferError( resource, e, TransferEvent.REQUEST_GET );
String msg =
"Error occurred while retrieving from remote repository:" + getRepository() + ": " + e.getMessage();
throw new TransferFailedException( msg, e );
}
inputData.setInputStream( is );
}