use of org.springframework.web.client.RequestCallback in project java-chassis by ServiceComb.
the class CseRestTemplate method getForObject.
// GET
@Override
@Nullable
public <T> T getForObject(String url, Class<T> responseType, Object... uriVariables) throws RestClientException {
RequestCallback requestCallback = acceptHeaderRequestCallback(responseType);
CseHttpMessageConverterExtractor<T> responseExtractor = new CseHttpMessageConverterExtractor<>();
return execute(url, HttpMethod.GET, requestCallback, responseExtractor, uriVariables);
}
use of org.springframework.web.client.RequestCallback in project java-chassis by ServiceComb.
the class CseRestTemplate method patchForObject.
@Override
@Nullable
public <T> T patchForObject(URI url, @Nullable Object request, Class<T> responseType) throws RestClientException {
RequestCallback requestCallback = httpEntityCallback(request, responseType);
CseHttpMessageConverterExtractor<T> responseExtractor = new CseHttpMessageConverterExtractor<>();
return execute(url, HttpMethod.PATCH, requestCallback, responseExtractor);
}
use of org.springframework.web.client.RequestCallback in project dhis2-core by dhis2.
the class DefaultSynchronizationManager method executeDataValuePush.
/**
* Executes a push of data values to the given remote instance.
*
* @param instance the remote system instance.
* @return an ImportSummary.
*/
private ImportConflicts executeDataValuePush(SystemInstance instance) throws WebMessageParseException {
// ---------------------------------------------------------------------
// Set time for last success to start of process to make data saved
// subsequently part of next synch process without being ignored
// ---------------------------------------------------------------------
final Date startTime = new Date();
final Date lastSuccessTime = SyncUtils.getLastSyncSuccess(systemSettingManager, SettingKey.LAST_SUCCESSFUL_DATA_VALUE_SYNC);
final Date skipChangedBefore = systemSettingManager.getDateSetting(SettingKey.SKIP_SYNCHRONIZATION_FOR_DATA_CHANGED_BEFORE);
final Date lastUpdatedAfter = lastSuccessTime.after(skipChangedBefore) ? lastSuccessTime : skipChangedBefore;
final int objectsToSynchronize = dataValueService.getDataValueCountLastUpdatedAfter(lastUpdatedAfter, true);
log.info("DataValues last changed before " + skipChangedBefore + " will not be synchronized.");
if (objectsToSynchronize == 0) {
SyncUtils.setLastSyncSuccess(systemSettingManager, SettingKey.LAST_SUCCESSFUL_DATA_VALUE_SYNC, startTime);
log.debug("Skipping data values push, no new or updated data values");
ImportCount importCount = new ImportCount(0, 0, 0, 0);
return new ImportSummary(ImportStatus.SUCCESS, "No new or updated data values to push.", importCount);
}
log.info("Data Values: " + objectsToSynchronize + " to push since last synchronization success: " + lastSuccessTime);
log.info("Remote server POST URL: " + instance.getUrl());
final RequestCallback requestCallback = request -> {
request.getHeaders().setContentType(MediaType.APPLICATION_JSON);
request.getHeaders().add(HEADER_AUTHORIZATION, CodecUtils.getBasicAuthString(instance.getUsername(), instance.getPassword()));
dataValueSetService.exportDataValueSetJson(lastUpdatedAfter, request.getBody(), new IdSchemes());
};
final int maxSyncAttempts = systemSettingManager.getIntSetting(SettingKey.MAX_SYNC_ATTEMPTS);
Optional<AbstractWebMessageResponse> responseSummary = SyncUtils.runSyncRequest(restTemplate, requestCallback, SyncEndpoint.DATA_VALUE_SETS.getKlass(), instance.getUrl(), maxSyncAttempts);
ImportSummary summary = null;
if (responseSummary.isPresent()) {
summary = (ImportSummary) responseSummary.get();
if (ImportStatus.SUCCESS.equals(summary.getStatus())) {
log.info("Push successful: " + summary);
} else {
log.warn("Push failed: " + summary);
}
}
return summary;
}
use of org.springframework.web.client.RequestCallback in project dhis2-core by dhis2.
the class TrackerSynchronization method sendSyncRequest.
private boolean sendSyncRequest(List<TrackedEntityInstance> dtoTeis) {
TrackedEntityInstances teis = new TrackedEntityInstances();
teis.setTrackedEntityInstances(dtoTeis);
final RequestCallback requestCallback = request -> {
request.getHeaders().setContentType(MediaType.APPLICATION_JSON);
request.getHeaders().add(SyncUtils.HEADER_AUTHORIZATION, CodecUtils.getBasicAuthString(instance.getUsername(), instance.getPassword()));
renderService.toJson(request.getBody(), teis);
};
return SyncUtils.sendSyncRequest(systemSettingManager, restTemplate, requestCallback, instance, SyncEndpoint.TRACKED_ENTITY_INSTANCES);
}
Aggregations