@Override public boolean hasError(ClientHttpResponse response) throws IOException { return this.defaultErrorHandler.hasError(response); }
@Override @Nullable protected final T adapt(ClientHttpResponse response) throws ExecutionException { try { if (!getErrorHandler().hasError(response)) { logResponseStatus(this.method, this.url, response); } else { handleResponseError(this.method, this.url, response); } return convertResponse(response); } catch (Throwable ex) { throw new ExecutionException(ex); } finally { response.close(); } }
/** * Handle the given response, performing appropriate logging and * invoking the {@link ResponseErrorHandler} if necessary. * <p>Can be overridden in subclasses. * @param url the fully-expanded URL to connect to * @param method the HTTP method to execute (GET, POST, etc.) * @param response the resulting {@link ClientHttpResponse} * @throws IOException if propagated from {@link ResponseErrorHandler} * @since 4.1.6 * @see #setErrorHandler */ protected void handleResponse(URI url, HttpMethod method, ClientHttpResponse response) throws IOException { ResponseErrorHandler errorHandler = getErrorHandler(); boolean hasError = errorHandler.hasError(response); if (logger.isDebugEnabled()) { try { int code = response.getRawStatusCode(); HttpStatus status = HttpStatus.resolve(code); logger.debug("Response " + (status != null ? status : code)); } catch (IOException ex) { // ignore } } if (hasError) { errorHandler.handleError(url, method, response); } }
@Override @Nullable protected final T adapt(ClientHttpResponse response) throws ExecutionException { try { if (!getErrorHandler().hasError(response)) { logResponseStatus(this.method, this.url, response); } else { handleResponseError(this.method, this.url, response); } return convertResponse(response); } catch (Throwable ex) { throw new ExecutionException(ex); } finally { response.close(); } }
public boolean hasError(ClientHttpResponse response) throws IOException { return HttpStatus.Series.CLIENT_ERROR.equals(response.getStatusCode().series()) || this.errorHandler.hasError(response); }
/** * Handle the given response, performing appropriate logging and * invoking the {@link ResponseErrorHandler} if necessary. * <p>Can be overridden in subclasses. * @param url the fully-expanded URL to connect to * @param method the HTTP method to execute (GET, POST, etc.) * @param response the resulting {@link ClientHttpResponse} * @throws IOException if propagated from {@link ResponseErrorHandler} * @since 4.1.6 * @see #setErrorHandler */ protected void handleResponse(URI url, HttpMethod method, ClientHttpResponse response) throws IOException { ResponseErrorHandler errorHandler = getErrorHandler(); boolean hasError = errorHandler.hasError(response); if (logger.isDebugEnabled()) { try { int code = response.getRawStatusCode(); HttpStatus status = HttpStatus.resolve(code); logger.debug("Response " + (status != null ? status : code)); } catch (IOException ex) { // ignore } } if (hasError) { errorHandler.handleError(url, method, response); } }
private void mockResponseStatus(HttpStatus responseStatus) throws Exception { given(request.execute()).willReturn(response); given(errorHandler.hasError(response)).willReturn(responseStatus.isError()); given(response.getStatusCode()).willReturn(responseStatus); given(response.getRawStatusCode()).willReturn(responseStatus.value()); given(response.getStatusText()).willReturn(responseStatus.getReasonPhrase()); }
@Override public boolean hasError(ClientHttpResponse response) throws IOException { return this.defaultErrorHandler.hasError(response); }
@Override public boolean hasError(ClientHttpResponse response) throws IOException { return errorHandler.hasError(response); } }
@Override @Nullable protected final T adapt(ClientHttpResponse response) throws ExecutionException { try { if (!getErrorHandler().hasError(response)) { logResponseStatus(this.method, this.url, response); } else { handleResponseError(this.method, this.url, response); } return convertResponse(response); } catch (Throwable ex) { throw new ExecutionException(ex); } finally { response.close(); } }
@Override @Nullable protected final T adapt(ClientHttpResponse response) throws ExecutionException { try { if (!getErrorHandler().hasError(response)) { logResponseStatus(this.method, this.url, response); } else { handleResponseError(this.method, this.url, response); } return convertResponse(response); } catch (Throwable ex) { throw new ExecutionException(ex); } finally { response.close(); } }
public boolean hasError(ClientHttpResponse response) throws IOException { return HttpStatus.Series.CLIENT_ERROR.equals(response.getStatusCode().series()) || this.errorHandler.hasError(response); }
protected void handleResponse(URI url, HttpMethod method, ClientHttpResponse response) throws IOException { ResponseErrorHandler errorHandler = getErrorHandler(); boolean hasError = errorHandler.hasError(response); if (logger.isDebugEnabled()) { try { logger.debug(method.name() + " request for \"" + url + "\" resulted in " + response.getRawStatusCode() + " (" + response.getStatusText() + ")" + (hasError ? "; invoking error handler" : "")); } catch (IOException ex) { // ignore } } if (hasError) { errorHandler.handleError(response); } }
/** * Handle the given response, performing appropriate logging and * invoking the {@link ResponseErrorHandler} if necessary. * <p>Can be overridden in subclasses. * @param url the fully-expanded URL to connect to * @param method the HTTP method to execute (GET, POST, etc.) * @param response the resulting {@link ClientHttpResponse} * @throws IOException if propagated from {@link ResponseErrorHandler} * @since 4.1.6 * @see #setErrorHandler */ protected void handleResponse(URI url, HttpMethod method, ClientHttpResponse response) throws IOException { ResponseErrorHandler errorHandler = getErrorHandler(); boolean hasError = errorHandler.hasError(response); if (logger.isDebugEnabled()) { try { logger.debug(method.name() + " request for \"" + url + "\" resulted in " + response.getRawStatusCode() + " (" + response.getStatusText() + ")" + (hasError ? "; invoking error handler" : "")); } catch (IOException ex) { // ignore } } if (hasError) { errorHandler.handleError(url, method, response); } }
/** * Handle the given response, performing appropriate logging and * invoking the {@link ResponseErrorHandler} if necessary. * <p>Can be overridden in subclasses. * @param url the fully-expanded URL to connect to * @param method the HTTP method to execute (GET, POST, etc.) * @param response the resulting {@link ClientHttpResponse} * @throws IOException if propagated from {@link ResponseErrorHandler} * @since 4.1.6 * @see #setErrorHandler */ protected void handleResponse(URI url, HttpMethod method, ClientHttpResponse response) throws IOException { ResponseErrorHandler errorHandler = getErrorHandler(); boolean hasError = errorHandler.hasError(response); if (logger.isDebugEnabled()) { try { int code = response.getRawStatusCode(); HttpStatus status = HttpStatus.resolve(code); logger.debug("Response " + (status != null ? status : code)); } catch (IOException ex) { // ignore } } if (hasError) { errorHandler.handleError(url, method, response); } }
private void initTransfer(final long firstByteInRange) throws IOException { final ClientHttpRequest request = restTemplate.getRequestFactory().createRequest(uri, HttpMethod.GET); if (firstByteInRange > 0) { request.getHeaders().add("Range", "bytes:" + firstByteInRange + "-"); } final ClientHttpResponse response = request.execute(); if (restTemplate.getErrorHandler().hasError(response)) { state = StreamingResourceState.ERROR; throw new IllegalStateException("Transfer initialization failed, error code " + response.getStatusCode() + ":" + response.getStatusText()); } state = StreamingResourceState.TRANSFER_IN_PROGRESS; inputStream = response.getBody(); contentLength = response.getHeaders().getContentLength(); }
public Metadata putFile(String path, byte[] file) { UriTemplate uriTemplate = new UriTemplate(FILE_PUT_URL); URI uri = uriTemplate.expand(appFolderUrl, path); try { ClientHttpRequest request = getRestTemplate().getRequestFactory().createRequest(uri, HttpMethod.PUT); request.getBody().write(file); ClientHttpResponse response = request.execute(); ResponseErrorHandler errorHandler = new DefaultResponseErrorHandler(); if (errorHandler.hasError(response)) { errorHandler.handleError(response); return null; } else { InputStream stream = response.getBody(); return objectMapper.readValue(stream, Metadata.class); } } catch (Exception e) { throw new RuntimeException(e); } }
if (!getErrorHandler().hasError(response)) { logResponseStatus(method, url, response);