use of org.apache.http.NoHttpResponseException in project kylo by Teradata.
the class NifiRestTest2 method testEvent.
// @Test
public void testEvent() {
try {
ProcessGroupDTO dto = restClient.getProcessGroupByName("root", "jhim");
// ProcessGroupEntity entity= restClient.getProcessGroup("3813381f-2205-414c-bfcf-5900f45fcf601234",true,true);
int i = 0;
} catch (Exception e) {
if (e instanceof NotFoundException) {
int i = 0;
} else if (e instanceof ProcessingException) {
if (e.getCause() instanceof NoHttpResponseException) {
// connection error
} else if (e.getCause() instanceof HttpHostConnectException) {
// connection error
}
}
}
}
use of org.apache.http.NoHttpResponseException in project bw-calendar-engine by Bedework.
the class IscheduleClient method send.
/**
* @param iout
* @param hi
* @param resp Response
* @throws CalFacadeException
*/
public void send(final IscheduleOut iout, final HostInfo hi, final Response resp) throws CalFacadeException {
try {
/* We may have to rediscover and retry. */
for (int failures = 0; failures < 10; failures++) {
// PrivateKey key = pkeys.getKey(url, "isched");
// if (key != null) {
// iout.sign(hi, key);
// }
resp.setHostInfo(hi);
final URI uri = new URI(hi.getIScheduleUrl());
final HttpRequestBase req = findMethod(iout.getMethod(), uri);
if (req == null) {
throw new CalFacadeException("No method " + iout.getMethod());
}
if (!Util.isEmpty(iout.getHeaders())) {
for (final Header hdr : iout.getHeaders()) {
req.addHeader(hdr);
}
}
/* Send the ischedule request. If we get a redirect from the other end
* we need to do the discovery thing again.
*/
setContent(req, iout.getContentBytes(), iout.getContentType());
try (CloseableHttpResponse hresp = cio.execute(req)) {
final int rcode = getStatus(hresp);
if (rcode != HttpServletResponse.SC_OK) {
error("Got response " + resp.getResponseCode() + ", host " + hi.getHostname() + " and url " + hi.getIScheduleUrl());
// hi.setIScheduleUrl(null);
discover(hi);
continue;
}
resp.setHttpResponse(hresp);
parseResponse(hi, resp);
return;
}
}
} catch (final NoHttpResponseException nhre) {
resp.setNoResponse(true);
} catch (final Throwable t) {
resp.setException(t);
throw new CalFacadeException(t);
}
}
use of org.apache.http.NoHttpResponseException in project galley by Commonjava.
the class AbstractHttpJob method executeHttp.
protected boolean executeHttp() throws TransferException {
try {
client = http.createClient(location);
response = client.execute(request, http.createContext(location));
final StatusLine line = response.getStatusLine();
final int sc = line.getStatusCode();
logger.trace("{} {} : {}", request.getMethod(), line, url);
if (sc > 399 && sc != 404 && sc != 408 && sc != 502 && sc != 503 && sc != 504) {
throw new TransferLocationException(location, "Server misconfigured or not responding normally: '%s'", line);
} else if (!successStatuses.contains(sc)) {
logger.trace("Detected failure respon se: " + sc);
success = TransferResponseUtils.handleUnsuccessfulResponse(request, response, location, url);
logger.trace("Returning non-error failure response for code: " + sc);
return false;
}
} catch (final NoHttpResponseException | ConnectTimeoutException | SocketTimeoutException e) {
throw new TransferTimeoutException(location, url, "Repository remote request failed for: {}. Reason: {}", e, url, e.getMessage());
} catch (final IOException e) {
throw new TransferLocationException(location, "Repository remote request failed for: {}. Reason: {}", e, url, e.getMessage());
} catch (TransferLocationException e) {
throw e;
} catch (final GalleyException e) {
throw new TransferException("Repository remote request failed for: {}. Reason: {}", e, url, e.getMessage());
} finally {
/*
* we need to integrate the writeMetadata() method into the executeHttp() call in a finally block,
* and with a condition that it only runs on HEAD or GET. This would allow us to capture metadata on failed requests too,
* which is critical for responding consistently to the user after a failed request is cached in the NFC.
*/
String method = request.getMethod();
if ("GET".equalsIgnoreCase(method) || "HEAD".equalsIgnoreCase(method)) {
Transfer target = getTransfer();
ObjectMapper mapper = getMetadataObjectMapper();
if (target != null && mapper != null) {
writeMetadata(target, mapper);
}
}
}
return true;
}
use of org.apache.http.NoHttpResponseException in project NetDiscovery by fengzhizi715.
the class HttpManager method getResponse.
public CloseableHttpResponse getResponse(HttpRequestBase request, Proxy proxy) {
HttpClientContext httpClientContext = HttpClientContext.create();
CloseableHttpResponse response = null;
try {
if (proxy == null) {
response = createHttpClient().execute(request, httpClientContext);
} else {
response = createHttpClient(20000, proxy.toHttpHost(), null).execute(request, httpClientContext);
}
} catch (NoHttpResponseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return response;
}
use of org.apache.http.NoHttpResponseException in project neo-java by coranos.
the class TestRpcServerUtil method getCityOfZionResponse.
/**
* @param input
* the input to use.
* @param method
* the method to call.
* @return the reseponse.
*/
public static String getCityOfZionResponse(final String input, final String method) {
try {
final String url = CityOfZionUtil.MAINNET_API + method + input;
LOG.debug("url:{}", url);
final HttpGet httpRequest = new HttpGet(url);
final RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(TIMEOUT_MILLIS).setConnectTimeout(TIMEOUT_MILLIS).setConnectionRequestTimeout(TIMEOUT_MILLIS).build();
httpRequest.setConfig(requestConfig);
final CloseableHttpClient client = HttpClients.createDefault();
final String responseStr;
try {
final CloseableHttpResponse response = client.execute(httpRequest);
logDebugStatus(response);
final HttpEntity entity = response.getEntity();
responseStr = EntityUtils.toString(entity);
} catch (final ConnectTimeoutException | SocketTimeoutException | NoHttpResponseException | SocketException e) {
throw new RuntimeException(CONNECTION_EXCEPTION, e);
}
final JSONObject responseJson = new JSONObject(responseStr);
final String actualStr = responseJson.toString(2);
return actualStr;
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
Aggregations