use of org.apache.commons.httpclient.HttpException in project zm-mailbox by Zimbra.
the class ElasticSearchIndex method deleteIndex.
@Override
public void deleteIndex() {
HttpMethod method = new DeleteMethod(ElasticSearchConnector.actualUrl(indexUrl));
try {
ElasticSearchConnector connector = new ElasticSearchConnector();
int statusCode = connector.executeMethod(method);
if (statusCode == HttpStatus.SC_OK) {
boolean ok = connector.getBooleanAtJsonPath(new String[] { "ok" }, false);
boolean acknowledged = connector.getBooleanAtJsonPath(new String[] { "acknowledged" }, false);
if (!ok || !acknowledged) {
ZimbraLog.index.debug("Delete index status ok=%b acknowledged=%b", ok, acknowledged);
}
} else {
String error = connector.getStringAtJsonPath(new String[] { "error" });
if (error != null && error.startsWith("IndexMissingException")) {
ZimbraLog.index.debug("Unable to delete index for key=%s. Index is missing", key);
} else {
ZimbraLog.index.error("Problem deleting index for key=%s error=%s", key, error);
}
}
} catch (HttpException e) {
ZimbraLog.index.error("Problem Deleting index with key=" + key, e);
} catch (IOException e) {
ZimbraLog.index.error("Problem Deleting index with key=" + key, e);
}
haveMappingInfo = false;
}
use of org.apache.commons.httpclient.HttpException in project cloudstack by apache.
the class ClusterServiceServletImpl method executePostMethod.
private String executePostMethod(final HttpClient client, final PostMethod method) {
int response = 0;
String result = null;
try {
final Profiler profiler = new Profiler();
profiler.start();
response = client.executeMethod(method);
if (response == HttpStatus.SC_OK) {
result = method.getResponseBodyAsString();
profiler.stop();
if (s_logger.isDebugEnabled()) {
s_logger.debug("POST " + _serviceUrl + " response :" + result + ", responding time: " + profiler.getDurationInMillis() + " ms");
}
} else {
profiler.stop();
s_logger.error("Invalid response code : " + response + ", from : " + _serviceUrl + ", method : " + method.getParameter("method") + " responding time: " + profiler.getDurationInMillis());
}
} catch (final HttpException e) {
s_logger.error("HttpException from : " + _serviceUrl + ", method : " + method.getParameter("method"));
} catch (final IOException e) {
s_logger.error("IOException from : " + _serviceUrl + ", method : " + method.getParameter("method"));
} catch (final Throwable e) {
s_logger.error("Exception from : " + _serviceUrl + ", method : " + method.getParameter("method") + ", exception :", e);
} finally {
method.releaseConnection();
}
return result;
}
use of org.apache.commons.httpclient.HttpException in project cloudstack by apache.
the class BigSwitchApiTest method testExecuteDeleteObjectException.
@Test(expected = BigSwitchBcfApiException.class)
public void testExecuteDeleteObjectException() throws BigSwitchBcfApiException, IOException {
_method = mock(DeleteMethod.class);
when(_method.getStatusCode()).thenReturn(HttpStatus.SC_OK);
when(_client.executeMethod((HttpMethod) any())).thenThrow(new HttpException());
try {
_api.executeDeleteObject("/");
} finally {
verify(_method, times(1)).releaseConnection();
}
}
use of org.apache.commons.httpclient.HttpException in project cloudstack by apache.
the class BigSwitchApiTest method testExecuteCreateObjectException.
@Test(expected = BigSwitchBcfApiException.class)
public void testExecuteCreateObjectException() throws BigSwitchBcfApiException, IOException {
NetworkData network = new NetworkData();
when(_client.executeMethod((HttpMethod) any())).thenThrow(new HttpException());
_method = mock(PostMethod.class);
when(_method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR);
Header header = mock(Header.class);
when(header.getValue()).thenReturn("text/html");
when(_method.getResponseHeader("Content-type")).thenReturn(header);
when(_method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later.");
try {
_api.executeCreateObject(network, "/", Collections.<String, String>emptyMap());
} finally {
verify(_method, times(1)).releaseConnection();
}
}
use of org.apache.commons.httpclient.HttpException in project cloudstack by apache.
the class UriUtils method checkUrlExistence.
// use http HEAD method to validate url
public static void checkUrlExistence(String url) {
if (url.toLowerCase().startsWith("http") || url.toLowerCase().startsWith("https")) {
HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
HeadMethod httphead = new HeadMethod(url);
try {
if (httpClient.executeMethod(httphead) != HttpStatus.SC_OK) {
throw new IllegalArgumentException("Invalid URL: " + url);
}
} catch (HttpException hte) {
throw new IllegalArgumentException("Cannot reach URL: " + url);
} catch (IOException ioe) {
throw new IllegalArgumentException("Cannot reach URL: " + url);
}
}
}
Aggregations