mirror of https://github.com/apache/archiva.git
improve logging of failed uploads
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@917519 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
31891b80e4
commit
09f8d89c57
|
@ -19,14 +19,6 @@ package org.apache.maven.archiva.webdav;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.archiva.scheduler.ArchivaTaskScheduler;
|
||||
import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler;
|
||||
import org.apache.archiva.scheduler.repository.RepositoryTask;
|
||||
|
@ -67,6 +59,14 @@ import org.joda.time.format.ISODateTimeFormat;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class ArchivaDavResource
|
||||
|
@ -125,9 +125,9 @@ public class ArchivaDavResource
|
|||
}
|
||||
|
||||
public ArchivaDavResource( String localResource, String logicalResource, ManagedRepositoryConfiguration repository,
|
||||
String remoteAddr, String principal, DavSession session, ArchivaDavResourceLocator locator,
|
||||
DavResourceFactory factory, MimeTypes mimeTypes, List<AuditListener> auditListeners,
|
||||
RepositoryArchivaTaskScheduler scheduler )
|
||||
String remoteAddr, String principal, DavSession session,
|
||||
ArchivaDavResourceLocator locator, DavResourceFactory factory, MimeTypes mimeTypes,
|
||||
List<AuditListener> auditListeners, RepositoryArchivaTaskScheduler scheduler )
|
||||
{
|
||||
this( localResource, logicalResource, repository, session, locator, factory, mimeTypes, auditListeners,
|
||||
scheduler );
|
||||
|
@ -190,7 +190,7 @@ public class ArchivaDavResource
|
|||
public void spool( OutputContext outputContext )
|
||||
throws IOException
|
||||
{
|
||||
if ( !isCollection())
|
||||
if ( !isCollection() )
|
||||
{
|
||||
outputContext.setContentLength( localResource.length() );
|
||||
outputContext.setContentType( mimeTypes.getMimeType( localResource.getName() ) );
|
||||
|
@ -210,7 +210,7 @@ public class ArchivaDavResource
|
|||
IOUtils.closeQuietly( is );
|
||||
}
|
||||
}
|
||||
else if (outputContext.hasStream())
|
||||
else if ( outputContext.hasStream() )
|
||||
{
|
||||
IndexWriter writer = new IndexWriter( this, localResource, logicalResource );
|
||||
writer.write( outputContext );
|
||||
|
@ -248,7 +248,7 @@ public class ArchivaDavResource
|
|||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings( "unchecked" )
|
||||
public MultiStatusResponse alterProperties( List changeList )
|
||||
throws DavException
|
||||
{
|
||||
|
@ -265,7 +265,8 @@ public class ArchivaDavResource
|
|||
{
|
||||
parentPath = "/";
|
||||
}
|
||||
DavResourceLocator parentloc = locator.getFactory().createResourceLocator( locator.getPrefix(), parentPath );
|
||||
DavResourceLocator parentloc = locator.getFactory().createResourceLocator( locator.getPrefix(),
|
||||
parentPath );
|
||||
try
|
||||
{
|
||||
parent = factory.createResource( parentloc, session );
|
||||
|
@ -306,13 +307,17 @@ public class ArchivaDavResource
|
|||
{
|
||||
FileUtils.deleteQuietly( localFile );
|
||||
|
||||
throw new DavException( HttpServletResponse.SC_BAD_REQUEST, "Content Header length was " +
|
||||
inputContext.getContentLength() + " but was " + localFile.length() );
|
||||
String msg =
|
||||
"Content Header length was " + inputContext.getContentLength() + " but was " + localFile.length();
|
||||
log.debug( "Upload failed: " + msg );
|
||||
throw new DavException( HttpServletResponse.SC_BAD_REQUEST, msg );
|
||||
}
|
||||
|
||||
queueRepositoryTask( localFile );
|
||||
|
||||
log.debug( "File '" + resource.getDisplayName() + ( exists ? "' modified " : "' created ") + "(current user '" + this.principal + "')" );
|
||||
log.debug(
|
||||
"File '" + resource.getDisplayName() + ( exists ? "' modified " : "' created " ) + "(current user '" +
|
||||
this.principal + "')" );
|
||||
|
||||
triggerAuditEvent( resource, exists ? AuditEvent.MODIFY_FILE : AuditEvent.CREATE_FILE );
|
||||
}
|
||||
|
@ -326,8 +331,10 @@ public class ArchivaDavResource
|
|||
}
|
||||
else
|
||||
{
|
||||
throw new DavException( HttpServletResponse.SC_BAD_REQUEST, "Could not write member " +
|
||||
resource.getResourcePath() + " at " + getResourcePath() );
|
||||
String msg = "Could not write member " + resource.getResourcePath() + " at " + getResourcePath() +
|
||||
" as this is not a DAV collection";
|
||||
log.debug( msg );
|
||||
throw new DavException( HttpServletResponse.SC_BAD_REQUEST, msg );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -343,8 +350,8 @@ public class ArchivaDavResource
|
|||
if ( !item.startsWith( HIDDEN_PATH_PREFIX ) )
|
||||
{
|
||||
String path = locator.getResourcePath() + '/' + item;
|
||||
DavResourceLocator resourceLocator =
|
||||
locator.getFactory().createResourceLocator( locator.getPrefix(), path );
|
||||
DavResourceLocator resourceLocator = locator.getFactory().createResourceLocator(
|
||||
locator.getPrefix(), path );
|
||||
DavResource resource = factory.createResource( resourceLocator, session );
|
||||
|
||||
if ( resource != null )
|
||||
|
@ -387,7 +394,8 @@ public class ArchivaDavResource
|
|||
|
||||
triggerAuditEvent( member, AuditEvent.REMOVE_FILE );
|
||||
}
|
||||
log.debug( ( resource.isDirectory() ? "Directory '" : "File '" ) + member.getDisplayName() + "' removed (current user '" + this.principal + "')" );
|
||||
log.debug( ( resource.isDirectory() ? "Directory '" : "File '" ) + member.getDisplayName() +
|
||||
"' removed (current user '" + this.principal + "')" );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
|
@ -400,7 +408,8 @@ public class ArchivaDavResource
|
|||
}
|
||||
}
|
||||
|
||||
private void triggerAuditEvent( DavResource member, String event ) throws DavException
|
||||
private void triggerAuditEvent( DavResource member, String event )
|
||||
throws DavException
|
||||
{
|
||||
String path = logicalResource + "/" + member.getDisplayName();
|
||||
|
||||
|
@ -486,41 +495,41 @@ public class ArchivaDavResource
|
|||
|
||||
public boolean isLockable( Type type, Scope scope )
|
||||
{
|
||||
return Type.WRITE.equals(type) && Scope.EXCLUSIVE.equals(scope);
|
||||
return Type.WRITE.equals( type ) && Scope.EXCLUSIVE.equals( scope );
|
||||
}
|
||||
|
||||
public boolean hasLock( Type type, Scope scope )
|
||||
{
|
||||
return getLock(type, scope) != null;
|
||||
return getLock( type, scope ) != null;
|
||||
}
|
||||
|
||||
public ActiveLock getLock( Type type, Scope scope )
|
||||
{
|
||||
ActiveLock lock = null;
|
||||
if (exists() && Type.WRITE.equals(type) && Scope.EXCLUSIVE.equals(scope))
|
||||
if ( exists() && Type.WRITE.equals( type ) && Scope.EXCLUSIVE.equals( scope ) )
|
||||
{
|
||||
lock = lockManager.getLock(type, scope, this);
|
||||
lock = lockManager.getLock( type, scope, this );
|
||||
}
|
||||
return lock;
|
||||
}
|
||||
|
||||
public ActiveLock[] getLocks()
|
||||
{
|
||||
ActiveLock writeLock = getLock(Type.WRITE, Scope.EXCLUSIVE);
|
||||
return (writeLock != null) ? new ActiveLock[]{writeLock} : new ActiveLock[0];
|
||||
ActiveLock writeLock = getLock( Type.WRITE, Scope.EXCLUSIVE );
|
||||
return ( writeLock != null ) ? new ActiveLock[]{writeLock} : new ActiveLock[0];
|
||||
}
|
||||
|
||||
public ActiveLock lock( LockInfo lockInfo )
|
||||
throws DavException
|
||||
{
|
||||
ActiveLock lock = null;
|
||||
if (isLockable(lockInfo.getType(), lockInfo.getScope()))
|
||||
if ( isLockable( lockInfo.getType(), lockInfo.getScope() ) )
|
||||
{
|
||||
lock = lockManager.createLock(lockInfo, this);
|
||||
lock = lockManager.createLock( lockInfo, this );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "Unsupported lock type or scope.");
|
||||
throw new DavException( DavServletResponse.SC_PRECONDITION_FAILED, "Unsupported lock type or scope." );
|
||||
}
|
||||
return lock;
|
||||
}
|
||||
|
@ -528,15 +537,18 @@ public class ArchivaDavResource
|
|||
public ActiveLock refreshLock( LockInfo lockInfo, String lockToken )
|
||||
throws DavException
|
||||
{
|
||||
if (!exists()) {
|
||||
throw new DavException(DavServletResponse.SC_NOT_FOUND);
|
||||
if ( !exists() )
|
||||
{
|
||||
throw new DavException( DavServletResponse.SC_NOT_FOUND );
|
||||
}
|
||||
ActiveLock lock = getLock(lockInfo.getType(), lockInfo.getScope());
|
||||
if (lock == null) {
|
||||
throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "No lock with the given type/scope present on resource " + getResourcePath());
|
||||
ActiveLock lock = getLock( lockInfo.getType(), lockInfo.getScope() );
|
||||
if ( lock == null )
|
||||
{
|
||||
throw new DavException( DavServletResponse.SC_PRECONDITION_FAILED,
|
||||
"No lock with the given type/scope present on resource " + getResourcePath() );
|
||||
}
|
||||
|
||||
lock = lockManager.refreshLock(lockInfo, lockToken, this);
|
||||
lock = lockManager.refreshLock( lockInfo, lockToken, this );
|
||||
|
||||
return lock;
|
||||
}
|
||||
|
@ -544,18 +556,18 @@ public class ArchivaDavResource
|
|||
public void unlock( String lockToken )
|
||||
throws DavException
|
||||
{
|
||||
ActiveLock lock = getLock(Type.WRITE, Scope.EXCLUSIVE);
|
||||
if (lock == null)
|
||||
ActiveLock lock = getLock( Type.WRITE, Scope.EXCLUSIVE );
|
||||
if ( lock == null )
|
||||
{
|
||||
throw new DavException(HttpServletResponse.SC_PRECONDITION_FAILED);
|
||||
throw new DavException( HttpServletResponse.SC_PRECONDITION_FAILED );
|
||||
}
|
||||
else if (lock.isLockedByToken(lockToken))
|
||||
else if ( lock.isLockedByToken( lockToken ) )
|
||||
{
|
||||
lockManager.releaseLock(lockToken, this);
|
||||
lockManager.releaseLock( lockToken, this );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new DavException(DavServletResponse.SC_LOCKED);
|
||||
throw new DavException( DavServletResponse.SC_LOCKED );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -662,8 +674,9 @@ public class ArchivaDavResource
|
|||
}
|
||||
catch ( TaskQueueException e )
|
||||
{
|
||||
log.error( "Unable to queue repository task to execute consumers on resource file ['" +
|
||||
localFile.getName() + "']." );
|
||||
log.error(
|
||||
"Unable to queue repository task to execute consumers on resource file ['" + localFile.getName() +
|
||||
"']." );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue