mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 00:15:44 +01:00
return error stream, if input stream could not be returned
This commit is contained in:
@@ -33,11 +33,13 @@ package sonia.scm.net.ahc;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.LinkedHashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.io.ByteSource;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -132,6 +134,14 @@ public class DefaultAdvancedHttpResponse extends AdvancedHttpResponse
|
||||
private static class URLConnectionByteSource extends ByteSource
|
||||
{
|
||||
|
||||
/**
|
||||
* the logger for URLConnectionByteSource
|
||||
*/
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(URLConnectionByteSource.class);
|
||||
|
||||
//~--- constructors -------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs a new {@link URLConnectionByteSource}.
|
||||
*
|
||||
@@ -146,17 +156,35 @@ public class DefaultAdvancedHttpResponse extends AdvancedHttpResponse
|
||||
//~--- methods ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Opens the http connection.
|
||||
* Opens the input stream of http connection, if an error occurs during
|
||||
* opening the method will return the error stream instead.
|
||||
*
|
||||
*
|
||||
* @return http connection
|
||||
* @return input or error stream of http connection
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public InputStream openStream() throws IOException
|
||||
{
|
||||
return connection.getInputStream();
|
||||
InputStream stream;
|
||||
|
||||
try
|
||||
{
|
||||
stream = connection.getInputStream();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug(
|
||||
"could not open input stream, open error stream instead", ex);
|
||||
}
|
||||
|
||||
stream = connection.getErrorStream();
|
||||
}
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
//~--- fields -------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user