Search in sources :

Example 6 with NoHttpResponseException

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
            }
        }
    }
}
Also used : NoHttpResponseException(org.apache.http.NoHttpResponseException) HttpHostConnectException(org.apache.http.conn.HttpHostConnectException) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) NotFoundException(javax.ws.rs.NotFoundException) ProcessingException(javax.ws.rs.ProcessingException) NoHttpResponseException(org.apache.http.NoHttpResponseException) NotFoundException(javax.ws.rs.NotFoundException) HttpHostConnectException(org.apache.http.conn.HttpHostConnectException) ProcessingException(javax.ws.rs.ProcessingException)

Example 7 with NoHttpResponseException

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);
    }
}
Also used : NoHttpResponseException(org.apache.http.NoHttpResponseException) HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) Header(org.apache.http.Header) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) URI(java.net.URI) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 8 with NoHttpResponseException

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;
}
Also used : NoHttpResponseException(org.apache.http.NoHttpResponseException) TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException) IOException(java.io.IOException) GalleyException(org.commonjava.maven.galley.GalleyException) StatusLine(org.apache.http.StatusLine) TransferException(org.commonjava.maven.galley.TransferException) SocketTimeoutException(java.net.SocketTimeoutException) Transfer(org.commonjava.maven.galley.model.Transfer) TransferLocationException(org.commonjava.maven.galley.TransferLocationException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException)

Example 9 with NoHttpResponseException

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;
}
Also used : NoHttpResponseException(org.apache.http.NoHttpResponseException) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpClientContext(org.apache.http.client.protocol.HttpClientContext) IOException(java.io.IOException)

Example 10 with NoHttpResponseException

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);
    }
}
Also used : NoHttpResponseException(org.apache.http.NoHttpResponseException) RequestConfig(org.apache.http.client.config.RequestConfig) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) SocketException(java.net.SocketException) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) NoHttpResponseException(org.apache.http.NoHttpResponseException) SocketException(java.net.SocketException) JSONException(org.json.JSONException) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException) SocketTimeoutException(java.net.SocketTimeoutException) SocketTimeoutException(java.net.SocketTimeoutException) JSONObject(org.json.JSONObject) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException)

Aggregations

NoHttpResponseException (org.apache.http.NoHttpResponseException)38 IOException (java.io.IOException)13 SocketException (java.net.SocketException)12 StatusLine (org.apache.http.StatusLine)12 ConnectTimeoutException (org.apache.http.conn.ConnectTimeoutException)11 SocketTimeoutException (java.net.SocketTimeoutException)10 ParserCursor (org.apache.http.message.ParserCursor)9 UnknownHostException (java.net.UnknownHostException)8 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)8 HttpRequest (org.apache.http.HttpRequest)7 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)7 ConnectException (java.net.ConnectException)6 HttpEntityEnclosingRequest (org.apache.http.HttpEntityEnclosingRequest)6 InterruptedIOException (java.io.InterruptedIOException)5 SSLException (javax.net.ssl.SSLException)5 HashMap (java.util.HashMap)4 HttpEntity (org.apache.http.HttpEntity)4 RequestConfig (org.apache.http.client.config.RequestConfig)4 HttpPost (org.apache.http.client.methods.HttpPost)4 SolrException (org.apache.solr.common.SolrException)4