use of org.springframework.web.client.ResourceAccessException in project sic by belluccifranco.
the class PuntoDeVentaGUI method agregarRenglon.
private void agregarRenglon(RenglonFactura renglon) {
try {
boolean agregado = false;
//busca entre los renglones al producto, aumenta la cantidad y recalcula el descuento
for (int i = 0; i < renglones.size(); i++) {
if (renglones.get(i).getId_ProductoItem() == renglon.getId_ProductoItem()) {
Producto producto = RestClient.getRestTemplate().getForObject("/productos/" + renglon.getId_ProductoItem(), Producto.class);
renglones.set(i, RestClient.getRestTemplate().getForObject("/facturas/renglon?" + "idProducto=" + producto.getId_Producto() + "&tipoDeComprobante=" + this.tipoDeComprobante.name() + "&movimiento=" + Movimiento.VENTA + "&cantidad=" + (renglones.get(i).getCantidad() + renglon.getCantidad()) + "&descuentoPorcentaje=" + renglon.getDescuento_porcentaje(), RenglonFactura.class));
agregado = true;
}
}
//si no encuentra el producto entre los renglones, carga un nuevo renglon
if (agregado == false) {
renglones.add(renglon);
}
//para que baje solo el scroll vertical
Point p = new Point(0, tbl_Resultado.getHeight());
sp_Resultado.getViewport().setViewPosition(p);
} catch (RestClientResponseException ex) {
JOptionPane.showMessageDialog(this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
} catch (ResourceAccessException ex) {
LOGGER.error(ex.getMessage());
JOptionPane.showMessageDialog(this, ResourceBundle.getBundle("Mensajes").getString("mensaje_error_conexion"), "Error", JOptionPane.ERROR_MESSAGE);
}
}
use of org.springframework.web.client.ResourceAccessException in project sic by belluccifranco.
the class TransportistasGUI method cargarComboBoxLocalidadesDeLaProvincia.
private void cargarComboBoxLocalidadesDeLaProvincia(Provincia provSeleccionada) {
cmb_Localidad.removeAllItems();
try {
List<Localidad> Localidades = new ArrayList(Arrays.asList(RestClient.getRestTemplate().getForObject("/localidades/provincias/" + provSeleccionada.getId_Provincia(), Localidad[].class)));
Localidad localidadTodas = new Localidad();
localidadTodas.setNombre("Todas");
cmb_Localidad.addItem(localidadTodas);
Localidades.stream().forEach((l) -> {
cmb_Localidad.addItem(l);
});
} catch (RestClientResponseException ex) {
JOptionPane.showMessageDialog(this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
} catch (ResourceAccessException ex) {
LOGGER.error(ex.getMessage());
JOptionPane.showMessageDialog(this, ResourceBundle.getBundle("Mensajes").getString("mensaje_error_conexion"), "Error", JOptionPane.ERROR_MESSAGE);
}
}
use of org.springframework.web.client.ResourceAccessException in project sic by belluccifranco.
the class TransportistasGUI method cargarComboBoxProvinciasDelPais.
private void cargarComboBoxProvinciasDelPais(Pais paisSeleccionado) {
cmb_Provincia.removeAllItems();
try {
List<Provincia> provincias = new ArrayList(Arrays.asList(RestClient.getRestTemplate().getForObject("/provincias/paises/" + paisSeleccionado.getId_Pais(), Provincia[].class)));
Provincia provinciaTodas = new Provincia();
provinciaTodas.setNombre("Todas");
cmb_Provincia.addItem(provinciaTodas);
provincias.stream().forEach((p) -> {
cmb_Provincia.addItem(p);
});
} catch (RestClientResponseException ex) {
JOptionPane.showMessageDialog(this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
} catch (ResourceAccessException ex) {
LOGGER.error(ex.getMessage());
JOptionPane.showMessageDialog(this, ResourceBundle.getBundle("Mensajes").getString("mensaje_error_conexion"), "Error", JOptionPane.ERROR_MESSAGE);
}
}
use of org.springframework.web.client.ResourceAccessException in project dhis2-core by dhis2.
the class DefaultSynchronizationManager method isRemoteServerAvailable.
// -------------------------------------------------------------------------
// SynchronizatonManager implementation
// -------------------------------------------------------------------------
@Override
public AvailabilityStatus isRemoteServerAvailable() {
Configuration config = configurationService.getConfiguration();
if (!isRemoteServerConfigured(config)) {
return new AvailabilityStatus(false, "Remote server is not configured", HttpStatus.BAD_GATEWAY);
}
String url = systemSettingManager.getSystemSetting(SettingKey.REMOTE_INSTANCE_URL) + PING_PATH;
String username = (String) systemSettingManager.getSystemSetting(SettingKey.REMOTE_INSTANCE_USERNAME);
String password = (String) systemSettingManager.getSystemSetting(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 ex) {
sc = ex.getStatusCode();
st = ex.getStatusText();
} catch (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.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 if (HttpStatus.OK.equals(sc)) {
status = new AvailabilityStatus(true, "Authentication was successful", sc);
} else {
status = new AvailabilityStatus(false, "Server is not available: " + st, sc);
}
log.info("Status: " + status);
return status;
}
use of org.springframework.web.client.ResourceAccessException in project dhis2-core by dhis2.
the class DefaultMonitoringService method pushMonitoringInfo.
@Override
public void pushMonitoringInfo() {
String url = (String) systemSettingManager.getSystemSetting(SettingKey.SYSTEM_MONITORING_URL);
String username = (String) systemSettingManager.getSystemSetting(SettingKey.SYSTEM_MONITORING_USERNAME);
String password = (String) systemSettingManager.getSystemSetting(SettingKey.SYSTEM_MONITORING_PASSWORD);
if (StringUtils.isBlank(url)) {
log.debug("Monitoring service URL not configured, aborting monitoring request");
return;
}
SystemInfo systemInfo = systemService.getSystemInfo();
if (systemInfo == null) {
log.warn("System info not available, aborting monitoring request");
return;
}
systemInfo.clearSensitiveInfo();
HttpHeadersBuilder headersBuilder = new HttpHeadersBuilder().withContentTypeJson();
if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)) {
headersBuilder.withBasicAuth(username, password);
}
HttpEntity<SystemInfo> requestEntity = new HttpEntity<>(systemInfo, headersBuilder.build());
ResponseEntity<String> response = null;
HttpStatus sc = null;
try {
response = restTemplate.postForEntity(url, requestEntity, String.class);
sc = response.getStatusCode();
} catch (HttpClientErrorException | HttpServerErrorException ex) {
log.warn("Monitoring request failed, status code: " + sc, ex);
return;
} catch (ResourceAccessException ex) {
log.info("Monitoring request failed, network is unreachable");
return;
}
if (response != null && sc != null && sc.is2xxSuccessful()) {
log.debug("Monitoring request successfully sent");
} else {
log.warn("Monitoring request was unsuccessful, status code: " + sc);
}
}
Aggregations