Upgrade HttpClient libraries from 3.1 to 4.3.2

This commit is contained in:
Jim Blake 2014-05-07 17:07:39 -04:00
parent 10d692d411
commit d3fe9d082e
12 changed files with 154 additions and 135 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -2,9 +2,10 @@
package edu.cornell.mannlib.vitro.webapp.controller.edit; package edu.cornell.mannlib.vitro.webapp.controller.edit;
import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -42,7 +43,7 @@ public class PrimitiveDelete extends VitroAjaxController {
if( !hasPermission ){ if( !hasPermission ){
//if not okay, send error message //if not okay, send error message
doError(response,"Insufficent permissions.", HttpStatus.SC_UNAUTHORIZED); doError(response,"Insufficent permissions.", SC_UNAUTHORIZED);
return; return;
} }

View file

@ -2,6 +2,9 @@
package edu.cornell.mannlib.vitro.webapp.controller.edit; package edu.cornell.mannlib.vitro.webapp.controller.edit;
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
import java.io.StringWriter; import java.io.StringWriter;
@ -11,7 +14,6 @@ import java.util.Set;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -66,7 +68,7 @@ public class PrimitiveRdfEdit extends VitroAjaxController {
try { try {
additions = parseRdfParam(vreq.getParameterValues("additions"),format); additions = parseRdfParam(vreq.getParameterValues("additions"),format);
} catch (Exception e) { } catch (Exception e) {
doError(response,"Error reading RDF, set log level to debug for this class to get error messages in the server logs.",HttpStatus.SC_BAD_REQUEST); doError(response,"Error reading RDF, set log level to debug for this class to get error messages in the server logs.",SC_BAD_REQUEST);
return; return;
} }
@ -74,7 +76,7 @@ public class PrimitiveRdfEdit extends VitroAjaxController {
try { try {
retractions = parseRdfParam(vreq.getParameterValues("retractions"),format); retractions = parseRdfParam(vreq.getParameterValues("retractions"),format);
} catch (Exception e) { } catch (Exception e) {
doError(response,"Error reading RDF, set log level to debug for this class to get error messages in the server logs.",HttpStatus.SC_BAD_REQUEST); doError(response,"Error reading RDF, set log level to debug for this class to get error messages in the server logs.",SC_BAD_REQUEST);
return; return;
} }
@ -92,7 +94,7 @@ public class PrimitiveRdfEdit extends VitroAjaxController {
toBeRetracted.add(depResRetractions); toBeRetracted.add(depResRetractions);
processChanges(editorUri, getWriteModel(vreq), toBeAdded, toBeRetracted); processChanges(editorUri, getWriteModel(vreq), toBeAdded, toBeRetracted);
} catch (Exception e) { } catch (Exception e) {
doError(response,e.getMessage(),HttpStatus.SC_INTERNAL_SERVER_ERROR); doError(response,e.getMessage(),SC_INTERNAL_SERVER_ERROR);
} }
} }

View file

@ -2,9 +2,13 @@
package edu.cornell.mannlib.vitro.webapp.controller.edit; package edu.cornell.mannlib.vitro.webapp.controller.edit;
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
import static javax.servlet.http.HttpServletResponse.SC_OK;
import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -57,7 +61,7 @@ public class ReorderController extends VitroAjaxController {
if (rankPredicate == null) { if (rankPredicate == null) {
errorMsg = "No rank parameter specified"; errorMsg = "No rank parameter specified";
log.error(errorMsg); log.error(errorMsg);
doError(response, errorMsg, HttpServletResponse.SC_BAD_REQUEST ); doError(response, errorMsg, SC_BAD_REQUEST );
return; return;
} }
@ -65,7 +69,7 @@ public class ReorderController extends VitroAjaxController {
if (individualUris == null || individualUris.length == 0) { if (individualUris == null || individualUris.length == 0) {
errorMsg = "No individuals specified"; errorMsg = "No individuals specified";
log.error(errorMsg); log.error(errorMsg);
doError(response, errorMsg, HttpServletResponse.SC_BAD_REQUEST); doError(response, errorMsg, SC_BAD_REQUEST);
return; return;
} }
@ -73,7 +77,7 @@ public class ReorderController extends VitroAjaxController {
if( vreq.getWebappDaoFactory() == null) { if( vreq.getWebappDaoFactory() == null) {
errorMsg = "No WebappDaoFactory available"; errorMsg = "No WebappDaoFactory available";
log.error(errorMsg); log.error(errorMsg);
doError(response, errorMsg, HttpServletResponse.SC_INTERNAL_SERVER_ERROR); doError(response, errorMsg, SC_INTERNAL_SERVER_ERROR);
return; return;
} }
@ -81,7 +85,7 @@ public class ReorderController extends VitroAjaxController {
if( dpsDao == null) { if( dpsDao == null) {
errorMsg = "No DataPropertyStatementDao available"; errorMsg = "No DataPropertyStatementDao available";
log.error(errorMsg); log.error(errorMsg);
doError(response, errorMsg, HttpServletResponse.SC_INTERNAL_SERVER_ERROR); doError(response, errorMsg, SC_INTERNAL_SERVER_ERROR);
return; return;
} }
@ -91,7 +95,7 @@ public class ReorderController extends VitroAjaxController {
boolean hasPermission = true; boolean hasPermission = true;
if( !hasPermission ){ if( !hasPermission ){
//if not okay, send error message //if not okay, send error message
doError(response,"Insufficent permissions", HttpStatus.SC_UNAUTHORIZED); doError(response,"Insufficent permissions", SC_UNAUTHORIZED);
return; return;
} }
@ -100,7 +104,7 @@ public class ReorderController extends VitroAjaxController {
reorderIndividuals(individualUris, vreq, rankPredicate); reorderIndividuals(individualUris, vreq, rankPredicate);
response.setStatus(HttpServletResponse.SC_OK); response.setStatus(SC_OK);
} }

View file

@ -7,20 +7,25 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.StringWriter; import java.io.StringWriter;
import java.net.URISyntaxException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicNameValuePair;
import org.openrdf.model.Resource; import org.openrdf.model.Resource;
import org.openrdf.repository.RepositoryConnection; import org.openrdf.repository.RepositoryConnection;
import org.openrdf.repository.RepositoryException; import org.openrdf.repository.RepositoryException;
@ -41,7 +46,6 @@ import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.RDFNode; import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Statement; import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator; import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP;
import edu.cornell.mannlib.vitro.webapp.dao.jena.SparqlGraph; import edu.cornell.mannlib.vitro.webapp.dao.jena.SparqlGraph;
import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeListener; import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeListener;
@ -65,7 +69,7 @@ public class RDFServiceSparql extends RDFServiceImpl implements RDFService {
protected String updateEndpointURI; protected String updateEndpointURI;
private HTTPRepository readRepository; private HTTPRepository readRepository;
private HTTPRepository updateRepository; private HTTPRepository updateRepository;
private HttpClient httpClient; private CloseableHttpClient httpClient;
private boolean useSesameContextQuery = true; private boolean useSesameContextQuery = true;
// the number of triples to be // the number of triples to be
private static final int CHUNK_SIZE = 1000; // added/removed in a single private static final int CHUNK_SIZE = 1000; // added/removed in a single
@ -88,9 +92,9 @@ public class RDFServiceSparql extends RDFServiceImpl implements RDFService {
this.readRepository = new HTTPRepository(readEndpointURI); this.readRepository = new HTTPRepository(readEndpointURI);
this.updateRepository = new HTTPRepository(updateEndpointURI); this.updateRepository = new HTTPRepository(updateEndpointURI);
MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager(); PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
mgr.getParams().setDefaultMaxConnectionsPerHost(50); cm.setDefaultMaxPerRoute(50);
this.httpClient = new HttpClient(mgr); this.httpClient = HttpClients.custom().setConnectionManager(cm).build();
testConnection(); testConnection();
} }
@ -285,50 +289,48 @@ public class RDFServiceSparql extends RDFServiceImpl implements RDFService {
//QueryEngineHTTP qh = new QueryEngineHTTP(readEndpointURI, queryStr); //QueryEngineHTTP qh = new QueryEngineHTTP(readEndpointURI, queryStr);
GetMethod meth = new GetMethod(readEndpointURI);
try { try {
meth.addRequestHeader("Accept", "application/sparql-results+xml"); HttpGet meth = new HttpGet(new URIBuilder(readEndpointURI).addParameter("query", queryStr).build());
NameValuePair param = new NameValuePair(); meth.addHeader("Accept", "application/sparql-results+xml");
param.setName("query"); CloseableHttpResponse response = httpClient.execute(meth);
param.setValue(queryStr); try {
NameValuePair[] params = new NameValuePair[1]; int statusCode = response.getStatusLine().getStatusCode();
params[0] = param; if (statusCode > 399) {
meth.setQueryString(params); log.error("response " + statusCode + " to query. \n");
int response = httpClient.executeMethod(meth); log.debug("update string: \n" + queryStr);
if (response > 399) { throw new RDFServiceException("Unable to perform SPARQL UPDATE");
log.error("response " + response + " to query. \n"); }
log.debug("update string: \n" + queryStr);
throw new RDFServiceException("Unable to perform SPARQL UPDATE"); InputStream in = response.getEntity().getContent();
ResultSet resultSet = ResultSetFactory.fromXML(in);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
switch (resultFormat) {
case CSV:
ResultSetFormatter.outputAsCSV(outputStream,resultSet);
break;
case TEXT:
ResultSetFormatter.out(outputStream,resultSet);
break;
case JSON:
ResultSetFormatter.outputAsJSON(outputStream, resultSet);
break;
case XML:
ResultSetFormatter.outputAsXML(outputStream, resultSet);
break;
default:
throw new RDFServiceException("unrecognized result format");
}
InputStream result = new ByteArrayInputStream(outputStream.toByteArray());
return result;
} finally {
response.close();
} }
InputStream in = meth.getResponseBodyAsStream();
ResultSet resultSet = ResultSetFactory.fromXML(in);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
switch (resultFormat) {
case CSV:
ResultSetFormatter.outputAsCSV(outputStream,resultSet);
break;
case TEXT:
ResultSetFormatter.out(outputStream,resultSet);
break;
case JSON:
ResultSetFormatter.outputAsJSON(outputStream, resultSet);
break;
case XML:
ResultSetFormatter.outputAsXML(outputStream, resultSet);
break;
default:
throw new RDFServiceException("unrecognized result format");
}
InputStream result = new ByteArrayInputStream(outputStream.toByteArray());
return result;
} catch (IOException ioe) { } catch (IOException ioe) {
throw new RuntimeException(ioe); throw new RuntimeException(ioe);
} finally { } catch (URISyntaxException e) {
//qh.close(); throw new RuntimeException(e);
meth.releaseConnection(); }
}
} }
/** /**
@ -486,20 +488,19 @@ public class RDFServiceSparql extends RDFServiceImpl implements RDFService {
protected void executeUpdate(String updateString) throws RDFServiceException { protected void executeUpdate(String updateString) throws RDFServiceException {
try { try {
PostMethod meth = new PostMethod(updateEndpointURI); HttpPost meth = new HttpPost(updateEndpointURI);
meth.addHeader("Content-Type", "application/x-www-form-urlencoded");
meth.setEntity(new UrlEncodedFormEntity(Arrays.asList(new BasicNameValuePair("update", updateString))));
CloseableHttpResponse response = httpClient.execute(meth);
try { try {
meth.addRequestHeader("Content-Type", "application/x-www-form-urlencoded"); int statusCode = response.getStatusLine().getStatusCode();
NameValuePair[] body = new NameValuePair[1]; if (statusCode > 399) {
body[0] = new NameValuePair("update", updateString); log.error("response " + statusCode + " to update. \n");
meth.setRequestBody(body);
int response = httpClient.executeMethod(meth);
if (response > 399) {
log.error("response " + response + " to update. \n");
//log.debug("update string: \n" + updateString); //log.debug("update string: \n" + updateString);
throw new RDFServiceException("Unable to perform SPARQL UPDATE"); throw new RDFServiceException("Unable to perform SPARQL UPDATE");
} }
} finally { } finally {
meth.releaseConnection(); response.close();
} }
} catch (Exception e) { } catch (Exception e) {
throw new RDFServiceException("Unable to perform change set update", e); throw new RDFServiceException("Unable to perform change set update", e);

View file

@ -3,7 +3,6 @@
package edu.cornell.mannlib.vitro.webapp.servlet.setup; package edu.cornell.mannlib.vitro.webapp.servlet.setup;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.net.ConnectException; import java.net.ConnectException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
@ -13,12 +12,14 @@ import java.net.UnknownHostException;
import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener; import javax.servlet.ServletContextListener;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpException;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
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;
@ -142,7 +143,10 @@ public class SolrSmokeTest implements ServletContextListener {
} }
private void reportPingProblem(SolrProblemException e) { private void reportPingProblem(SolrProblemException e) {
ss.warning(listener, "The Solr search engine did not respond to a 'ping' request", e); ss.warning(
listener,
"The Solr search engine did not respond to a 'ping' request",
e);
} }
private void warnSocketTimeout() { private void warnSocketTimeout() {
@ -203,7 +207,8 @@ public class SolrSmokeTest implements ServletContextListener {
private static final long SLEEP_INTERVAL = 20000; // 20 seconds private static final long SLEEP_INTERVAL = 20000; // 20 seconds
private final URL solrUrl; private final URL solrUrl;
private final HttpClient httpClient = new HttpClient(); private final CloseableHttpClient httpClient = HttpClients
.createDefault();
private int statusCode; private int statusCode;
@ -230,23 +235,22 @@ public class SolrSmokeTest implements ServletContextListener {
} }
private void tryToConnect() throws SolrProblemException { private void tryToConnect() throws SolrProblemException {
GetMethod method = new GetMethod(solrUrl.toExternalForm());
try { try {
HttpGet method = new HttpGet(solrUrl.toExternalForm());
SolrSmokeTest.log.debug("Trying to connect to Solr"); SolrSmokeTest.log.debug("Trying to connect to Solr");
statusCode = httpClient.executeMethod(method); CloseableHttpResponse response = httpClient.execute(method);
SolrSmokeTest.log.debug("HTTP status was " + statusCode); try {
statusCode = response.getStatusLine().getStatusCode();
// clear the buffer. SolrSmokeTest.log.debug("HTTP status was " + statusCode);
InputStream stream = method.getResponseBodyAsStream(); } finally {
stream.close(); response.close();
}
} 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.
statusCode = SolrSmokeTest.SOCKET_TIMEOUT_STATUS; statusCode = SolrSmokeTest.SOCKET_TIMEOUT_STATUS;
} catch (Exception e) { } catch (Exception e) {
throw new SolrProblemException(e); throw new SolrProblemException(e);
} finally {
method.releaseConnection();
} }
} }
@ -275,30 +279,30 @@ public class SolrSmokeTest implements ServletContextListener {
*/ */
private static class SolrPinger { private static class SolrPinger {
private final URL solrUrl; private final URL solrUrl;
private final HttpClient httpClient = new HttpClient(); private final CloseableHttpClient httpClient = HttpClients
.createDefault();
public SolrPinger(URL solrUrl) { public SolrPinger(URL solrUrl) {
this.solrUrl = solrUrl; this.solrUrl = solrUrl;
} }
public void ping() throws SolrProblemException { public void ping() throws SolrProblemException {
GetMethod method = new GetMethod(solrUrl.toExternalForm() + "/admin/ping");
try { try {
HttpGet method = new HttpGet(solrUrl.toExternalForm()
+ "/admin/ping");
SolrSmokeTest.log.debug("Trying to ping Solr"); SolrSmokeTest.log.debug("Trying to ping Solr");
int statusCode = httpClient.executeMethod(method); CloseableHttpResponse response = httpClient.execute(method);
SolrSmokeTest.log.debug("Finished pinging Solr"); SolrSmokeTest.log.debug("Finished pinging Solr");
try {
// clear the buffer. int statusCode = response.getStatusLine().getStatusCode();
InputStream stream = method.getResponseBodyAsStream(); if (statusCode != HttpStatus.SC_OK) {
stream.close(); throw new SolrProblemException(statusCode);
}
if (statusCode != HttpStatus.SC_OK) { } finally {
throw new SolrProblemException(statusCode); response.close();
} }
} catch (IOException e) { } catch (IOException e) {
throw new SolrProblemException(e); throw new SolrProblemException(e);
} finally {
method.releaseConnection();
} }
} }
} }

View file

@ -19,12 +19,14 @@ import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener; import javax.servlet.ServletContextListener;
import org.apache.commons.dbcp.BasicDataSource; import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
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;
@ -70,7 +72,8 @@ public class OpenSocialSmokeTests implements ServletContextListener {
configProps = ConfigurationProperties.getBean(ctx); configProps = ConfigurationProperties.getBean(ctx);
/* /*
* If OpenSocial is not configured in runtime.properties, skip the tests. * If OpenSocial is not configured in runtime.properties, skip the
* tests.
*/ */
if (!configurationPresent()) { if (!configurationPresent()) {
ss.info(this, "The OpenSocial connection is not configured."); ss.info(this, "The OpenSocial connection is not configured.");
@ -210,14 +213,15 @@ public class OpenSocialSmokeTests implements ServletContextListener {
} }
/** /**
* Get the Token Service info from runtime.properties. It must be in the form * Get the Token Service info from runtime.properties. It must be in the
* of host:port, and may not refer to localhost. * form of host:port, and may not refer to localhost.
*/ */
private void checkTokenServiceInfo() { private void checkTokenServiceInfo() {
String tsInfo = configProps.getProperty(PROPERTY_SHINDIG_TOKEN_SERVICE); String tsInfo = configProps.getProperty(PROPERTY_SHINDIG_TOKEN_SERVICE);
if (StringUtils.isEmpty(tsInfo)) { if (StringUtils.isEmpty(tsInfo)) {
warnings.add(new Warning("There is no value for '" warnings.add(new Warning("There is no value for '"
+ PROPERTY_SHINDIG_TOKEN_SERVICE + "' in runtime.properties")); + PROPERTY_SHINDIG_TOKEN_SERVICE
+ "' in runtime.properties"));
return; return;
} }
@ -346,7 +350,8 @@ public class OpenSocialSmokeTests implements ServletContextListener {
private final String shindigBaseUrl; private final String shindigBaseUrl;
private final String shindigTestUrl; private final String shindigTestUrl;
private final HttpClient httpClient = new HttpClient(); private final CloseableHttpClient httpClient = HttpClients
.createDefault();
private int statusCode = Integer.MIN_VALUE; private int statusCode = Integer.MIN_VALUE;
@ -375,15 +380,16 @@ public class OpenSocialSmokeTests implements ServletContextListener {
} }
private void testConnection() throws ShindigTesterException { private void testConnection() throws ShindigTesterException {
GetMethod method = new GetMethod(shindigTestUrl); HttpGet method = new HttpGet(shindigTestUrl);
try { try {
log.debug("Trying to connect to Shindig"); log.debug("Trying to connect to Shindig");
statusCode = httpClient.executeMethod(method); CloseableHttpResponse response = httpClient.execute(method);
log.debug("HTTP status was " + statusCode); try {
statusCode = response.getStatusLine().getStatusCode();
// clear the buffer. log.debug("HTTP status was " + statusCode);
InputStream stream = method.getResponseBodyAsStream(); } finally {
stream.close(); response.close();
}
} 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.
@ -391,8 +397,6 @@ public class OpenSocialSmokeTests implements ServletContextListener {
} catch (Exception e) { } catch (Exception e) {
throw new ShindigTesterException(e, shindigBaseUrl, throw new ShindigTesterException(e, shindigBaseUrl,
shindigTestUrl); shindigTestUrl);
} finally {
method.releaseConnection();
} }
} }
@ -513,25 +517,28 @@ public class OpenSocialSmokeTests implements ServletContextListener {
try { try {
log.debug("Connecting to the token service"); log.debug("Connecting to the token service");
Socket s = new Socket(host, port); Socket s = new Socket(host, port);
try {
s.getOutputStream().write("c=default\n".getBytes());
s.getOutputStream().write("c=default\n".getBytes()); int byteCount = 0;
int totalBytecount = 0;
byte[] buffer = new byte[8192];
int byteCount = 0; // The following will block until the page is transmitted.
int totalBytecount = 0; InputStream inputStream = s.getInputStream();
byte[] buffer = new byte[8192]; while ((byteCount = inputStream.read(buffer)) > 0) {
totalBytecount += byteCount;
}
// The following will block until the page is transmitted. if (totalBytecount == 0) {
InputStream inputStream = s.getInputStream(); log.debug("Received an empty response.");
while ((byteCount = inputStream.read(buffer)) > 0) { problem = "The Shindig security token service responded to a test, but the response was empty.";
totalBytecount += byteCount; } else {
} log.debug("Recieved the token.");
problem = null;
if (totalBytecount == 0) { }
log.debug("Received an empty response."); } finally {
problem = "The Shindig security token service responded to a test, but the response was empty."; s.close();
} else {
log.debug("Recieved the token.");
problem = null;
} }
} catch (Exception e) { } catch (Exception e) {
log.debug("Problem with the token service", e); log.debug("Problem with the token service", e);