use of org.springframework.web.client.HttpClientErrorException in project goci by EBISPOT.
the class DepositionPublicationServiceImpl method retrievePublication.
@Override
public DepositionPublication retrievePublication(String id) {
log.info("Retrieving publication using id [{}]", id);
DepositionPublication publication = null;
Map<String, String> params = new HashMap<>();
params.put("pmID", id);
String url = depositionIngestUri + "/publications/{pmID}?pmid=true";
try {
String response = template.getForObject(url, String.class, params);
publication = template.getForObject(url, DepositionPublication.class, params);
} catch (HttpClientErrorException e) {
System.out.println(e.getMessage());
}
return publication;
}
use of org.springframework.web.client.HttpClientErrorException in project mirrorgate-jira-stories-collector by BBVA.
the class SprintService method deleteIssue.
public void deleteIssue(final Long issueId) {
final MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.set("collectorId", appName);
final UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(mirrorGateUrl + MIRRORGATE_DELETE_ISSUE_ENDPOINT).queryParams(params);
try {
restTemplate.delete(builder.build().toUriString(), issueId);
} catch (final HttpClientErrorException e) {
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
LOGGER.warn("Issue {} already deleted", issueId);
} else {
LOGGER.error("Error trying to delete issue {}", issueId, e);
throw e;
}
}
}
use of org.springframework.web.client.HttpClientErrorException in project spring-boot by spring-projects.
the class CloudFoundrySecurityService method getAccessLevel.
/**
* Return the access level that should be granted to the given token.
* @param token the token
* @param applicationId the cloud foundry application ID
* @return the access level that should be granted
* @throws CloudFoundryAuthorizationException if the token is not authorized
*/
AccessLevel getAccessLevel(String token, String applicationId) throws CloudFoundryAuthorizationException {
try {
URI uri = getPermissionsUri(applicationId);
RequestEntity<?> request = RequestEntity.get(uri).header("Authorization", "bearer " + token).build();
Map<?, ?> body = this.restTemplate.exchange(request, Map.class).getBody();
if (Boolean.TRUE.equals(body.get("read_sensitive_data"))) {
return AccessLevel.FULL;
}
return AccessLevel.RESTRICTED;
} catch (HttpClientErrorException ex) {
if (ex.getStatusCode().equals(HttpStatus.FORBIDDEN)) {
throw new CloudFoundryAuthorizationException(Reason.ACCESS_DENIED, "Access denied");
}
throw new CloudFoundryAuthorizationException(Reason.INVALID_TOKEN, "Invalid token", ex);
} catch (HttpServerErrorException ex) {
throw new CloudFoundryAuthorizationException(Reason.SERVICE_UNAVAILABLE, "Cloud controller not reachable");
}
}
use of org.springframework.web.client.HttpClientErrorException in project dhis2-core by dhis2.
the class SimplisticHttpGetGateWay method send.
@Override
public OutboundMessageResponse send(String subject, String text, Set<String> recipients, SmsGatewayConfig config) {
GenericHttpGatewayConfig genericConfig = (GenericHttpGatewayConfig) config;
UriComponentsBuilder uriBuilder;
ResponseEntity<String> responseEntity = null;
HttpEntity<String> requestEntity;
URI uri;
try {
requestEntity = getRequestEntity(genericConfig, text, recipients);
if (genericConfig.isSendUrlParameters()) {
uriBuilder = UriComponentsBuilder.fromHttpUrl(config.getUrlTemplate() + "?" + requestEntity.getBody());
} else {
uriBuilder = UriComponentsBuilder.fromHttpUrl(config.getUrlTemplate());
}
uri = uriBuilder.build().encode().toUri();
responseEntity = restTemplate.exchange(uri, genericConfig.isUseGet() ? HttpMethod.GET : HttpMethod.POST, requestEntity, String.class);
} catch (HttpClientErrorException ex) {
log.error("Client error " + ex.getMessage());
} catch (HttpServerErrorException ex) {
log.error("Server error " + ex.getMessage());
} catch (Exception ex) {
log.error("Error " + ex.getMessage());
}
return getResponse(responseEntity);
}
use of org.springframework.web.client.HttpClientErrorException in project dhis2-core by dhis2.
the class SyncUtils method isRemoteServerAvailable.
/**
* Checks the availability of remote server
*
* @param systemSettingManager Reference to SystemSettingManager
* @param restTemplate Reference to RestTemplate
* @return AvailabilityStatus that says whether the server is available or
* not
*/
public static AvailabilityStatus isRemoteServerAvailable(SystemSettingManager systemSettingManager, RestTemplate restTemplate) {
if (!isRemoteServerConfigured(systemSettingManager)) {
return new AvailabilityStatus(false, "Remote server is not configured", HttpStatus.BAD_GATEWAY);
}
String url = systemSettingManager.getStringSetting(SettingKey.REMOTE_INSTANCE_URL) + PING_PATH;
String username = systemSettingManager.getStringSetting(SettingKey.REMOTE_INSTANCE_USERNAME);
String password = systemSettingManager.getStringSetting(SettingKey.REMOTE_INSTANCE_PASSWORD);
log.debug(String.format("Remote server ping URL: %s, username: %s", url, username));
HttpEntity<String> request = getBasicAuthRequestEntity(username, password);
ResponseEntity<String> response = null;
HttpStatus sc = null;
String st = null;
AvailabilityStatus status = null;
try {
response = restTemplate.exchange(url, HttpMethod.GET, request, String.class);
sc = response.getStatusCode();
} catch (HttpClientErrorException | HttpServerErrorException ex) {
sc = ex.getStatusCode();
st = ex.getStatusText();
} catch (ResourceAccessException ex) {
return new AvailabilityStatus(false, "Network is unreachable", HttpStatus.BAD_GATEWAY);
}
log.debug("Response status code: " + sc);
if (HttpStatus.OK.equals(sc)) {
status = new AvailabilityStatus(true, "Authentication was successful", sc);
} else if (HttpStatus.FOUND.equals(sc)) {
status = new AvailabilityStatus(false, "No authentication was provided", sc);
} else if (HttpStatus.UNAUTHORIZED.equals(sc)) {
status = new AvailabilityStatus(false, "Authentication failed", sc);
} else if (HttpStatus.INTERNAL_SERVER_ERROR.equals(sc)) {
status = new AvailabilityStatus(false, "Remote server experienced an internal error", sc);
} else {
status = new AvailabilityStatus(false, "Server is not available: " + st, sc);
}
log.info("Status: " + status);
return status;
}
Aggregations