Minor HttpClient resource cleanups

This commit is contained in:
Graham Triggs 2016-07-21 21:00:09 +01:00
parent 64eb5929a7
commit 83534d49be
3 changed files with 10 additions and 4 deletions

View file

@ -45,6 +45,7 @@ import com.hp.hpl.jena.util.iterator.SingletonIterator;
import com.hp.hpl.jena.util.iterator.WrappedIterator; import com.hp.hpl.jena.util.iterator.WrappedIterator;
import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString; import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
public class SparqlGraph implements GraphWithPerform { public class SparqlGraph implements GraphWithPerform {
@ -97,7 +98,7 @@ public class SparqlGraph implements GraphWithPerform {
meth.addHeader("Content-Type", "application/x-www-form-urlencoded"); meth.addHeader("Content-Type", "application/x-www-form-urlencoded");
meth.setEntity(new UrlEncodedFormEntity(Arrays.asList( meth.setEntity(new UrlEncodedFormEntity(Arrays.asList(
new BasicNameValuePair("update", updateString)))); new BasicNameValuePair("update", updateString))));
HttpResponse response = httpClient.execute(meth); HttpResponse response = httpClient.execute(meth, new BasicHttpContext());
try { try {
int statusCode = response.getStatusLine().getStatusCode(); int statusCode = response.getStatusLine().getStatusCode();
if (statusCode > 399) { if (statusCode > 399) {

View file

@ -932,7 +932,7 @@ public class RDFServiceSparql extends RDFServiceImpl implements RDFService {
} }
} }
return null; return new BasicHttpContext();
} }
protected UsernamePasswordCredentials getCredentials() { protected UsernamePasswordCredentials getCredentials() {

View file

@ -32,6 +32,7 @@ import org.apache.http.impl.client.DefaultHttpClient;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread; import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread;
import org.apache.http.util.EntityUtils;
/** /**
* Do some quick checks to see whether the OpenSocial stuff is configured and * Do some quick checks to see whether the OpenSocial stuff is configured and
@ -384,8 +385,12 @@ public class OpenSocialSmokeTests implements ServletContextListener {
try { try {
log.debug("Trying to connect to Shindig"); log.debug("Trying to connect to Shindig");
HttpResponse response = httpClient.execute(method); HttpResponse response = httpClient.execute(method);
statusCode = response.getStatusLine().getStatusCode(); try {
log.debug("HTTP status was " + statusCode); statusCode = response.getStatusLine().getStatusCode();
log.debug("HTTP status was " + statusCode);
} finally {
EntityUtils.consume(response.getEntity());
}
} catch (SocketTimeoutException e) { } catch (SocketTimeoutException e) {
// Catch the exception so we can retry this. // Catch the exception so we can retry this.
// Save the status so we know why we failed. // Save the status so we know why we failed.