Skip to content
Browse files

Buffer respond entity in case of an URE / Use a ThreadSafeClientConnM…

…anager

This may  be temporary till we figure out why connection is not closed in case of an exception

Signed-off-by: Alin Dreghiciu <adreghiciu@gmail.com>
  • Loading branch information...
1 parent fba0a29 commit 5197f3a4581c386450f83eb445838271da544565 @adreghiciu adreghiciu committed with cstamas Nov 14, 2012
View
12 .../main/java/org/sonatype/nexus/client/internal/rest/jersey/NexusUniformRequestBuilder.java
@@ -579,9 +579,14 @@ T perform()
}
catch ( final UniformInterfaceException e )
{
- final ClientResponse response = e.getResponse();
+ ClientResponse response = null;
try
{
+ response = e.getResponse();
+
+ // buffer entity so callers may consume it if needed
+ response.bufferEntity();
+
if ( response.getStatus() == ClientResponse.Status.BAD_REQUEST.getStatusCode() )
{
if ( response.hasEntity() )
@@ -607,7 +612,10 @@ else if ( response.getStatus() == ClientResponse.Status.NOT_FOUND.getStatusCode(
}
finally
{
- response.close();
+ if ( response != null )
+ {
+ response.close();
+ }
}
}
}
View
4 ...nt-core/src/main/java/org/sonatype/nexus/client/rest/jersey/JerseyNexusClientFactory.java
@@ -24,6 +24,7 @@
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.conn.params.ConnRoutePNames;
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.params.CoreProtocolPNames;
import org.sonatype.nexus.client.core.Condition;
import org.sonatype.nexus.client.core.spi.SubsystemFactory;
@@ -95,6 +96,9 @@ protected ApacheHttpClient4 doCreateHttpClientFor( final ConnectionInfo connecti
config.getSingletons().add( new XStreamXmlProvider( xstream, APPLICATION_XML_UTF8_TYPE ) );
// set _real_ URL for baseUrl, and not a redirection (typically http instead of https)
config.getProperties().put( ApacheHttpClient4Config.PROPERTY_FOLLOW_REDIRECTS, Boolean.FALSE );
+ config.getProperties().put(
+ ApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER, new ThreadSafeClientConnManager( )
+ );
applyAuthenticationIfAny( connectionInfo, config );
applyProxyIfAny( connectionInfo, config );

0 comments on commit 5197f3a

Please sign in to comment.
Something went wrong with that request. Please try again.