Example usage for java.io IOException getClass

List of usage examples for java.io IOException getClass

Introduction

In this page you can find the example usage for java.io IOException getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.damytech.HttpConn.RetryHandler.java

public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
    boolean retry = true;

    Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT);
    boolean sent = (b != null && b.booleanValue());

    if (executionCount > maxRetries) {
        // Do not retry if over max retry count
        retry = false;/*  www.j  av  a2  s. c o  m*/
    } else if (exceptionBlacklist.contains(exception.getClass())) {
        // immediately cancel retry if the error is blacklisted
        retry = false;
    } else if (exceptionWhitelist.contains(exception.getClass())) {
        // immediately retry if error is whitelisted
        retry = true;
    } else if (!sent) {
        // for most other errors, retry only if request hasn't been fully sent yet
        retry = true;
    }

    if (retry) {
        // resend all idempotent requests
        HttpRequest currentReq = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
        /*String requestType = currentReq.getMethod();
        retry = !requestType.equals("POST");*/
        retry = !(currentReq instanceof HttpEntityEnclosingRequest);
    }

    if (retry) {
        SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS);
    } else {
        exception.printStackTrace();
    }

    return retry;
}

From source file:com.feilong.commons.core.io.FileUtilTest.java

/**
 * Test get content length./*ww w  .  j av  a2  s  .  co  m*/
 */
@Test
public void testGetContentLength() {
    try {
        URL url = new URL("http://www.jinbaowang.cn/images//20110722/096718c3d1c9b4a1.jpg");
        URLConnection urlConnection = url.openConnection();
        int contentLength = urlConnection.getContentLength();
        log.info(FileUtil.formatSize(contentLength));
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    try {
        URL url = new URL("http://localhost:8080/TestHttpURLConnectionPro/index.jsp");
        url.openConnection();
    } catch (MalformedURLException e) {
        log.error(e.getClass().getName(), e);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:org.apache.http.impl.execchain.RetryExec.java

public CloseableHttpResponse execute(final HttpRoute route, final HttpRequestWrapper request,
        final HttpClientContext context, final HttpExecutionAware execAware) throws IOException, HttpException {
    Args.notNull(route, "HTTP route");
    Args.notNull(request, "HTTP request");
    Args.notNull(context, "HTTP context");
    final Header[] origheaders = request.getAllHeaders();
    for (int execCount = 1;; execCount++) {
        try {//from   www  . j a  v a2  s. c  o m
            return this.requestExecutor.execute(route, request, context, execAware);
        } catch (final IOException ex) {
            if (execAware != null && execAware.isAborted()) {
                this.log.debug("Request has been aborted");
                throw ex;
            }
            if (retryHandler.retryRequest(ex, execCount, context)) {
                if (this.log.isInfoEnabled()) {
                    this.log.info("I/O exception (" + ex.getClass().getName()
                            + ") caught when processing request to " + route + ": " + ex.getMessage());
                }
                if (this.log.isDebugEnabled()) {
                    this.log.debug(ex.getMessage(), ex);
                }
                if (!Proxies.isRepeatable(request)) {
                    this.log.debug("Cannot retry non-repeatable request");
                    throw new NonRepeatableRequestException(
                            "Cannot retry request " + "with a non-repeatable request entity", ex);
                }
                request.setHeaders(origheaders);
                if (this.log.isInfoEnabled()) {
                    this.log.info("Retrying request to " + route);
                }
            } else {
                if (ex instanceof NoHttpResponseException) {
                    final NoHttpResponseException updatedex = new NoHttpResponseException(
                            route.getTargetHost().toHostString() + " failed to respond");
                    updatedex.setStackTrace(ex.getStackTrace());
                    throw updatedex;
                } else {
                    throw ex;
                }
            }
        }
    }
}

From source file:cn.com.dfc.pl.afinal.http.RetryHandler.java

@Override
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
    boolean retry = true;

    Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT);
    boolean sent = (b != null && b.booleanValue());

    if (executionCount > maxRetries) {
        // ?5/*from w  ww. jav a  2 s . c  o m*/
        retry = false;
    } else if (exceptionBlacklist.contains(exception.getClass())) {
        // ??
        retry = false;
    } else if (exceptionWhitelist.contains(exception.getClass())) {
        retry = true;
    } else if (!sent) {
        retry = true;
    }

    if (retry) {
        HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
        retry = currentReq != null && !"POST".equals(currentReq.getMethod());
    }

    if (retry) {
        //1???
        SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS);
    } else {
        exception.printStackTrace();
    }

    return retry;
}

From source file:com.my.cloudcontact.http.RetryHandler.java

@Override
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
    boolean retry = true;

    Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT);
    boolean sent = (b != null && b.booleanValue());

    if (executionCount > maxRetries) {
        // ?5// w  w w  .  ja v a  2  s .  c  o  m
        retry = false;
    } else if (exceptionBlacklist.contains(exception.getClass())) {
        // ??
        retry = false;
    } else if (exceptionWhitelist.contains(exception.getClass())) {
        retry = true;
    } else if (!sent) {
        retry = true;
    }

    if (retry) {
        HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
        retry = currentReq != null && !"POST".equals(currentReq.getMethod());
    }

    if (retry) {
        // 1???
        SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS);
    } else {
        exception.printStackTrace();
    }

    return retry;
}

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

@Override
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {

    boolean retry;

    Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT);
    boolean sent = (b != null && b.booleanValue());

    if (executionCount > maxRetries) {
        // Do not retry if over max retry count
        retry = false;/*ww  w .  ja v  a 2 s .  c o  m*/
    } else if (exceptionBlacklist.contains(exception.getClass())) {
        // immediately cancel retry if the error is blacklisted
        retry = false;
    } else if (exceptionWhitelist.contains(exception.getClass())) {
        // immediately retry if error is whitelisted
        retry = true;
    } else if (!sent) {
        // for most other errors, retry only if request hasn't been fully sent yet
        retry = true;
    } else {
        // resend all idempotent requests
        HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
        String requestType = currentReq.getMethod();
        if (!requestType.equals("POST")) {
            retry = true;
        } else {
            // otherwise do not retry
            retry = false;
        }
    }

    if (retry) {
        SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS);
    } else {
        exception.printStackTrace();
    }

    return retry;
}

From source file:org.apache.http.HC4.impl.execchain.RetryExec.java

@Override
public CloseableHttpResponse execute(final HttpRoute route, final HttpRequestWrapper request,
        final HttpClientContext context, final HttpExecutionAware execAware) throws IOException, HttpException {
    Args.notNull(route, "HTTP route");
    Args.notNull(request, "HTTP request");
    Args.notNull(context, "HTTP context");
    final Header[] origheaders = request.getAllHeaders();
    for (int execCount = 1;; execCount++) {
        try {/*from w  w w.j av a2 s  . c om*/
            return this.requestExecutor.execute(route, request, context, execAware);
        } catch (final IOException ex) {
            if (execAware != null && execAware.isAborted()) {
                this.log.debug("Request has been aborted");
                throw ex;
            }
            if (retryHandler.retryRequest(ex, execCount, context)) {
                if (this.log.isInfoEnabled()) {
                    this.log.info("I/O exception (" + ex.getClass().getName()
                            + ") caught when processing request to " + route + ": " + ex.getMessage());
                }
                if (this.log.isDebugEnabled()) {
                    this.log.debug(ex.getMessage(), ex);
                }
                if (!RequestEntityProxy.isRepeatable(request)) {
                    this.log.debug("Cannot retry non-repeatable request");
                    throw new NonRepeatableRequestException(
                            "Cannot retry request " + "with a non-repeatable request entity", ex);
                }
                request.setHeaders(origheaders);
                if (this.log.isInfoEnabled()) {
                    this.log.info("Retrying request to " + route);
                }
            } else {
                if (ex instanceof NoHttpResponseException) {
                    final NoHttpResponseException updatedex = new NoHttpResponseException(
                            route.getTargetHost().toHostString() + " failed to respond");
                    updatedex.setStackTrace(ex.getStackTrace());
                    throw updatedex;
                } else {
                    throw ex;
                }
            }
        }
    }
}

From source file:org.fracturedatlas.athena.apa.indexing.IndexingApaAdapter.java

private void cleanup(IndexSearcher searcher, IndexReader reader) {
    if (searcher != null) {
        try {/*from w w w. j av a2s. c o m*/
            searcher.close();
        } catch (IOException ioe) {
            logger.error("Error trying to close index searcher");
            logger.error("{}", ioe.getClass().getName());
            logger.error("{}", ioe.getMessage());
        }
    }

    if (reader != null) {
        try {
            reader.close();
        } catch (IOException ioe) {
            logger.error("Error trying to close index writer");
            logger.error("{}", ioe.getClass().getName());
            logger.error("{}", ioe.getMessage());
        }
    }
}

From source file:org.apache.solr.client.solrj.impl.SolrHttpRequestRetryHandler.java

@Override
public boolean retryRequest(final IOException exception, final int executionCount, final HttpContext context) {
    log.debug("Retry http request {} out of {}", executionCount, this.retryCount);
    if (executionCount > this.retryCount) {
        log.debug("Do not retry, over max retry count");
        return false;
    }//from   w  w w .  ja  v a2s . c  om
    if (this.nonRetriableClasses.contains(exception.getClass())) {
        log.debug("Do not retry, non retriable class {}", exception.getClass().getName());
        return false;
    } else {
        for (final Class<? extends IOException> rejectException : this.nonRetriableClasses) {
            if (rejectException.isInstance(exception)) {
                log.debug("Do not retry, non retriable class {}", exception.getClass().getName());
                return false;
            }
        }
    }
    final HttpClientContext clientContext = HttpClientContext.adapt(context);
    final HttpRequest request = clientContext.getRequest();

    if (requestIsAborted(request)) {
        log.debug("Do not retry, request was aborted");
        return false;
    }

    if (handleAsIdempotent(clientContext)) {
        log.debug("Retry, request should be idempotent");
        return true;
    }

    log.debug("Do not retry, no allow rules matched");
    return false;
}

From source file:com.searchcode.app.service.JobService.java

@Override
public boolean rebuildAll() {
    // Turn off everything
    Singleton.getLogger().info("Recrawl and rebuild of index starting");
    Singleton.getSharedService().setBackgroundJobsEnabled(false);
    try {/*from   w w w  .j  a v  a2  s.  c  o m*/
        Thread.sleep(2000);
    } catch (InterruptedException e) {
    }

    this.shutdownScheduler();

    int attempt = 0;
    boolean successful = false;

    String repoLocation = Properties.getProperties().getProperty(Values.REPOSITORYLOCATION,
            Values.DEFAULTREPOSITORYLOCATION);
    String indexLocation = Properties.getProperties().getProperty(Values.INDEXLOCATION,
            Values.DEFAULTINDEXLOCATION);

    while (attempt < 3) {
        try {
            attempt++;
            FileUtils.deleteDirectory(new File(indexLocation));
            FileUtils.deleteDirectory(new File(repoLocation));

            successful = true;

            Singleton.getLogger().info("Recrawl and rebuild of index successful");
            break;
        } catch (IOException ex) {
            Singleton.getLogger().warning("ERROR - caught a " + ex.getClass() + " in " + this.getClass()
                    + "\n with message: " + ex.getMessage());
        }

        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
        }
    }

    if (!successful) {
        successful = this.attemptMoveToTrash(repoLocation, indexLocation);
    }

    Singleton.getSharedService().setBackgroundJobsEnabled(true);
    this.initialJobs();
    return successful;
}