List of usage examples for org.springframework.http HttpStatus getReasonPhrase
public String getReasonPhrase()
From source file:com.walmart.gatling.AbstractRestIntTest.java
protected HttpStatus delete(String url) { ResponseEntity<Void> response = template.exchange(url, HttpMethod.DELETE, null, Void.class); HttpStatus code = response.getStatusCode(); if (code == HttpStatus.OK || code == HttpStatus.NO_CONTENT || code == HttpStatus.NOT_FOUND) return response.getStatusCode(); else {//from w w w . j a v a 2s. co m fail("Expected the delete response to be 200 or 404, but was " + code.value() + "(" + code.getReasonPhrase() + ")."); return null; //for compiler } }
From source file:com.github.jmnarloch.spring.cloud.feign.VndErrorDecoder.java
/** * Creates the instance of {@link VndErrorException}. * * @param response the response//ww w. java2 s . c o m * @param body the response body * @param vndErrors the vnd errors @return the exception instance */ private VndErrorException createException(Response response, byte[] body, VndErrors vndErrors) { final HttpStatus status = HttpStatus.valueOf(response.status()); final HttpHeaders headers = mapHeaders(response.headers()); final Charset charset = getCharset(headers); return new VndErrorException(status, status.getReasonPhrase(), headers, body, charset, vndErrors); }
From source file:dk.clanie.bitcoin.client.BitcoindJsonRpcErrorHandler.java
/** * Parses the response body, deserializing it into an BitcoinJsonRpcErrorResponse object. * <p>/* w ww. j av a 2 s .co m*/ * If parsing fails an BitcoinException containing the given HTTP error code is thrown. * * @param response * @param statusCode * @return BitcoinJsonRpcErrorResponse * @throws BitcoinException */ private BitcoindErrorResponse parseResponse(ClientHttpResponse response, HttpStatus statusCode) { String body = new String(getResponseBody(response), getCharset(response)); try { return objectMapper.readValue(body, BitcoindErrorResponse.class); } catch (IOException ioe) { throw new BitcoinException("Received an HTTP " + statusCode.value() + " " + statusCode.getReasonPhrase() + ". Response parsing failed.", ioe); } }
From source file:nl.minbzk.dwr.zoeken.enricher.uploader.ElasticSearchResultUploader.java
/** * {@inheritDoc}/*from w ww.jav a 2 s . c o m*/ */ @Override public void deleteByReference(final EnricherJob job, final String field, final String[] documents) throws Exception { final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); XContentBuilder builder = XContentFactory.jsonBuilder(outputStream); try { builder.startObject(); builder.startObject("bool"); builder.startArray("should"); for (String document : documents) { builder.startObject(); builder.startObject("match"); builder.field(field, document); builder.endObject(); builder.endObject(); } builder.endArray(); builder.endObject(); builder.endObject(); builder.flush(); // Then post the result String queryUri = format("http://%s/%s/%s/_query", getElasticSearchUri(), job.getDatabaseName(), job.getDatabaseType()); HttpStatus status = operations.execute(queryUri, HttpMethod.DELETE, new RequestCallback() { @Override public void doWithRequest(final ClientHttpRequest request) throws IOException { request.getBody().write(outputStream.toByteArray()); } }, new ResponseExtractor<HttpStatus>() { @Override public HttpStatus extractData(final ClientHttpResponse response) throws IOException { return response.getStatusCode(); } }, null); if (status.value() == HttpStatus.OK.value()) logger.info(format("Successfully removed document(s) from ElasticSearch")); else logger.error( format("Failed to delete document(s) from ElasticSearch %s", status.getReasonPhrase())); } finally { builder.close(); } }
From source file:eu.freme.common.exception.ExceptionHandlerService.java
public ResponseEntity<String> handleError(HttpServletRequest req, Throwable exception) { logger.error("Request: " + req.getRequestURL() + " raised ", exception); HttpStatus statusCode = null; if (exception instanceof MissingServletRequestParameterException) { // create response for spring exceptions statusCode = HttpStatus.BAD_REQUEST; } else if (exception instanceof FREMEHttpException && ((FREMEHttpException) exception).getHttpStatusCode() != null) { // get response code from FREMEHttpException statusCode = ((FREMEHttpException) exception).getHttpStatusCode(); } else if (exception instanceof AccessDeniedException) { statusCode = HttpStatus.UNAUTHORIZED; } else if (exception instanceof HttpMessageNotReadableException) { statusCode = HttpStatus.BAD_REQUEST; } else {/*from w ww . java2 s . c o m*/ // get status code from exception class annotation Annotation responseStatusAnnotation = exception.getClass().getAnnotation(ResponseStatus.class); if (responseStatusAnnotation instanceof ResponseStatus) { statusCode = ((ResponseStatus) responseStatusAnnotation).value(); } else { // set default status code 500 statusCode = HttpStatus.INTERNAL_SERVER_ERROR; } } JSONObject json = new JSONObject(); json.put("status", statusCode.value()); json.put("message", exception.getMessage()); json.put("error", statusCode.getReasonPhrase()); json.put("timestamp", new Date().getTime()); json.put("exception", exception.getClass().getName()); json.put("path", req.getRequestURI()); if (exception instanceof AdditionalFieldsException) { Map<String, JSONObject> additionalFields = ((AdditionalFieldsException) exception) .getAdditionalFields(); for (String key : additionalFields.keySet()) { json.put(key, additionalFields.get(key)); } } HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.add("Content-Type", "application/json"); return new ResponseEntity<String>(json.toString(2), responseHeaders, statusCode); }
From source file:it.infn.mw.iam.core.web.IamErrorController.java
@RequestMapping(PATH) public ModelAndView error(HttpServletRequest request) { ModelAndView errorPage = new ModelAndView(IAM_ERROR_VIEW); HttpStatus status = HttpStatus.valueOf(getErrorCode(request)); errorPage.addObject("errorMessage", String.format("%d. %s", status.value(), status.getReasonPhrase())); Exception exception = getRequestException(request); if (exception != null) { errorPage.addObject("exceptionMessage", exception.getMessage()); errorPage.addObject("exceptionStackTrace", ExceptionUtils.getStackTrace(exception).trim()); }/*from ww w. j av a 2 s. c o m*/ return errorPage; }
From source file:net.longfalcon.newsj.service.GoogleSearchService.java
public GoogleSearchResponse search(String searchString, String referer) { try {/* w w w . j ava 2 s .c o m*/ if (ValidatorUtil.isNull(referer)) { referer = "http://longfalcon.net"; } String v = "1.0"; String userip = "192.168.0.1"; HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.set("Referer", referer); HttpEntity<?> requestEntity = new HttpEntity(httpHeaders); UriComponents uriComponents = UriComponentsBuilder.fromUriString(_SEARCH_URL).queryParam("v", v) .queryParam("q", searchString).queryParam("userip", userip).build(); ResponseEntity<GoogleSearchResponse> responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, requestEntity, GoogleSearchResponse.class); HttpStatus statusCode = responseEntity.getStatusCode(); if (statusCode.is2xxSuccessful() || statusCode.is3xxRedirection()) { return responseEntity.getBody(); } else { _log.error(String.format("Search request: \n%s\n failed with HTTP code %s : %s", uriComponents.toString(), statusCode.toString(), statusCode.getReasonPhrase())); return null; } } catch (Exception e) { _log.error(e); } return null; }
From source file:net.longfalcon.newsj.service.TmdbService.java
public TmdbFindResults findResultsByImdbId(int imdbId) { try {//from www. ja v a 2s . c o m String tmdbUrlBase = config.getTmdbApiUrl(); String apiKey = config.getDefaultSite().getTmdbKey(); HttpHeaders httpHeaders = new HttpHeaders(); HttpEntity<?> requestEntity = new HttpEntity(httpHeaders); UriComponents uriComponents = UriComponentsBuilder .fromUriString(tmdbUrlBase + "/find/tt" + String.format("%07d", imdbId)) .queryParam("external_source", "imdb_id").queryParam("api_key", apiKey).build(); ResponseEntity<TmdbFindResults> responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, requestEntity, TmdbFindResults.class); HttpStatus statusCode = responseEntity.getStatusCode(); if (statusCode.is2xxSuccessful() || statusCode.is3xxRedirection()) { return responseEntity.getBody(); } else { _log.error(String.format("Search request: \n%s\n failed with HTTP code %s : %s", uriComponents.toString(), statusCode.toString(), statusCode.getReasonPhrase())); return null; } } catch (Exception e) { _log.error(e.toString(), e); } return null; }
From source file:net.longfalcon.newsj.service.TraktService.java
/** * call ID lookup web service//w w w . j a va 2s .c om * @param id id to look up that matches the id type. String to allow imdb queries "ttxxxxxx" * @param idType Possible values: trakt-movie , trakt-show , trakt-episode , imdb , tmdb , tvdb , tvrage . * @return */ protected TraktResult[] searchById(String id, String idType) { try { String traktApiUrl = config.getTraktApiUrl(); String traktAppId = config.getTraktAppId(); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.set("Content-type", "application/json"); httpHeaders.set("trakt-api-key", traktAppId); httpHeaders.set("trakt-api-version", "2"); HttpEntity<?> requestEntity = new HttpEntity(httpHeaders); UriComponents uriComponents = UriComponentsBuilder.fromUriString(traktApiUrl + "/search") .queryParam("id_type", idType).queryParam("id", id).build(); ResponseEntity<TraktResult[]> responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, requestEntity, TraktResult[].class); HttpStatus statusCode = responseEntity.getStatusCode(); if (statusCode.is2xxSuccessful() || statusCode.is3xxRedirection()) { return responseEntity.getBody(); } else { _log.error(String.format("Trakt Search request: \n%s\n failed with HTTP code %s : %s", uriComponents.toString(), statusCode.toString(), statusCode.getReasonPhrase())); return null; } } catch (Exception e) { _log.error(e.toString(), e); } return null; }
From source file:net.longfalcon.newsj.service.TraktService.java
/** * call text search web service/* ww w . jav a 2 s. c o m*/ * @param name * @param type Possible values: movie , show , episode , person , list . * @return */ protected TraktResult[] searchByName(String name, String type) { try { String traktApiUrl = config.getTraktApiUrl(); String traktAppId = config.getTraktAppId(); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.set("Content-type", "application/json"); httpHeaders.set("trakt-api-key", traktAppId); httpHeaders.set("trakt-api-version", "2"); HttpEntity<?> requestEntity = new HttpEntity(httpHeaders); UriComponents uriComponents = UriComponentsBuilder.fromUriString(traktApiUrl + "/search") .queryParam("query", name).queryParam("type", type).build(); ResponseEntity<TraktResult[]> responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, requestEntity, TraktResult[].class); HttpStatus statusCode = responseEntity.getStatusCode(); if (statusCode.is2xxSuccessful() || statusCode.is3xxRedirection()) { return responseEntity.getBody(); } else { _log.error(String.format("Trakt Search request: \n%s\n failed with HTTP code %s : %s", uriComponents.toString(), statusCode.toString(), statusCode.getReasonPhrase())); return null; } } catch (Exception e) { _log.error(e.toString(), e); } return null; }