use of org.springframework.web.client.HttpClientErrorException in project spring-security-oauth by spring-projects.
the class AbstractAuthorizationCodeProviderTests method testUnauthenticatedAuthorizationRespondsUnauthorized.
@Test
@OAuth2ContextConfiguration(resource = MyTrustedClient.class, initialize = false)
public void testUnauthenticatedAuthorizationRespondsUnauthorized() throws Exception {
AccessTokenRequest request = context.getAccessTokenRequest();
request.setCurrentUri("http://anywhere");
request.add(OAuth2Utils.USER_OAUTH_APPROVAL, "true");
try {
String code = accessTokenProvider.obtainAuthorizationCode(context.getResource(), request);
assertNotNull(code);
fail("Expected UserRedirectRequiredException");
} catch (HttpClientErrorException e) {
assertEquals(HttpStatus.UNAUTHORIZED, e.getStatusCode());
}
}
use of org.springframework.web.client.HttpClientErrorException in project mirrorgate-jira-stories-collector by BBVA.
the class CollectorService method getUpdatedDate.
public Date getUpdatedDate() {
try {
final MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.set("collectorId", appName);
final UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(mirrorGateUrl + MIRRORGATE_COLLECTOR_ENDPOINT).queryParams(params);
return restTemplate.getForObject(builder.build().toUriString(), Date.class, appName);
} catch (final HttpClientErrorException e) {
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
LOGGER.info("Not previous execution date found. " + "Running from the very beginning so this could take a while");
} else {
LOGGER.error("Error requesting previous collector status", e);
throw e;
}
}
return null;
}
use of org.springframework.web.client.HttpClientErrorException in project mirrorgate-jira-stories-collector by BBVA.
the class SprintService method getSprint.
public SprintDTO getSprint(final String name) {
try {
final MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.set("collectorId", appName);
final UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(mirrorGateUrl + MIRRORGATE_GET_SPRINT_ISSUES_ENDPOINT).queryParams(params);
return restTemplate.getForObject(builder.build().toUriString(), SprintDTO.class, name);
} catch (HttpClientErrorException e) {
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
LOGGER.warn("Sprint {} does not exist", name);
} else {
LOGGER.error("Error getting sprint {}", name, e);
throw e;
}
}
return null;
}
use of org.springframework.web.client.HttpClientErrorException in project spring-boot by spring-projects.
the class ArtifactoryService method promote.
/**
* Move artifacts to a target repository in Artifactory.
* @param targetRepo the targetRepo
* @param releaseInfo the release information
*/
public void promote(String targetRepo, ReleaseInfo releaseInfo) {
PromotionRequest request = getPromotionRequest(targetRepo);
String buildName = releaseInfo.getBuildName();
String buildNumber = releaseInfo.getBuildNumber();
logger.info("Promoting " + buildName + "/" + buildNumber + " to " + request.getTargetRepo());
RequestEntity<PromotionRequest> requestEntity = RequestEntity.post(URI.create(PROMOTION_URL + buildName + "/" + buildNumber)).contentType(MediaType.APPLICATION_JSON).body(request);
try {
this.restTemplate.exchange(requestEntity, String.class);
logger.debug("Promotion complete");
} catch (HttpClientErrorException ex) {
boolean isAlreadyPromoted = isAlreadyPromoted(buildName, buildNumber, request.getTargetRepo());
if (isAlreadyPromoted) {
logger.info("Already promoted.");
} else {
logger.info("Promotion failed.");
throw ex;
}
}
}
use of org.springframework.web.client.HttpClientErrorException in project spring-boot by spring-projects.
the class ArtifactoryService method isAlreadyPromoted.
private boolean isAlreadyPromoted(String buildName, String buildNumber, String targetRepo) {
try {
logger.debug("Checking if already promoted");
ResponseEntity<BuildInfoResponse> entity = this.restTemplate.getForEntity(BUILD_INFO_URL + buildName + "/" + buildNumber, BuildInfoResponse.class);
Status[] statuses = entity.getBody().getBuildInfo().getStatuses();
BuildInfoResponse.Status status = (statuses != null) ? statuses[0] : null;
if (status == null) {
logger.debug("Returned no status object");
return false;
}
logger.debug("Returned repository " + status.getRepository() + " expecting " + targetRepo);
return status.getRepository().equals(targetRepo);
} catch (HttpClientErrorException ex) {
logger.debug("Client error, assuming not promoted");
return false;
}
}
Aggregations