use of org.springframework.web.client.RestClientException in project commons by craftercms.
the class HttpMessageConvertingResponseErrorHandler method handleError.
@Override
public void handleError(ClientHttpResponse response) throws IOException {
HttpStatus status = response.getStatusCode();
HttpMessageConverterExtractor<?> responseExtractor = new HttpMessageConverterExtractor<>(responseType, messageConverters);
Object errorDetails;
try {
errorDetails = responseExtractor.extractData(response);
} catch (RestClientException e) {
// the response body as string
throw new RestServiceException(status, getResponseBodyAsString(response));
}
throw new RestServiceException(status, errorDetails);
}
use of org.springframework.web.client.RestClientException in project spring-cloud-sleuth by spring-cloud.
the class TraceExchangeFilterFunction method filter.
@Override
public Mono<ClientResponse> filter(ClientRequest request, ExchangeFunction next) {
final ClientRequest.Builder builder = ClientRequest.from(request);
Mono<ClientResponse> exchange = Mono.defer(() -> next.exchange(builder.build())).cast(Object.class).onErrorResume(Mono::just).zipWith(Mono.subscriberContext()).flatMap(anyAndContext -> {
Object any = anyAndContext.getT1();
Span clientSpan = anyAndContext.getT2().get(CLIENT_SPAN_KEY);
Mono<ClientResponse> continuation;
final Tracer.SpanInScope ws = tracer().withSpanInScope(clientSpan);
if (any instanceof Throwable) {
continuation = Mono.error((Throwable) any);
} else {
continuation = Mono.just((ClientResponse) any);
}
return continuation.doAfterSuccessOrError((clientResponse, throwable1) -> {
Throwable throwable = throwable1;
if (clientResponse == null || clientResponse.statusCode() == null) {
if (log.isDebugEnabled()) {
log.debug("No response was returned. Will close the span [" + clientSpan + "]");
}
handleReceive(clientSpan, ws, clientResponse, throwable);
return;
}
boolean error = clientResponse.statusCode().is4xxClientError() || clientResponse.statusCode().is5xxServerError();
if (error) {
if (log.isDebugEnabled()) {
log.debug("Non positive status code was returned from the call. Will close the span [" + clientSpan + "]");
}
throwable = new RestClientException("Status code of the response is [" + clientResponse.statusCode().value() + "] and the reason is [" + clientResponse.statusCode().getReasonPhrase() + "]");
}
handleReceive(clientSpan, ws, clientResponse, throwable);
});
}).subscriberContext(c -> {
if (log.isDebugEnabled()) {
log.debug("Instrumenting WebClient call");
}
Span parent = c.getOrDefault(Span.class, null);
Span clientSpan = handler().handleSend(injector(), builder, request, tracer().nextSpan());
if (log.isDebugEnabled()) {
log.debug("Created a client span for the WebClient " + clientSpan);
}
if (parent == null) {
c = c.put(Span.class, clientSpan);
if (log.isDebugEnabled()) {
log.debug("Reactor Context got injected with the client span " + clientSpan);
}
}
return c.put(CLIENT_SPAN_KEY, clientSpan);
});
return exchange;
}
use of org.springframework.web.client.RestClientException in project syndesis-qe by syndesisio.
the class EndpointClient method createAllTrustingClient.
// Required in order to skip certificate validation
private static HttpClient createAllTrustingClient() {
HttpClient httpclient;
try {
final SSLContextBuilder builder = new SSLContextBuilder();
builder.loadTrustMaterial((TrustStrategy) (X509Certificate[] chain, String authType) -> true);
final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build(), // needed to connections to API Provider integrations
new NoopHostnameVerifier());
httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).setMaxConnTotal(1000).setMaxConnPerRoute(1000).build();
} catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
throw new RestClientException("Cannot create all SSL certificates trusting client", e);
}
return httpclient;
}
use of org.springframework.web.client.RestClientException in project nzbhydra2 by theotherp.
the class Sabnzbd method checkConnection.
@Override
public GenericResponse checkConnection() {
logger.debug("Checking connection");
UriComponentsBuilder baseUrl = getBaseUrl();
try {
restTemplate.exchange(baseUrl.queryParam("mode", "get_cats").toUriString(), HttpMethod.GET, null, CategoriesResponse.class);
logger.info("Connection check with sabnzbd using URL {} successful", baseUrl.toUriString());
return new GenericResponse(true, null);
} catch (RestClientException e) {
logger.info("Connection check with sabnzbd using URL {} failed: {}", baseUrl.toUriString(), e.getMessage());
return new GenericResponse(false, e.getMessage());
}
}
use of org.springframework.web.client.RestClientException in project nzbhydra2 by theotherp.
the class UpdateManager method installUpdate.
public void installUpdate() throws UpdateException {
Release latestRelease = latestReleaseCache.get();
logger.info("Starting update process to {}", latestRelease.getTagName());
Asset asset = getAsset(latestRelease);
String url = asset.getBrowserDownloadUrl();
logger.debug("Downloading update from URL {}", url);
File updateZip;
try {
File updateFolder = new File(NzbHydra.getDataFolder(), "update");
if (!updateFolder.exists()) {
logger.debug("Creating update folder {}", updateFolder);
Files.createDirectory(updateFolder.toPath());
} else {
logger.debug("Cleaning update folder {}", updateFolder.getAbsolutePath());
FileUtils.cleanDirectory(updateFolder);
}
updateZip = new File(updateFolder, asset.getName());
logger.debug("Saving update file as {}", updateZip.getAbsolutePath());
applicationEventPublisher.publishEvent(new UpdateEvent("Downloading update file"));
webAccess.downloadToFile(url, updateZip);
} catch (RestClientException | IOException e) {
logger.error("Error while download or saving ZIP", e);
throw new UpdateException("Error while downloading, saving or extracting update ZIP", e);
}
if (configProvider.getBaseConfig().getMain().isBackupBeforeUpdate()) {
try {
logger.info("Creating backup before shutting down");
applicationEventPublisher.publishEvent(new UpdateEvent("Creating backup before update"));
backupAndRestore.backup();
} catch (Exception e) {
throw new UpdateException("Unable to create backup before update", e);
}
}
logger.info("Shutting down to let wrapper execute the update");
applicationEventPublisher.publishEvent(new UpdateEvent("Shutting down to let wrapper execute update"));
exitWithReturnCode(UPDATE_RETURN_CODE);
}
Aggregations