Package org.apache.http.client

Examples of org.apache.http.client.ClientProtocolException


            String host = ssp.substring(0, end);

            int port = requestURI.getPort();
            String scheme = requestURI.getScheme();
            if (host == null || "".equals(host)) {
                throw new ClientProtocolException(
                        "URI does not specify a valid host name: " + requestURI);
            }
            target = new HttpHost(host, port, scheme);
        }
        return target;
View Full Code Here


        }

        try {
            return director.execute(target, request, execContext);
        } catch(HttpException httpException) {
            throw new ClientProtocolException(httpException);
        }
    }
View Full Code Here

        }

        try {
            request = requestCompliance.makeRequestCompliant(request);
        } catch (ProtocolException e) {
            throw new ClientProtocolException(e);
        }
        request.addHeader("Via",via);

        try {
            responseCache.flushInvalidatedCacheEntriesFor(target, request);
        } catch (IOException ioe) {
            log.warn("Unable to flush invalidated entries from cache", ioe);
        }

        if (!cacheableRequestPolicy.isServableFromCache(request)) {
            return callBackend(target, request, context);
        }

        HttpCacheEntry entry = null;
        try {
            entry = responseCache.getCacheEntry(target, request);
        } catch (IOException ioe) {
            log.warn("Unable to retrieve entries from cache", ioe);
        }
        if (entry == null) {
            cacheMisses.getAndIncrement();
            if (log.isDebugEnabled()) {
                RequestLine rl = request.getRequestLine();
                log.debug("Cache miss [host: " + target + "; uri: " + rl.getUri() + "]");
            }

            if (!mayCallBackend(request)) {
                return new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_GATEWAY_TIMEOUT,
                        "Gateway Timeout");
            }

            Set<HttpCacheEntry> variantEntries = null;
            try {
                responseCache.getVariantCacheEntries(target, request);
            } catch (IOException ioe) {
                log.warn("Unable to retrieve variant entries from cache", ioe);
            }
            if (variantEntries != null && variantEntries.size() > 0) {
                try {
                    return negotiateResponseFromVariants(target, request, context, variantEntries);
                } catch (ProtocolException e) {
                    throw new ClientProtocolException(e);
                }
            }

            return callBackend(target, request, context);
        }

        if (log.isDebugEnabled()) {
            RequestLine rl = request.getRequestLine();
            log.debug("Cache hit [host: " + target + "; uri: " + rl.getUri() + "]");

        }
        cacheHits.getAndIncrement();

        Date now = getCurrentDate();
        if (suitabilityChecker.canCachedResponseBeUsed(target, request, entry, now)) {
            final HttpResponse cachedResponse;
            if (request.containsHeader(HeaderConstants.IF_NONE_MATCH)
                    || request.containsHeader(HeaderConstants.IF_MODIFIED_SINCE)) {
                cachedResponse = responseGenerator.generateNotModifiedResponse(entry);
            } else {
                cachedResponse = responseGenerator.generateResponse(entry);
            }
            setResponseStatus(context, CacheResponseStatus.CACHE_HIT);
            if (validityPolicy.getStalenessSecs(entry, now) > 0L) {
                cachedResponse.addHeader("Warning","110 localhost \"Response is stale\"");
            }
            return cachedResponse;
        }

        if (!mayCallBackend(request)) {
            return new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_GATEWAY_TIMEOUT,
                    "Gateway Timeout");
        }

        if (validityPolicy.isRevalidatable(entry)) {
            log.debug("Revalidating the cache entry");

            try {
                return revalidateCacheEntry(target, request, context, entry);
            } catch (IOException ioex) {
                if (validityPolicy.mustRevalidate(entry)
                    || (isSharedCache() && validityPolicy.proxyRevalidate(entry))
                    || explicitFreshnessRequest(request, entry, now)) {
                    setResponseStatus(context, CacheResponseStatus.CACHE_MODULE_RESPONSE);
                    return new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_GATEWAY_TIMEOUT, "Gateway Timeout");
                } else {
                    final HttpResponse cachedResponse = responseGenerator.generateResponse(entry);
                    setResponseStatus(context, CacheResponseStatus.CACHE_HIT);
                    cachedResponse.addHeader(HeaderConstants.WARNING, "111 localhost \"Revalidation failed\"");
                    log.debug("111 revalidation failed due to exception: " + ioex);
                    return cachedResponse;
                }
            } catch (ProtocolException e) {
                throw new ClientProtocolException(e);
            }
        }
        return callBackend(target, request, context);
    }
View Full Code Here

            ZeroCopyConsumer<File> consumer = new ZeroCopyConsumer<File>(download) {

                @Override
                protected File process(final HttpResponse response, final File file) throws Exception {
                    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                        throw new ClientProtocolException("Upload failed: " + response.getStatusLine());
                    }
                    return file;
                }

            };
View Full Code Here

            HttpResponse response = httpClient.execute(postRequest);

            return response;
        } catch (ClientProtocolException e) {
            throw new ClientProtocolException();
        } catch (ConnectException e) {
            throw new ConnectException();
        }
        catch (IOException e) {
            e.printStackTrace();
View Full Code Here

            HttpResponse response = httpClient.execute(getRequest);

            return response;
        } catch (ClientProtocolException e) {
            throw new ClientProtocolException();
        } catch (ConnectException e) {
            throw new ConnectException();
        } catch (IOException e) {
            e.printStackTrace();
            return null;
View Full Code Here

        final URI requestURI = request.getURI();
        if (requestURI.isAbsolute()) {
            target = URIUtils.extractHost(requestURI);
            if (target == null) {
                throw new ClientProtocolException(
                        "URI does not specify a valid host name: " + requestURI);
            }
        }
        return target;
    }
View Full Code Here

                return out;
            } else {
                return director.execute(target, request, execContext);
            }
        } catch(final HttpException httpException) {
            throw new ClientProtocolException(httpException);
        }
    }
View Full Code Here

            } catch (RuntimeException ex) {
                EntityUtils.consume(response.getEntity());
                throw ex;
            }
        } catch (HttpException e) {
            throw new ClientProtocolException(e);
        }
    }
View Full Code Here

                    expiresDate = new Date(System.currentTimeMillis() + RETRY_AFTER *1000);
                }

            } else {
                log.error("the HTTP request failed (status: {})", response.getStatusLine());
                throw new ClientProtocolException("the HTTP request failed (status: " + response.getStatusLine() + ")");
            }

            return requestUrls;
        }
View Full Code Here

TOP

Related Classes of org.apache.http.client.ClientProtocolException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.