Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
NXCM-4852: Client drops connection during upload.
Browse files Browse the repository at this point in the history
Introduced new LS exception that denotes EOF situation.
Most likely we really need to get rid of StorageException
altogether.
  • Loading branch information
cstamas committed Dec 7, 2012
1 parent 6c63b70 commit 0e6ef37
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2007-2012 Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.sonatype.nexus.proxy;

/**
* Local storage exception thrown by local storage when stream/content being pushed (stored) ends prematurely (EOFs).
* Denotes an unrecoverable state, but is not resolvable by Nexus core (happens when client drops connection
* during upload, recovery is to have client retry upload).
*
* @author cstamas
* @since 2.3
*/
public class LocalStorageEofException
extends LocalStorageException
{
public LocalStorageEofException( String msg )
{
super( msg );
}

public LocalStorageEofException( String msg, Throwable cause )
{
super( msg, cause );
}

public LocalStorageEofException( Throwable cause )
{
super( cause.getMessage(), cause );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

import static com.google.common.base.Preconditions.checkNotNull;

import java.io.EOFException;
import java.io.File;
import java.io.FileFilter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand All @@ -31,11 +31,11 @@
import org.codehaus.plexus.util.IOUtil;
import org.sonatype.nexus.logging.AbstractLoggingComponent;
import org.sonatype.nexus.proxy.ItemNotFoundException;
import org.sonatype.nexus.proxy.LocalStorageEofException;
import org.sonatype.nexus.proxy.LocalStorageException;
import org.sonatype.nexus.proxy.ResourceStoreRequest;
import org.sonatype.nexus.proxy.access.Action;
import org.sonatype.nexus.proxy.item.ContentLocator;
import org.sonatype.nexus.proxy.item.RepositoryItemUid;
import org.sonatype.nexus.proxy.item.RepositoryItemUidLock;
import org.sonatype.nexus.proxy.item.StorageItem;
import org.sonatype.nexus.proxy.item.uid.IsItemAttributeMetacontentAttribute;
Expand Down Expand Up @@ -113,6 +113,17 @@ public void storeItem( final Repository repository, final File repositoryBaseDir

os.flush();
}
catch ( EOFException e )
{
if ( hiddenTarget != null )
{
hiddenTarget.delete();
}

throw new LocalStorageEofException( String.format(
"EOF during storing on path \"%s\" (while writing to hiddenTarget: \"%s\")",
item.getRepositoryItemUid().toString(), hiddenTarget.getAbsolutePath() ), e );
}
catch ( IOException e )
{
if ( hiddenTarget != null )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.sonatype.nexus.proxy.IllegalOperationException;
import org.sonatype.nexus.proxy.IllegalRequestException;
import org.sonatype.nexus.proxy.ItemNotFoundException;
import org.sonatype.nexus.proxy.LocalStorageEofException;
import org.sonatype.nexus.proxy.NoSuchRepositoryException;
import org.sonatype.nexus.proxy.NoSuchResourceStoreException;
import org.sonatype.nexus.proxy.RemoteStorageTransportOverloadedException;
Expand Down Expand Up @@ -881,6 +882,12 @@ protected void handleException( final Request req, final Response res, final Exc
{
throw (ResourceException) t;
}
else if ( t instanceof LocalStorageEofException )
{
// not that it makes much sense, as client will not receive response anyway
// it dropped connection on us!
throw new ResourceException( getStatus( Status.CLIENT_ERROR_BAD_REQUEST, t ), t );
}
else if ( t instanceof IllegalArgumentException )
{
throw new ResourceException( getStatus( Status.CLIENT_ERROR_BAD_REQUEST, t ), t );
Expand Down

0 comments on commit 0e6ef37

Please sign in to comment.