List of usage examples for org.springframework.http HttpStatus is2xxSuccessful
public boolean is2xxSuccessful()
From source file:com.github.tddts.jet.oauth.server.DefaultAuthHandler.java
@Override public void process(AuthHandlerCallback callback, List<NameValuePair> params) { if (params.isEmpty()) { callback.returnMessage(responseText); } else {/*from w w w.ja va2 s . c om*/ HttpStatus status = authService.processAuthorization(params); String message = status.is2xxSuccessful() ? successMessage : status.getReasonPhrase(); callback.returnMessage(status.value(), message); } }
From source file:de.swm.nis.logicaldecoding.gwc.GWCInvalidator.java
private void postSeedRequest(Envelope envelope) { String gwcurl = gwcBaseUrl + "seed/" + layername + ".json"; Bounds bounds = new Bounds( new Coordinates(envelope.getMinX(), envelope.getMinY(), envelope.getMaxX(), envelope.getMaxY())); Srs srs = new Srs(epsgCode); SeedRequest request = new SeedRequest(layername, bounds, srs, zoomStart, zoomStop, imageFormat, operation, numThreads);/*from www. ja va 2s . co m*/ HttpEntity<GwcSeedDAO> httpentity = new HttpEntity<GwcSeedDAO>(new GwcSeedDAO(request), createHeaders(gwcUserName, gwcPassword)); ResponseEntity response = template.exchange(gwcurl, HttpMethod.POST, httpentity, String.class); HttpStatus returncode = response.getStatusCode(); if (!returncode.is2xxSuccessful()) { log.warn("HTTP Call to " + gwcurl + " was not successfull, Status code: " + response.getStatusCode()); } else { log.debug("HTTP Call to " + gwcurl + "succeeded"); } }
From source file:net.longfalcon.newsj.service.GoogleSearchService.java
public GoogleSearchResponse search(String searchString, String referer) { try {/* w ww .j a v a 2 s. co 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 a2s . 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/*from w w w.jav a2 s. c o m*/ * @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/*from w ww.j av a 2s. 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; }
From source file:net.longfalcon.newsj.service.TraktService.java
public TraktEpisodeResult getEpisode(long traktId, int season, int episode) { try {//from w ww . ja va2s . com 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; }
From source file:org.craftercms.studio.impl.v1.deployment.PreviewDeployerImpl.java
@EventListener(EVENT_PREVIEW_SYNC) public void onPreviewSync(PreviewEventContext context) { String site = context.getSite(); String requestUrl = getDeployTargetUrl(site); HttpPost postRequest = new HttpPost(requestUrl); if (context.isWaitTillDeploymentIsDone()) { String requestBody = getDeployTargetRequestBody(true); HttpEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON); postRequest.setEntity(requestEntity); }// ww w. jav a 2s .c o m // TODO: DB: add all required params to post method try { CloseableHttpResponse response = httpClient.execute(postRequest); HttpStatus httpStatus = HttpStatus.valueOf(response.getStatusLine().getStatusCode()); if (!httpStatus.is2xxSuccessful()) { logger.error("Preview sync request for site " + site + " returned status " + httpStatus + " (" + httpStatus.getReasonPhrase() + ")"); } } catch (IOException e) { logger.error("Error while sending preview sync request for site " + site, e); } finally { postRequest.releaseConnection(); } }
From source file:org.springframework.cloud.function.web.source.HttpSupplier.java
private Mono<?> transform(ClientResponse response) { HttpStatus status = response.statusCode(); if (!status.is2xxSuccessful()) { if (this.props.isDebug()) { logger.info("Delaying supplier based on status=" + response.statusCode()); }/* ww w .j a va 2s . co m*/ return Mono.delay(Duration.ofSeconds(1)); } return response.bodyToMono(this.props.getSource().getType()).map(value -> message(response, value)); }