Example usage for org.apache.commons.httpclient HttpRecoverableException getClass

List of usage examples for org.apache.commons.httpclient HttpRecoverableException getClass

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpRecoverableException getClass.

Prototype

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

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.openlaszlo.data.HTTPDataSource.java

public static Data getHTTPData(HttpServletRequest req, HttpServletResponse res, String surl, long since)
        throws DataSourceException, IOException {

    int tries = 1;

    // timeout msecs of time we're allowed in this routine
    // we must return or throw an exception.  0 means infinite.
    int timeout = mTimeout;
    if (req != null) {
        String timeoutParm = req.getParameter("timeout");
        if (timeoutParm != null) {
            timeout = Integer.parseInt(timeoutParm);
        }//w w  w .  j a  v a2s.c om
    }

    long t1 = System.currentTimeMillis();
    long elapsed = 0;
    if (surl == null) {
        surl = getURL(req);
    }

    while (true) {
        long tout;
        if (timeout > 0) {
            tout = timeout - elapsed;
            if (tout <= 0) {
                throw new InterruptedIOException(
                        /* (non-Javadoc)
                         * @i18n.test
                         * @org-mes=p[0] + " timed out"
                         */
                        org.openlaszlo.i18n.LaszloMessages.getMessage(HTTPDataSource.class.getName(),
                                "051018-194", new Object[] { surl }));
            }
        } else {
            tout = 0;
        }

        try {
            HttpData data = getDataOnce(req, res, since, surl, 0, (int) tout);
            if (data.code >= 400) {
                data.release();
                throw new DataSourceException(errorMessage(data.code));
            }
            return data;
        } catch (HttpRecoverableException e) {
            // This type of exception should be retried.
            if (tries++ > mMaxRetries) {
                throw new InterruptedIOException(
                        /* (non-Javadoc)
                         * @i18n.test
                         * @org-mes="too many retries, exception: " + p[0]
                         */
                        org.openlaszlo.i18n.LaszloMessages.getMessage(HTTPDataSource.class.getName(),
                                "051018-217", new Object[] { e.getMessage() }));
            }
            mLogger.warn(
                    /* (non-Javadoc)
                     * @i18n.test
                     * @org-mes="retrying a recoverable exception: " + p[0]
                     */
                    org.openlaszlo.i18n.LaszloMessages.getMessage(HTTPDataSource.class.getName(), "051018-226",
                            new Object[] { e.getMessage() }));
        } catch (HttpException e) {
            throw new IOException(
                    /* (non-Javadoc)
                     * @i18n.test
                     * @org-mes="HttpException: " + p[0]
                     */
                    org.openlaszlo.i18n.LaszloMessages.getMessage(HTTPDataSource.class.getName(), "051018-235",
                            new Object[] { e.getMessage() }));
        } catch (IOException e) {

            try {
                Class<?> ssle = Class.forName("javax.net.ssl.SSLException");
                if (ssle.isAssignableFrom(e.getClass())) {
                    throw new DataSourceException(
                            /* (non-Javadoc)
                             * @i18n.test
                             * @org-mes="SSL exception: " + p[0]
                             */
                            org.openlaszlo.i18n.LaszloMessages.getMessage(HTTPDataSource.class.getName(),
                                    "051018-256", new Object[] { e.getMessage() }));
                }
            } catch (ClassNotFoundException cfne) {
            }

            throw e;
        }

        long t2 = System.currentTimeMillis();
        elapsed = (t2 - t1);
    }
}