catch ( IOException e )
{
fireTransferError( resource, e, TransferEvent.REQUEST_GET );
}
HttpPut putMethod = new HttpPut( url.toString() );
firePutStarted( resource, source );
try
{
putMethod.setEntity( httpEntity );
HttpResponse response;
try
{
response = execute( putMethod );
}
catch ( IOException e )
{
fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
throw new TransferFailedException( e.getMessage(), e );
}
catch ( HttpException e )
{
fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
throw new TransferFailedException( e.getMessage(), e );
}
int statusCode = response.getStatusLine().getStatusCode();
String reasonPhrase = ", ReasonPhrase:" + response.getStatusLine().getReasonPhrase() + ".";
fireTransferDebug( url + " - Status code: " + statusCode + reasonPhrase );
// Check that we didn't run out of retries.
switch ( statusCode )
{
// Success Codes
case HttpStatus.SC_OK: // 200
case HttpStatus.SC_CREATED: // 201
case HttpStatus.SC_ACCEPTED: // 202
case HttpStatus.SC_NO_CONTENT: // 204
break;
case SC_NULL:
{
TransferFailedException e =
new TransferFailedException( "Failed to transfer file: " + url + reasonPhrase );
fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
throw e;
}
case HttpStatus.SC_FORBIDDEN:
fireSessionConnectionRefused();
throw new AuthorizationException( "Access denied to: " + url + reasonPhrase );
case HttpStatus.SC_NOT_FOUND:
throw new ResourceDoesNotExistException( "File: " + url + " does not exist" + reasonPhrase );
//add more entries here
default:
{
TransferFailedException e = new TransferFailedException(
"Failed to transfer file: " + url + ". Return code is: " + statusCode + reasonPhrase );
fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
throw e;
}
}
firePutCompleted( resource, source );
}
finally
{
putMethod.abort();
}
}