List of usage examples for java.net SocketTimeoutException setStackTrace
public void setStackTrace(StackTraceElement[] stackTrace)
From source file:com.proofpoint.http.client.ApacheHttpClient.java
public <T, E extends Exception> T execute(Request request, final ResponseHandler<T, E> responseHandler) throws E { Preconditions.checkNotNull(request, "request is null"); Preconditions.checkNotNull(responseHandler, "responseHandler is null"); for (HttpRequestFilter requestFilter : requestFilters) { request = requestFilter.filterRequest(request); }//from www .j a v a2 s . c o m final long requestStart = System.nanoTime(); final StatsHttpUriRequest httpUriRequest = StatsHttpUriRequest.createGenericHttpRequest(request); final Request finalRequest = request; try { T value = httpClient.execute(httpUriRequest, new org.apache.http.client.ResponseHandler<T>() { @Override public T handleResponse(HttpResponse httpResponse) throws IOException { long responseStart = System.nanoTime(); Response response = new MyResponse(httpResponse); try { T value = responseHandler.handle(finalRequest, response); return value; } catch (Exception e) { throw new ExceptionFromResponseHandler(e); } finally { Duration responseProcessingTime = Duration.nanosSince(responseStart); Duration requestProcessingTime = new Duration(responseStart - requestStart, TimeUnit.NANOSECONDS); stats.record(finalRequest.getMethod(), response.getStatusCode(), httpUriRequest.getBytesWritten(), response.getBytesRead(), requestProcessingTime, responseProcessingTime); } } }); return value; } catch (Exception e) { if (e instanceof ExceptionFromResponseHandler) { try { throw (E) e.getCause(); } catch (ClassCastException classCastException) { // this should never happen but generics suck so be safe // handler will be notified of the same exception again below } } else if (e instanceof ConnectTimeoutException) { // apache http client eats the socket timeout exception SocketTimeoutException socketTimeoutException = new SocketTimeoutException(e.getMessage()); socketTimeoutException.setStackTrace(e.getStackTrace()); return responseHandler.handleException(request, socketTimeoutException); } return responseHandler.handleException(request, e); } }