use of org.springframework.web.client.HttpClientErrorException in project spring-boot by spring-projects.
the class MavenMetadataVersionResolver method resolveVersions.
private Set<String> resolveVersions(String groupId, String artifactId, String repositoryUrl) {
Set<String> versions = new HashSet<>();
String url = repositoryUrl + "/" + groupId.replace('.', '/') + "/" + artifactId + "/maven-metadata.xml";
try {
String metadata = this.rest.getForObject(url, String.class);
Document metadataDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(metadata)));
NodeList versionNodes = (NodeList) XPathFactory.newInstance().newXPath().evaluate("/metadata/versioning/versions/version", metadataDocument, XPathConstants.NODESET);
for (int i = 0; i < versionNodes.getLength(); i++) {
versions.add(versionNodes.item(i).getTextContent());
}
} catch (HttpClientErrorException ex) {
if (ex.getStatusCode() != HttpStatus.NOT_FOUND) {
System.err.println("Failed to download maven-metadata.xml for " + groupId + ":" + artifactId + " from " + url + ": " + ex.getMessage());
}
} catch (Exception ex) {
System.err.println("Failed to resolve versions for module " + groupId + ":" + artifactId + " in repository " + repositoryUrl + ": " + ex.getMessage());
}
return versions;
}
use of org.springframework.web.client.HttpClientErrorException in project hippo by NHS-digital-website.
the class MicrosoftGraphAuthorizationProviderTest method throwsAuthorizationExceptionIfGraphApiThrowsHttpExceptionOnRequestAccessToken.
@Test(expected = AuthorizationException.class)
public void throwsAuthorizationExceptionIfGraphApiThrowsHttpExceptionOnRequestAccessToken() throws Exception {
when(restTemplate.postForEntity(any(URI.class), any(HttpEntity.class), any())).thenThrow(new HttpClientErrorException(HttpStatus.BAD_REQUEST));
authorizationProvider.processAuthorizationResponse(AUTHORIZATION_CODE);
}
use of org.springframework.web.client.HttpClientErrorException in project hippo by NHS-digital-website.
the class MicrosoftGraphAuthorizationProviderTest method throwsAuthorizationExceptionIfGraphApiThrowsHttpExceptionOnRefreshAccessToken.
@Test(expected = AuthorizationException.class)
public void throwsAuthorizationExceptionIfGraphApiThrowsHttpExceptionOnRefreshAccessToken() throws Exception {
when(restTemplate.postForEntity(any(URI.class), any(HttpEntity.class), any())).thenThrow(new HttpClientErrorException(HttpStatus.BAD_REQUEST));
final AccessToken oldAccessToken = new AccessToken(TOKEN, REFRESH_TOKEN, 1);
authorizationProvider.refreshAccessToken(oldAccessToken);
}
use of org.springframework.web.client.HttpClientErrorException in project CzechIdMng by bcvsolutions.
the class AbstractPasswordFilterIntegrationTest method process.
// FIXME: use Spring MVC and remove this method at all
// FIXME: admin authentication is used internally => security cannot be tested
protected IdmResponse process(PasswordRequest request, String url, boolean success) {
RestTemplate template = new RestTemplate();
HttpEntity<PasswordRequest> requestUpdate = new HttpEntity<>(request, prepareHeaderBasicAuth());
ResponseEntity<Object> result = null;
IdmResponse response = new IdmResponse();
try {
result = template.exchange(url, HttpMethod.PUT, requestUpdate, Object.class);
if (success) {
assertEquals(HttpStatus.OK, result.getStatusCode());
assertNull(result.getBody());
} else {
assertNotEquals(HttpStatus.OK, result.getStatusCode());
assertNotNull(result.getBody());
}
response.message = String.valueOf(result.getBody());
response.status = result.getStatusCode();
} catch (HttpClientErrorException e) {
response.message = e.getResponseBodyAsString();
response.status = e.getStatusCode();
}
return response;
}
use of org.springframework.web.client.HttpClientErrorException in project apollo by ctripcorp.
the class ClusterControllerTest method shouldFailWhenRequestBodyInvalid.
@Test
public void shouldFailWhenRequestBodyInvalid() {
ClusterDTO cluster = new ClusterDTO();
cluster.setAppId("valid");
cluster.setName("notBlank");
ResponseEntity<ClusterDTO> response = restTemplate.postForEntity(baseUrl() + "/apps/{appId}/clusters", cluster, ClusterDTO.class, cluster.getAppId());
ClusterDTO createdCluster = response.getBody();
Assert.assertNotNull(createdCluster);
Assert.assertEquals(cluster.getAppId(), createdCluster.getAppId());
Assert.assertEquals(cluster.getName(), createdCluster.getName());
cluster.setName("invalid app name");
try {
restTemplate.postForEntity(baseUrl() + "/apps/{appId}/clusters", cluster, ClusterDTO.class, cluster.getAppId());
Assert.fail("Should throw");
} catch (HttpClientErrorException e) {
Assert.assertThat(new String(e.getResponseBodyAsByteArray()), containsString(InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE));
}
}
Aggregations