Example usage for java.net ConnectException ConnectException

List of usage examples for java.net ConnectException ConnectException

Introduction

In this page you can find the example usage for java.net ConnectException ConnectException.

Prototype

public ConnectException() 

Source Link

Document

Construct a new ConnectException with no detailed message.

Usage

From source file:org.apache.hadoop.metrics2.sink.timeline.cache.HandleConnectExceptionTest.java

@Before
public void init() {
    sink = new TestTimelineMetricsSink();
    sink.setHttpClient(client);//from  w w w. ja va  2s.c  om

    try {
        Mockito.when(client.executeMethod(Mockito.<HttpMethod>any())).thenThrow(new ConnectException());
    } catch (IOException e) {
        //no-op
    }
}

From source file:control.services.DownloadPortraitsHttpServiceImpl.java

@Override
public void checkNetworkConnection() throws ConnectException {
    boolean networkAvalaible = false;
    int timeout = 2000;

    try {//  w w w.  j av  a 2s .  c o m
        final URL url = new URL(PROTOCOL_HOST + CLASH_HOST);
        final URLConnection conn = url.openConnection();
        conn.connect();
        networkAvalaible = true;

        /*
        InetAddress[] addresses = InetAddress.getAllByName(CLASH_HOST);
        for (InetAddress address : addresses) {
        if (address.isReachable(timeout)) {
            networkAvalaible = true;
        }
        }
        */
    } catch (UnknownHostException e1) {
        LOG.error(e1);
        networkAvalaible = false;
    } catch (IOException e2) {
        LOG.error(e2);
        networkAvalaible = false;
    }

    if (!networkAvalaible) {
        throw new ConnectException();
    }
}

From source file:bad.robot.http.apache.ApacheExceptionWrappingExecutorTest.java

@Test
public void wrapsConnectException() {
    exception.expect(HttpConnectionRefusedException.class);
    exception.expect(new ThrowableCauseMatcher(HttpHostConnectException.class));
    wrapper.submit(//from   ww  w  .  j ava 2s  .  com
            throwsException(new HttpHostConnectException(new HttpHost("localhost"), new ConnectException())));
}

From source file:com.corebase.android.framework.http.client.MyHttpRequest.java

public byte[] downloadWithCache() throws ConnectException, Exception {
    byte[] data = null;
    boolean retry = true;
    IOException cause = null;// ww w .ja  v  a  2  s.  c  o  m
    HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler();
    while (retry) {
        try {
            //pcgroup?
            if (null != cacheParams && !cacheParams.isRefresh()) {
                data = CacheManager.getCache(url);
                if (null != data) {
                    return data;
                } else {
                    data = executeTask();
                }
            } else {
                data = executeTask();
            }
        } catch (IOException e) {
            cause = e;
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        } catch (NullPointerException e) {
            cause = new IOException("NPE in HttpClient" + e.getMessage());
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        }
    }

    // no retries left, crap out with exception
    ConnectException ex = new ConnectException();
    ex.initCause(cause);
    throw ex;
}

From source file:com.uwindsor.elgg.project.http.AsyncHttpRequest.java

private void makeRequestWithRetries() throws ConnectException {

    // This is an additional layer of retry logic lifted from droid-fu
    // See://from   ww  w. j  a va  2  s . c  o  m
    // https://github.com/kaeppler/droid-fu/blob/master/src/main/java/com/github/droidfu/http/BetterHttpRequestBase.java
    boolean retry = true;
    IOException cause = null;
    HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler();
    while (retry) {
        try {
            makeRequest();
            return;
        } catch (IOException e) {
            cause = e;
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        } catch (NullPointerException e) {
            // there's a bug in HttpClient 4.0.x that on some occasions causes
            // DefaultRequestExecutor to throw an NPE, see
            // http://code.google.com/p/android/issues/detail?id=5255
            cause = new IOException("NPE in HttpClient" + e.getMessage());
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        }
    }

    // no retries left, crap out with exception
    ConnectException ex = new ConnectException();
    ex.initCause(cause);
    throw ex;
}

From source file:net.tsz.afinal.http.AjaxRequestHandler.java

private void makeRequestWithRetries(HttpUriRequest request) throws ConnectException {

    boolean retry = true;
    IOException cause = null;/*from  w ww  .  ja v  a 2  s.  c o  m*/
    HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler();
    while (retry) {
        try {
            if (!isCancelled()) {
                HttpResponse response = client.execute(request, context);
                if (!isCancelled()) {
                    handleResponse(response);
                }
            }
            return;
        } catch (UnknownHostException e) {
            publishProgress(Update_failure, e, "can't resolve host");
            return;
        } catch (IOException e) {
            cause = e;
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        } catch (NullPointerException e) {
            // HttpClient 4.0.x ?bug
            // http://code.google.com/p/android/issues/detail?id=5255
            cause = new IOException("NPE in HttpClient" + e.getMessage());
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        }
    }

    //??
    ConnectException ex = new ConnectException();
    ex.initCause(cause);
    throw ex;
}

From source file:com.heyzap.http.AsyncHttpRequest.java

private void makeRequestWithRetries() throws ConnectException {
    // This is an additional layer of retry logic lifted from droid-fu
    // See: https://github.com/kaeppler/droid-fu/blob/master/src/main/java/com/github/droidfu/http/BetterHttpRequestBase.java
    boolean retry = true;
    IOException cause = null;/*from  ww  w  .  j  av  a  2s. c o  m*/
    HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler();
    while (retry) {
        try {
            makeRequest();
            return;
        } catch (IOException e) {
            cause = e;
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        } catch (NullPointerException e) {
            // there's a bug in HttpClient 4.0.x that on some occasions causes
            // DefaultRequestExecutor to throw an NPE, see
            // http://code.google.com/p/android/issues/detail?id=5255
            cause = new IOException("NPE in HttpClient" + e.getMessage());
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        }
    }

    // no retries left, crap out with exception
    ConnectException ex = new ConnectException();
    ex.initCause(cause);
    throw ex;
}

From source file:com.hippoapp.asyncmvp.http.AsyncCachedHttpRequest.java

private void makeRequestWithRetries() throws ConnectException {
    boolean retry = true;
    IOException cause = null;//  w w w.  j  a  v  a 2  s . com
    HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler();
    while (retry) {
        try {
            makeRequest();
            return;
        } catch (IOException e) {
            cause = e;
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        } catch (NullPointerException e) {
            // http://code.google.com/p/android/issues/detail?id=5255
            cause = new IOException("NPE in HttpClient" + e.getMessage());
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        }
    }

    ConnectException ex = new ConnectException();
    ex.initCause(cause);
    throw ex;
}

From source file:com.baidu.asynchttpclient.AsyncHttpRequest.java

private void makeRequestWithRetries() throws ConnectException {
    // This is an additional layer of retry logic lifted from droid-fu
    // See:/* w w w  . ja v a2 s .c o  m*/
    // https://github.com/kaeppler/droid-fu/blob/master/src/main/java/com/github/droidfu/http/BetterHttpRequestBase.java
    boolean retry = true;
    IOException cause = null;
    HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler();
    while (retry) {
        try {
            makeRequest();
            return;
        } catch (IOException e) {
            cause = e;
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        } catch (NullPointerException e) {
            // there's a bug in HttpClient 4.0.x that on some occasions causes
            // DefaultRequestExecutor to throw an NPE, see
            // http://code.google.com/p/android/issues/detail?id=5255
            cause = new IOException("NPE in HttpClient" + e.getMessage());
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        }
    }

    // no retries left, crap out with exception
    ConnectException ex = new ConnectException();
    ex.initCause(cause);
    throw ex;
}