List of usage examples for org.springframework.http HttpStatus is3xxRedirection
public boolean is3xxRedirection()
From source file:craterdog.marketplace.ServiceResponseErrorHandler.java
@Override protected boolean hasError(HttpStatus statusCode) { // only throw exception when the status code is not expected boolean result = statusCode.is1xxInformational() || statusCode.is3xxRedirection(); return result; }
From source file:net.longfalcon.newsj.service.GoogleSearchService.java
public GoogleSearchResponse search(String searchString, String referer) { try {// ww w .ja v a 2s . c om 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 w w w. j a va 2 s . co 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/* ww w. j a va 2 s . com*/ * @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.com*/ * @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; }
From source file:net.longfalcon.newsj.service.TraktService.java
public TraktEpisodeResult getEpisode(long traktId, int season, int episode) { try {/*from w w w. ja v a 2 s . c o m*/ 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 + "/shows/" + traktId + "/seasons/" + season + "/episodes/" + episode) .queryParam("extended", "full").build(); ResponseEntity<TraktEpisodeResult> responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, requestEntity, TraktEpisodeResult.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; }