This repository has been archived by the owner on Aug 11, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #705 from sonatype/proxy-eof
Proxy EOF detection.
- Loading branch information
Showing
9 changed files
with
283 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
nexus-core/src/main/java/org/sonatype/nexus/proxy/RemoteStorageEOFException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* 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; | ||
|
||
import org.sonatype.nexus.proxy.repository.ProxyRepository; | ||
import com.google.common.base.Preconditions; | ||
|
||
/** | ||
* Remote storage exception for cases when outbound request is unsuccessful, due to remote peer hang up on us unexpectedly. | ||
* Main use of this exception is to "translate" various EOF notification for various Remote Repository Storage implementations | ||
* into single exception handled by Nexus Core. | ||
* | ||
* @author cstamas | ||
* @since 2.4 | ||
*/ | ||
public class RemoteStorageEOFException | ||
extends RemoteStorageException | ||
{ | ||
private final ProxyRepository repository; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param repository | ||
* @param message | ||
*/ | ||
public RemoteStorageEOFException( final ProxyRepository repository, final String message ) | ||
{ | ||
this( repository, message, null ); | ||
} | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param repository | ||
* @param message | ||
* @param cause | ||
*/ | ||
public RemoteStorageEOFException( final ProxyRepository repository, final String message, final Throwable cause ) | ||
{ | ||
super( message, cause ); | ||
this.repository = Preconditions.checkNotNull( repository ); | ||
} | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param repository | ||
* @param cause | ||
*/ | ||
public RemoteStorageEOFException( final ProxyRepository repository, final Throwable cause ) | ||
{ | ||
this( repository, cause.getMessage(), cause ); | ||
} | ||
|
||
/** | ||
* Returns the involved proxy repository. Never returns {@code null}. | ||
* | ||
* @return the involved proxy repository. | ||
*/ | ||
public ProxyRepository getRepository() | ||
{ | ||
return repository; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...core/src/main/java/org/sonatype/nexus/proxy/storage/remote/httpclient/Hc4InputStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* 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.storage.remote.httpclient; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import org.apache.http.ConnectionClosedException; | ||
import org.sonatype.nexus.proxy.RemoteStorageEOFException; | ||
import org.sonatype.nexus.proxy.repository.ProxyRepository; | ||
import org.sonatype.nexus.util.WrappingInputStream; | ||
|
||
/** | ||
* Simple wrapper input stream implementation that translates some HC4 specific exceptions to Nexus Core specific | ||
* exceptions, making Core able to properly respond to them. | ||
* | ||
* @since 2.4 | ||
*/ | ||
class Hc4InputStream | ||
extends WrappingInputStream | ||
{ | ||
private final ProxyRepository proxyRepository; | ||
|
||
public Hc4InputStream( final ProxyRepository proxyRepository, final InputStream stream ) | ||
{ | ||
super( stream ); | ||
this.proxyRepository = proxyRepository; | ||
} | ||
|
||
@Override | ||
public int read() | ||
throws IOException | ||
{ | ||
try | ||
{ | ||
return super.read(); | ||
} | ||
catch ( ConnectionClosedException e ) | ||
{ | ||
throw new RemoteStorageEOFException( proxyRepository, e ); | ||
} | ||
} | ||
|
||
@Override | ||
public int read( byte[] b ) | ||
throws IOException | ||
{ | ||
try | ||
{ | ||
return super.read( b ); | ||
} | ||
catch ( ConnectionClosedException e ) | ||
{ | ||
throw new RemoteStorageEOFException( proxyRepository, e ); | ||
} | ||
} | ||
|
||
@Override | ||
public int read( byte b[], int off, int len ) | ||
throws IOException | ||
{ | ||
try | ||
{ | ||
return super.read( b, off, len ); | ||
} | ||
catch ( ConnectionClosedException e ) | ||
{ | ||
throw new RemoteStorageEOFException( proxyRepository, e ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.