List of usage examples for org.springframework.http HttpStatus series
public Series series()
From source file:nu.yona.server.rest.RestUtil.java
public static boolean isError(HttpStatus status) { HttpStatus.Series series = status.series(); return (series == HttpStatus.Series.CLIENT_ERROR || series == HttpStatus.Series.SERVER_ERROR); }
From source file:com.sra.biotech.submittool.persistence.client.RestUtil.java
public static boolean isError(HttpStatus status) { HttpStatus.Series series = status.series(); return (HttpStatus.Series.CLIENT_ERROR.equals(series) || HttpStatus.Series.SERVER_ERROR.equals(series)); }
From source file:org.craftercms.commons.rest.HttpMessageConvertingResponseErrorHandler.java
protected boolean hasError(HttpStatus statusCode) { return (statusCode.series() == HttpStatus.Series.CLIENT_ERROR || statusCode.series() == HttpStatus.Series.SERVER_ERROR); }
From source file:nl.gridshore.nosapi.impl.NosApiResponseErrorHandler.java
@Override public boolean hasError(ClientHttpResponse response) throws IOException { HttpStatus statusCode = response.getStatusCode(); return (statusCode.series() == HttpStatus.Series.CLIENT_ERROR || statusCode.series() == HttpStatus.Series.SERVER_ERROR); }
From source file:org.cloudfoundry.identity.uaa.login.RemoteUaaAuthenticationManager.java
public RemoteUaaAuthenticationManager() { RestTemplate restTemplate = new RestTemplate(); // The default java.net client doesn't allow you to handle 4xx responses restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory()); restTemplate.setErrorHandler(new DefaultResponseErrorHandler() { protected boolean hasError(HttpStatus statusCode) { return statusCode.series() == HttpStatus.Series.SERVER_ERROR; }//w w w .j a va 2s. c om }); this.restTemplate = restTemplate; }
From source file:org.zalando.riptide.Selectors.java
/** * A {@link Selector} that selects a binding based on the response's status code series * * @return an HTTP status code series selector * @see org.springframework.http.HttpStatus.Series *///from w ww. ja v a 2 s. c o m public static Selector<HttpStatus.Series> series() { return new SeriesSelector(); }
From source file:com.neiljbrown.brighttalk.channels.reportingapi.client.spring.ApiResponseErrorHandler.java
/** * Template method called from {@link #hasError(ClientHttpResponse)}. * <p>/*from w w w . j av a 2 s . co m*/ * The default implementation checks if the given status code is * {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR CLIENT_ERROR} or * {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR SERVER_ERROR}. Can be overridden in subclasses. * * @param statusCode the HTTP status code * @return {@code true} if the response has an error; {@code false} otherwise */ protected boolean hasError(HttpStatus statusCode) { return (statusCode.series() == HttpStatus.Series.CLIENT_ERROR || statusCode.series() == HttpStatus.Series.SERVER_ERROR); }
From source file:com.sastix.cms.common.client.exception.CommonExceptionHandler.java
/** * This default implementation throws a {@link HttpClientErrorException} if the response status code * is {@link HttpStatus.Series#CLIENT_ERROR}, a {@link HttpServerErrorException} * if it is {@link HttpStatus.Series#SERVER_ERROR}, * and a {@link RestClientException} in other cases. *///from w ww. ja v a 2 s . c o m @Override public void handleError(ClientHttpResponse response) throws IOException, RestClientException { HttpStatus statusCode = getHttpStatusCode(response); switch (statusCode.series()) { case CLIENT_ERROR: final byte[] responseBody = getResponseBody(response); final Charset charset = getCharset(response); final String statusText = response.getStatusText(); final HttpHeaders httpHeaders = response.getHeaders(); final RestErrorDTO errorDTO; try { errorDTO = objectMapper.readValue(new String(responseBody, charset), RestErrorDTO.class); LOG.error("Exception: " + errorDTO.toString()); } catch (final Exception e) { //Wasn't able to map String on ErrorDTO. //It is an Unknown Exception //Throw Default Exception final HttpClientErrorException clientErrorException = new HttpClientErrorException(statusCode, statusText, httpHeaders, responseBody, charset); LOG.error("Unknown Exception: " + clientErrorException.getMessage()); throw clientErrorException; } if (exceptionClasses.containsKey(errorDTO.getException())) { throw (exceptionClasses.get(errorDTO.getException())).create(errorDTO.getMessage()); } else { throw new HttpClientErrorException(statusCode, statusText, httpHeaders, responseBody, charset); } case SERVER_ERROR: throw new HttpServerErrorException(statusCode, response.getStatusText(), response.getHeaders(), getResponseBody(response), getCharset(response)); default: throw new RestClientException("Unknown status code [" + statusCode + "]"); } }
From source file:org.bremersee.common.web.client.ResponseErrorHandlerImpl.java
@Override public boolean hasError(final ClientHttpResponse response) throws IOException { boolean hasError; try {//from ww w . ja v a 2 s .co m HttpStatus statusCode = response.getStatusCode(); hasError = statusCode.series() == HttpStatus.Series.CLIENT_ERROR || statusCode.series() == HttpStatus.Series.SERVER_ERROR; } catch (Throwable t) { // NOSONAR hasError = response.getRawStatusCode() >= 400; } if (log.isTraceEnabled()) { log.trace("Response is error? " + hasError); } return hasError; }
From source file:dk.clanie.bitcoin.client.BitcoindJsonRpcErrorHandler.java
public void handleError(ClientHttpResponse response) throws IOException { HttpStatus statusCode = getHttpStatusCode(response); switch (statusCode.series()) { case SERVER_ERROR: { BitcoindErrorResponse errorResponse = parseResponse(response, statusCode); switch (errorResponse.getError().getCode()) { // Comments are observed error messages for each code. case -1://from w w w . ja v a 2 s. c o m // a multisignature address must require at least one key to redeem // no full public key for address <bitcoinaddress> // createrawtransaction [{\"txid\":txid,\"vout\":n},...] {address:amount,...}\nCreate a transaction ... throw new BitcoinServerException(errorResponse); case -4: // Private key for address <bitcoinaddress> is not known // Wallet backup failed! // Error adding key to wallet throw new BitcoinServerException(errorResponse); case -5: // Invalid Bitcoin address throw new InvalidAddressException(errorResponse); case -13: // Error: Please enter the wallet passphrase with walletpassphrase first. throw new BitcoinServerException(errorResponse); case -14: // Error: The wallet passphrase entered was incorrect. throw new BitcoinServerException(errorResponse); case -15: // Error: running with an unencrypted wallet, but walletpassphrasechange was called. // Error: running with an encrypted wallet, but encryptwallet was called. throw new WalletEncryptionException(errorResponse); case -17: // Error: Wallet is already unlocked. throw new BitcoinServerException(errorResponse); default: throw new BitcoinServerException(errorResponse); } } case CLIENT_ERROR: { BitcoindErrorResponse errorResponse = parseResponse(response, statusCode); switch (errorResponse.getError().getCode()) { case -32601: // Method not found throw new MethodNotFoundException(errorResponse); default: throw new BitcoinClientException(errorResponse); } } default: try { super.handleError(response); } catch (Exception cause) { throw new BitcoinException(cause); } } }