Search in sources :

Example 66 with HttpClientErrorException

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());
    }
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) AccessTokenRequest(org.springframework.security.oauth2.client.token.AccessTokenRequest) OAuth2ContextConfiguration(org.springframework.security.oauth2.client.test.OAuth2ContextConfiguration) Test(org.junit.Test)

Example 67 with HttpClientErrorException

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;
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder)

Example 68 with HttpClientErrorException

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;
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder)

Example 69 with HttpClientErrorException

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;
        }
    }
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) PromotionRequest(io.spring.concourse.releasescripts.artifactory.payload.PromotionRequest)

Example 70 with HttpClientErrorException

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;
    }
}
Also used : Status(io.spring.concourse.releasescripts.artifactory.payload.BuildInfoResponse.Status) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) Status(io.spring.concourse.releasescripts.artifactory.payload.BuildInfoResponse.Status) BuildInfoResponse(io.spring.concourse.releasescripts.artifactory.payload.BuildInfoResponse)

Aggregations

HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)109 HttpHeaders (org.springframework.http.HttpHeaders)31 Test (org.junit.Test)25 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)24 HashMap (java.util.HashMap)21 HttpServerErrorException (org.springframework.web.client.HttpServerErrorException)21 MediaType (org.springframework.http.MediaType)19 RestTemplate (org.springframework.web.client.RestTemplate)19 ParameterizedTypeReference (org.springframework.core.ParameterizedTypeReference)18 HttpEntity (org.springframework.http.HttpEntity)16 URI (java.net.URI)15 Map (java.util.Map)8 HttpStatus (org.springframework.http.HttpStatus)8 RestClientException (org.springframework.web.client.RestClientException)8 ResourceAccessException (org.springframework.web.client.ResourceAccessException)7 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)6 Date (java.util.Date)5 List (java.util.List)5 OpenAppNamespaceDTO (com.ctrip.framework.apollo.openapi.dto.OpenAppNamespaceDTO)4 ArrayList (java.util.ArrayList)4